blob: 49c15735fb213752472ea1fe9512a2144dc4e8fe [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>
<head>
<link rel="stylesheet" type="text/css" href="../../com.ibm.help.doc/swg_info_common.css" />
<title>Using xsi:type</title>
<script language="JavaScript">
function popup_window( url, id, width, height )
{
popup = window.open( url, id, 'toolbar=no,scrollbars=no,location=no,statusbar=no,menubar=no,resizable=no,width=' + width + ',height=' + height + ',left=,top=' );
popup.focus();
}
</script><script language="JavaScript" src="help/liveHelp.js"></script></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="skipspace"><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 <tt class="sysout">.</tt></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 <b>xsi:type</b> support.</p>
<p>For
more information about xsi:type, refer to the <b>Using Derived Types in Instance
Documents</b> 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 <b>Schema-Related Markup in Documents Being Validated</b> section
in <a href="http://www.w3.org/TR/xmlschema-1/#xsi_type" target="_blank">XML Schema Part 1: Structures</a>  </p>
</div>
</div>
<div>
</div><p>
(C) Copyright IBM Corporation 2000, 2005. All Rights Reserved.
</p>
</body>
</html>