blob: b38e10454438efb177c18fa6c8044c4f9585a55c [file] [log] [blame]
<html>
<head>
<title>How to declare XML Schemas</title>
<link href="book.css" rel="stylesheet" type="text/css"/>
<meta content="DocBook XSL Stylesheets V1.75.1" name="generator"/>
<link rel="home" href="index.html" title="Xpand Documentation"/>
<link rel="up" href="xsd_reference.html" title="XSD Adapter"/>
<link rel="prev" href="xsd_reference_xsd2ecore.html" title="Behind the scenes: Transforming XSD to Ecore"/>
<link rel="next" href="Tutorials.html" title="Part II. Tutorials"/>
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<h1 xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0">How to declare XML Schemas</h1>
<div class="section" title="How to declare XML Schemas">
<div class="titlepage">
<div>
<div>
<h2 class="title" style="clear: both">
<a name="xsd_reference_declare_xsd"/>How to declare XML Schemas</h2>
</div>
</div>
</div>
<p>There are three different ways to declare your XSDs. It does not
matter which way you choose, or how you combine them, as long as the XSD
Adapter can find all needed schemas.</p>
<div class="orderedlist">
<ol class="orderedlist" type="1">
<li class="listitem">
<p>Within the Workflow: <code class="classname">
org.eclipse.xtend.typesystem.xsd.XSDMetaModel </code> can have any
amount of <code class="classname">schemaFile</code> elements.</p>
<pre class="programlisting">&lt;component class="org.eclipse.xtend.typesystem.xsd.XMLReader"&gt;
&lt;modelSlot value="model" /&gt;
&lt;uri value="${file}" /&gt;
&lt;metaModel id="mm" class="org.eclipse.xtend.typesystem.xsd.XSDMetaModel"&gt;
&lt;schemaFile value="model/loadcurve.xsd" /&gt;
&lt;schemaFile value="model/device.xsd" /&gt;
&lt;/metaModel&gt;
&lt;/component&gt;</pre>
</li>
<li class="listitem">
<p>Within the XML file: XML files can contain
<code class="classname">schemaLocation</code> attributes which associate the
schema's namespace with the schema's filename. If the schema is
created using WTP like described in <a class="xref" href="xsd_tutorial_model.html" title="Step 3: Create a Model using XML">the section called “Step 3: Create a Model using XML”</a> , the
<code class="classname">schemaLocation</code> attribute is created
automatically.</p>
<pre class="programlisting">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;device:Device
xmlns:device="http://www.eclipse.org/modeling/xpand/example/model/device"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.eclipse.org/modeling/xpand/example/model/device device.xsd"&gt;
&lt;device:Name&gt;MyLaptop&lt;/device:Name&gt;
&lt;/device:Device&gt;</pre>
</li>
<li class="listitem">
<p>Within an XSD: If one schema imports another, the
<code class="classname">import</code> element can have a
<code class="classname">schemaLocation</code> attribute, too.</p>
<pre class="programlisting">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;schema
targetNamespace="http://www.eclipse.org/modeling/xpand/example/model/device"
elementFormDefault="qualified" xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://www.eclipse.org/modeling/xpand/example/model/device"
xmlns:lc="http://www.eclipse.org/modeling/xpand/example/model/loadcurve"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"&gt;
&lt;import
namespace="http://www.eclipse.org/modeling/xpand/example/model/loadcurve"
schemaLocation="loadcurve.xsd"&gt;
&lt;/import&gt;
&lt;complexType name="Device"&gt;
&lt;sequence&gt;
&lt;element name="Name" type="string" /&gt;
&lt;element name="LoadCurve" type="lc:LoadCurve" /&gt;
&lt;/sequence&gt;
&lt;/complexType&gt;
&lt;element name="Device" type="tns:Device"&gt;&lt;/element&gt;
&lt;/schema&gt;</pre>
</li>
</ol>
</div>
</div>
</body>
</html>