blob: 7f3450c1656b4deaabe36003884aa1bd5292a386 [file] [log] [blame]
<html>
<head>
<title>Step 2: Define a Meta Model using XML Schema</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_tutorial.html" title="XSD Tutorial"/>
<link rel="prev" href="xsd_tutorial_create_project.html" title="Step 1: Create a Project"/>
<link rel="next" href="xsd_tutorial_model.html" title="Step 3: Create a Model using XML"/>
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<h1 xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0">Step 2: Define a Meta Model using XML Schema</h1>
<div class="section" title="Step 2: Define a Meta Model using XML Schema">
<div class="titlepage">
<div>
<div>
<h2 class="title" style="clear: both">
<a name="xsd_tutorial_metamodel"/>Step 2: Define a Meta Model using XML Schema</h2>
</div>
</div>
</div>
<p>In case you are not going to use an existing XML Schema Definition,
you can create a new a new one like described below. These steps make use
of the Eclipse Web Tools Platform (WTP) to have fancy editors.</p>
<p>In Eclipse, click on <span class="emphasis">
<em>"File", "New", "Other..."</em>
</span>
and choose <span class="emphasis">
<em>"XML Schema"</em>
</span> from category "XML". Select
the project's "src" folder and specify a filename. Clicking on "finish"
creates an empty XSD file. It is important that the XSD file is located
somewhere within the project's classpath.</p>
<p>This XML Schema consists of two complex data types, which contain
some elements and attributes. "complex" in the XSD terminology means that
as opposed to simple data types that they can actually have sub-elements
and/or attributes. This example is too minimalistic to do anything
useful.</p>
<p>The complex Type <code class="classname">Wizard</code> contains the elements
<code class="classname">startpage</code> , <code class="classname">name</code> ,
<code class="classname">welcometext</code> , and <code class="classname">choicepage</code>
. Except for <code class="classname">choicepage</code> all elements have to
contain strings, whereas the string of <code class="classname">startpage</code>
must be a valid id of any <code class="classname">ChoicePage</code> . The complex
type <code class="classname">ChoicePage</code> just contains an
<code class="classname">id</code> and a <code class="classname">name</code> . For Xpand it
does not make any difference if something is modeled as an XML-attribute
or XML-element. Just the datafield's type defines how Xpand treats the
value.</p>
<p>To get an overview how schemas can be used by the Xpand XSD Adapter,
see <a class="xref" href="xsd_reference_declare_xsd.html" title="How to declare XML Schemas">the section called “How to declare XML Schemas”</a>
</p>
<p>Internally, the Xpand XSD Adapter transforms the XSD model to an
Ecore model which Xpand can use like any other Ecore model. For more
information about that, see <a class="xref" href="xsd_reference_xsd2ecore.html" title="Behind the scenes: Transforming XSD to Ecore">the section called “Behind the scenes: Transforming XSD to Ecore”</a>
</p>
<div class="figure">
<a name="xsd_tutorial_xsd_editor"/>
<p class="title">
<b>Figure 4. WTP Schema Editor</b>
</p>
<div class="figure-contents">
<div class="mediaobject">
<img src="xsd_tutorial/xsd-editor.png" alt="WTP Schema Editor"/>
</div>
</div>
</div>
<br class="figure-break"/>
<pre class="programlisting">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;schema xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.org/wizard"
xmlns:tns="http://www.example.org/wizard"
elementFormDefault="qualified"&gt;
&lt;complexType name="Wizard"&gt;
&lt;sequence&gt;
&lt;element name="startpage" type="IDREF" /&gt;
&lt;element name="name" type="string" /&gt;
&lt;element name="welcometext" type="string" /&gt;
&lt;element name="choicepage" type="tns:ChoicePage" /&gt;
&lt;/sequence&gt;
&lt;/complexType&gt;
&lt;complexType name="ChoicePage"&gt;
&lt;sequence&gt;
&lt;element name="title" type="string" /&gt;
&lt;/sequence&gt;
&lt;attribute name="id" type="ID" /&gt;
&lt;/complexType&gt;
&lt;element name="wizard" type="tns:Wizard" /&gt;
&lt;/schema&gt;</pre>
</div>
</body>
</html>