| <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"><component class="org.eclipse.xtend.typesystem.xsd.XMLReader"> |
| <modelSlot value="model" /> |
| <uri value="${file}" /> |
| <metaModel id="mm" class="org.eclipse.xtend.typesystem.xsd.XSDMetaModel"> |
| <schemaFile value="model/loadcurve.xsd" /> |
| <schemaFile value="model/device.xsd" /> |
| </metaModel> |
| </component></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"><?xml version="1.0" encoding="UTF-8"?> |
| <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"> |
| <device:Name>MyLaptop</device:Name> |
| </device:Device></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"><?xml version="1.0" encoding="UTF-8"?> |
| <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"> |
| |
| <import |
| namespace="http://www.eclipse.org/modeling/xpand/example/model/loadcurve" |
| schemaLocation="loadcurve.xsd"> |
| </import> |
| |
| <complexType name="Device"> |
| <sequence> |
| <element name="Name" type="string" /> |
| <element name="LoadCurve" type="lc:LoadCurve" /> |
| </sequence> |
| </complexType> |
| |
| <element name="Device" type="tns:Device"></element> |
| </schema></pre> |
| </li> |
| </ol> |
| </div> |
| </div> |
| </body> |
| </html> |