blob: fc47c4cdcea2c0ae51e1cd8be0b400015745b732 [file] [log] [blame]
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en-us" xml:lang="en-us">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<meta name="copyright" content="Copyright (c) 2000, 2009 IBM Corporation and others. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html. Contributors: IBM Corporation - initial API and implementation" />
<meta name="DC.rights.owner" content="(C) Copyright 2000, 2009" />
<meta content="public" name="security" />
<meta content="index,follow" name="Robots" />
<meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.icra.org/ratingsv02.html" l gen true r (cz 1 lz 1 nz 1 oz 1 vz 1) "http://www.rsac.org/ratingsv01.html" l gen true r (n 0 s 0 v 0 l 0) "http://www.classify.org/safesurf/" l gen true r (SS~~000 1))' />
<meta content="task" name="DC.Type" />
<meta name="DC.Title" content="Using xsi:type" />
<meta name="abstract" content="If you have elements in your XML file whose type is a complex type, xsi:type support in the XML editor lets you choose between the complex type and any other complex types derived from it." />
<meta name="description" content="If you have elements in your XML file whose type is a complex type, xsi:type support in the XML editor lets you choose between the complex type and any other complex types derived from it." />
<meta content="XHTML" name="DC.Format" />
<meta content="txsityp" name="DC.Identifier" />
<meta content="en-us" name="DC.Language" />
<link href="../../org.eclipse.wst.doc.user/common.css" type="text/css" rel="stylesheet" />
<title>Using xsi:type</title>
</head>
<body id="txsityp"><a name="txsityp"><!-- --></a>
<h1 class="topictitle1">Using xsi:type</h1>
<div><p>If you have elements in your XML file whose type is a complex type,
xsi:type support in the XML editor lets you choose between the complex type
and any other complex types derived from it.</p>
<div class="section"><p>The XML Schema specification allows you to derive types by extension.
See the following steps as an example:</p>
</div>
<ol>
<li class="stepexpand"><span>Create an XML schema and create a complex type for it called <kbd class="userinput">Address</kbd>. </span>
</li>
<li class="stepexpand"><span>Add some basic elements to <kbd class="userinput">Address</kbd>, such
as <kbd class="userinput">streetName</kbd> and <kbd class="userinput">city</kbd>.</span>
</li>
<li class="stepexpand"><span>Derive (by extension) two new complex types from <kbd class="userinput">Address</kbd>: <kbd class="userinput">USAddress</kbd> and <kbd class="userinput">UKAddress</kbd>. </span></li>
<li class="stepexpand"><span>Add a new element to <kbd class="userinput">USAddress</kbd> called <kbd class="userinput">state</kbd>,
and also a new element to <kbd class="userinput">UKAddress</kbd> called <kbd class="userinput">postcode</kbd>.</span>
</li>
<li class="stepexpand"><span>Create two more elements: <kbd class="userinput">billTo</kbd> and <kbd class="userinput">shipTo</kbd>,
as <tt class="sysout">Address</tt> types.</span></li>
<li class="stepexpand"><span>When you create an XML instance document for an element such as
<tt class="sysout">billTo</tt> or <kbd class="userinput">Address</kbd>, an
xsi:type attribute will automatically be added to it.</span> For example, <pre>&lt;billTo xsi:type="ipo:Address"&gt;</pre>
The
xsi:type attribute is used to identify derived complex types (as well as complex
types that have been derived from).</li>
<li class="stepexpand"><span>In the Design view of the XML editor, a list will be available,
letting you select the appropriate type definition (<span class="uicontrol">Address</span>, <span class="uicontrol">USAddress</span>,
or <span class="uicontrol">UKAddress</span>). The guided editing for the content
model will reflect the type definition that you choose. For example, if you
select <span class="uicontrol">USAddress</span> , your <samp class="codeph">billTo</samp> element
can contain a <samp class="codeph">state</samp> element, but it cannot contain a <samp class="codeph">postcode</samp> element.</span>
</li>
</ol>
<div class="section"><p>The XML example "Editing and validating XML files" demonstrates <strong>xsi:type</strong> support.</p>
<p>For
more information about xsi:type, refer to the <strong>Using Derived Types in Instance
Documents</strong> section in <a href="http://www.w3.org/TR/xmlschema-0/#UseDerivInInstDocs" target="_blank">XML Schema Part 0: Primer.</a></p>
<p>For more information
about validation semantics when xsi:type is used, refer to the <strong>Schema-Related
Markup in Documents Being Validated</strong> section in <a href="http://www.w3.org/TR/xmlschema-1/#xsi_type" target="_blank">XML Schema Part 1: Structures</a> </p>
</div>
</div>
</body>
</html>