Note that there are some explanatory texts on larger screens.

plurals
  1. POusing xml type attribute for derived complex types
    primarykey
    data
    text
    <p>I'm trying to get derived complex types from a base type in an xsd schema. </p> <p>it works well when I do this (inspired by <a href="http://msdn.microsoft.com/en-us/library/ms256157.aspx" rel="nofollow noreferrer">this</a>):</p> <p>xml file:</p> <pre><code> &lt;person xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="Employee"&gt; &lt;name&gt;John&lt;/name&gt; &lt;height&gt;59&lt;/height&gt; &lt;jobDescription&gt;manager&lt;/jobDescription&gt; &lt;/person&gt; </code></pre> <p>xsd file:</p> <pre><code> &lt;xs:element name="person" type="Person"/&gt; &lt;xs:complexType name="Person" abstract="true"&gt; &lt;xs:sequence&gt; &lt;xs:element name= "name" type="xs:string"/&gt; &lt;xs:element name= "height" type="xs:double" /&gt; &lt;/xs:sequence&gt; &lt;/xs:complexType&gt; &lt;xs:complexType name="Employee"&gt; &lt;xs:complexContent&gt; &lt;xs:extension base="Person"&gt; &lt;xs:sequence&gt; &lt;xs:element name="jobDescription" type="xs:string" /&gt; &lt;/xs:sequence&gt; &lt;/xs:extension&gt; &lt;/xs:complexContent&gt; &lt;/xs:complexType&gt; </code></pre> <p>However, if I want to have the person element inside, for example, a sequence of another complex type, it doesn't work anymore:</p> <p>xml:</p> <pre><code> &lt;staffRecord&gt; &lt;company&gt;mycompany&lt;/company&gt; &lt;dpt&gt;sales&lt;/dpt&gt; &lt;person xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="Employee"&gt; &lt;name&gt;John&lt;/name&gt; &lt;height&gt;59&lt;/height&gt; &lt;jobDescription&gt;manager&lt;/jobDescription&gt; &lt;/person&gt; &lt;/staffRecord&gt; </code></pre> <p>xsd file:</p> <pre><code>&lt;xs:element name="staffRecord"&gt; &lt;xs:complexType&gt; &lt;xs:sequence&gt; &lt;xs:element name="company" type="xs:string"/&gt; &lt;xs:element name="dpt" type="xs:string"/&gt; &lt;xs:element name="person" type="Person"/&gt; &lt;xs:complexType name="Person" abstract="true"&gt; &lt;xs:sequence&gt; &lt;xs:element name= "name" type="xs:string"/&gt; &lt;xs:element name= "height" type="xs:double" /&gt; &lt;/xs:sequence&gt; &lt;/xs:complexType&gt; &lt;xs:complexType name="Employee"&gt; &lt;xs:complexContent&gt; &lt;xs:extension base="Person"&gt; &lt;xs:sequence&gt; &lt;xs:element name="jobDescription" type="xs:string" /&gt; &lt;/xs:sequence&gt; &lt;/xs:extension&gt; &lt;/xs:complexContent&gt; &lt;/xs:complexType&gt; &lt;/xs:sequence&gt; &lt;/xs:complexType&gt; &lt;/xs:element&gt; </code></pre> <p>When validating the xml with that schema with xmllint (under linux), I get this error message then:</p> <blockquote> <p>config.xsd:12: element complexType: Schemas parser error : Element '{<a href="http://www.w3.org/2001/XMLSchema" rel="nofollow noreferrer">http://www.w3.org/2001/XMLSchema</a>}sequence': The content is not valid. Expected is (annotation?, (element | group | choice | sequence | any)*). WXS schema config.xsd failed to compile</p> </blockquote> <p>Any idea what is wrong ?</p> <p>David</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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