blob: 87ed2c68f74bee58c38a3448556da901a89508ee [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, 2006 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, 2006" />
<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.
For example, you have an XML schema and you create a complex type for it called
<kbd class="userinput">Address</kbd>. You then add some basic elements to <kbd class="userinput">Address</kbd>,
such as <kbd class="userinput">streetName</kbd> and <kbd class="userinput">city</kbd>.</p>
<p>After
this, you derive (by extension) two new complex types from <kbd class="userinput">Address</kbd> - <kbd class="userinput">USAddress</kbd> and <kbd class="userinput">UKAddress</kbd> You 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>.</p>
<p>After
you have done this, you create two more elements - <kbd class="userinput">billTo</kbd> and <kbd class="userinput">shipTo</kbd> -
as <tt class="sysout">Address</tt> types.</p>
<p>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. For example:</p>
<pre>&lt;billTo xsi:type="ipo:Address"&gt;</pre>
<p>The
xsi:type attribute is used to identify derived complex types (as well as complex
types that have been derived from).</p>
<p>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.</p>
<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>