Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The key points (see <a href="http://msdn.microsoft.com/en-us/library/aa468563.aspx#xmlschmachng_topic04" rel="nofollow noreferrer">XML Schema Runtime Polymorphism via xsi:type and Abstract Types</a> for complete and correct context/placement/usage) are:</p> <ol> <li><p>Create a base type with (abstract="true" to prevent it from being used directly)</p> <p>Note: the ref attribute replaces the name attribute for elements defined elsewhere</p> <pre><code>&lt;xs:complexType name="CustomerType" abstract="true" &gt; &lt;xs:sequence&gt; &lt;xs:element ref="cust:FirstName" /&gt; &lt;xs:element ref="cust:LastName" /&gt; &lt;xs:element ref="cust:PhoneNumber" minOccurs="0"/&gt; &lt;/xs:sequence&gt; &lt;xs:attribute name="customerID" type="xs:integer" /&gt; &lt;/xs:complexType&gt; </code></pre></li> <li><p>Create two or more derived types by extending or restricting the base type</p> <pre><code>&lt;xs:complexType name="MandatoryPhoneCustomerType" &gt; &lt;xs:complexContent&gt; &lt;xs:restriction base="cust:CustomerType"&gt; &lt;xs:sequence&gt; &lt;xs:element ref="cust:FirstName" /&gt; &lt;xs:element ref="cust:LastName" /&gt; &lt;xs:element ref="cust:PhoneNumber" minOccurs="1" /&gt; &lt;/xs:sequence&gt; &lt;/xs:restriction&gt; &lt;/xs:complexContent&gt; &lt;/xs:complexType&gt; </code></pre> <p>and</p> <pre><code>&lt;xs:complexType name="AddressableCustomerType" &gt; &lt;xs:complexContent&gt; &lt;xs:extension base="cust:CustomerType"&gt; &lt;xs:sequence&gt; &lt;xs:element ref="cust:Address" /&gt; &lt;xs:element ref="cust:City" /&gt; &lt;xs:element ref="cust:State" /&gt; &lt;xs:element ref="cust:Zip" /&gt; &lt;/xs:sequence&gt; &lt;/xs:extension&gt; &lt;/xs:complexContent&gt; &lt;/xs:complexType&gt; </code></pre></li> <li><p>Reference the base type in an element</p> <pre><code>&lt;xs:element name="Customer" type="cust:CustomerType" /&gt; </code></pre></li> <li><p>In your instance XML document, specify the specific derived type as an xsi:type attribute</p> <pre><code>&lt;cust:Customer customerID="12345" xsi:type="cust:MandatoryPhoneCustomerType" &gt; &lt;cust:FirstName&gt;Dare&lt;/cust:FirstName&gt; &lt;cust:LastName&gt;Obasanjo&lt;/cust:LastName&gt; &lt;cust:PhoneNumber&gt;425-555-1234&lt;/cust:PhoneNumber&gt; &lt;/cust:Customer&gt; </code></pre> <p>or:</p> <pre><code>&lt;cust:Customer customerID="67890" xsi:type="cust:AddressableCustomerType" &gt; &lt;cust:FirstName&gt;John&lt;/cust:FirstName&gt; &lt;cust:LastName&gt;Smith&lt;/cust:LastName&gt; &lt;cust:Address&gt;2001&lt;/cust:Address&gt; &lt;cust:City&gt;Redmond&lt;/cust:City&gt; &lt;cust:State&gt;WA&lt;/cust:State&gt; &lt;cust:Zip&gt;98052&lt;/cust:Zip&gt; &lt;/cust:Customer&gt; </code></pre></li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload