blob: 87ed2c68f74bee58c38a3448556da901a89508ee [file] [log] [blame]
kpriceef160682006-08-29 18:08:31 +00001<?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">
2<html lang="en-us" xml:lang="en-us">
syeshinbefd53e2005-07-27 18:16:40 +00003<head>
kpriceef160682006-08-29 18:08:31 +00004<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
5<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" />
6<meta name="DC.rights.owner" content="(C) Copyright 2000, 2006" />
7<meta content="public" name="security" />
8<meta content="index,follow" name="Robots" />
9<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))' />
10<meta content="task" name="DC.Type" />
11<meta name="DC.Title" content="Using xsi:type" />
12<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." />
13<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." />
14<meta content="XHTML" name="DC.Format" />
15<meta content="txsityp" name="DC.Identifier" />
16<meta content="en-us" name="DC.Language" />
17<link href="../../org.eclipse.wst.doc.user/common.css" type="text/css" rel="stylesheet" />
syeshinbefd53e2005-07-27 18:16:40 +000018<title>Using xsi:type</title>
syeshin66078272005-09-20 16:53:38 +000019</head>
syeshinbefd53e2005-07-27 18:16:40 +000020<body id="txsityp"><a name="txsityp"><!-- --></a>
21
kpriceef160682006-08-29 18:08:31 +000022
syeshinbefd53e2005-07-27 18:16:40 +000023<h1 class="topictitle1">Using xsi:type</h1>
kpriceef160682006-08-29 18:08:31 +000024
25
26
syeshinbefd53e2005-07-27 18:16:40 +000027<div><p>If you have elements in your XML file whose type is a complex type,
28xsi:type support in the XML editor lets you choose between the complex type
kpriceef160682006-08-29 18:08:31 +000029and any other complex types derived from it.</p>
30
31<div class="section"><p>The XML Schema specification allows you to derive types by extension.
syeshinbefd53e2005-07-27 18:16:40 +000032For example, you have an XML schema and you create a complex type for it called
33 <kbd class="userinput">Address</kbd>. You then add some basic elements to <kbd class="userinput">Address</kbd>,
syeshind0bdb8e2005-10-27 17:44:14 +000034such as <kbd class="userinput">streetName</kbd> and <kbd class="userinput">city</kbd>.</p>
syeshinbefd53e2005-07-27 18:16:40 +000035<p>After
kpriceef160682006-08-29 18:08:31 +000036this, 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>,
37and also a new element to <kbd class="userinput">UKAddress</kbd> called <kbd class="userinput">postcode</kbd>.</p>
syeshinbefd53e2005-07-27 18:16:40 +000038<p>After
39you have done this, you create two more elements - <kbd class="userinput">billTo</kbd> and <kbd class="userinput">shipTo</kbd> -
kpriceef160682006-08-29 18:08:31 +000040as <tt class="sysout">Address</tt> types.</p>
41<p>When you create an XML
42instance document for an element such as <tt class="sysout">billTo</tt> or
syeshinbefd53e2005-07-27 18:16:40 +000043 <kbd class="userinput">Address</kbd>, an xsi:type attribute will automatically
44be added to it. For example:</p>
45<pre>&lt;billTo xsi:type="ipo:Address"&gt;</pre>
46<p>The
47xsi:type attribute is used to identify derived complex types (as well as complex
48types that have been derived from).</p>
49<p>In the Design view of the XML editor,
50a list will be available, letting you select the appropriate type definition
51(<span class="uicontrol">Address</span>, <span class="uicontrol">USAddress</span>, or <span class="uicontrol">UKAddress</span>).
52The guided editing for the content model will reflect the type definition
53that you choose. For example, if you select <span class="uicontrol">USAddress</span> ,
54your <samp class="codeph">billTo</samp> element can contain a <samp class="codeph">state</samp> element,
55but it cannot contain a <samp class="codeph">postcode</samp> element.</p>
56<p>The XML example
kpriceef160682006-08-29 18:08:31 +000057"Editing and validating XML files" demonstrates <strong>xsi:type</strong> support.</p>
syeshinbefd53e2005-07-27 18:16:40 +000058<p>For
kpriceef160682006-08-29 18:08:31 +000059more information about xsi:type, refer to the <strong>Using Derived Types in Instance
60Documents</strong> section in <a href="http://www.w3.org/TR/xmlschema-0/#UseDerivInInstDocs" target="_blank">XML Schema Part 0: Primer.</a></p>
61<p>For more information
62about validation semantics when xsi:type is used, refer to the <strong>Schema-Related
63Markup 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>
syeshinbefd53e2005-07-27 18:16:40 +000064</div>
kpriceef160682006-08-29 18:08:31 +000065
syeshinbefd53e2005-07-27 18:16:40 +000066</div>
kpriceef160682006-08-29 18:08:31 +000067
68
syeshinbefd53e2005-07-27 18:16:40 +000069</body>
70</html>