Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can create two different types (e.g. <code>fathersName</code> and <code>mothersName</code>) and use them for the respective <code>name</code> elements. Here's the full XSD:</p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt; &lt;xs:element name="firstname"&gt; &lt;xs:complexType mixed="true" /&gt; &lt;/xs:element&gt; &lt;xs:element name="maidenname"&gt; &lt;xs:complexType mixed="true" /&gt; &lt;/xs:element&gt; &lt;xs:element name="mother"&gt; &lt;xs:complexType&gt; &lt;xs:sequence&gt; &lt;xs:element name="name" type="mothersName" /&gt; &lt;/xs:sequence&gt; &lt;/xs:complexType&gt; &lt;/xs:element&gt; &lt;xs:element name="father"&gt; &lt;xs:complexType&gt; &lt;xs:sequence&gt; &lt;xs:element name="name" type="fathersName" /&gt; &lt;/xs:sequence&gt; &lt;/xs:complexType&gt; &lt;/xs:element&gt; &lt;xs:complexType name="fathersName"&gt; &lt;xs:all&gt; &lt;xs:element ref="firstname" /&gt; &lt;xs:element ref="surname" /&gt; &lt;/xs:all&gt; &lt;/xs:complexType&gt; &lt;xs:complexType name="mothersName"&gt; &lt;xs:all&gt; &lt;xs:element ref="firstname" /&gt; &lt;xs:element ref="surname" /&gt; &lt;xs:element ref="maidenname" /&gt; &lt;/xs:all&gt; &lt;/xs:complexType&gt; &lt;xs:element name="parent"&gt; &lt;xs:complexType&gt; &lt;xs:choice&gt; &lt;xs:element ref="mother"/&gt; &lt;xs:element ref="father"/&gt; &lt;/xs:choice&gt; &lt;/xs:complexType&gt; &lt;/xs:element&gt; &lt;xs:element name="surname"&gt; &lt;xs:complexType mixed="true" /&gt; &lt;/xs:element&gt; &lt;/xs:schema&gt; </code></pre> <p>Also, if the names are supposed to be simple strings, you could write the XSD in a more concise way:</p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt; &lt;xs:element name="mother"&gt; &lt;xs:complexType&gt; &lt;xs:sequence&gt; &lt;xs:element name="name" type="mothersName" /&gt; &lt;/xs:sequence&gt; &lt;/xs:complexType&gt; &lt;/xs:element&gt; &lt;xs:element name="father"&gt; &lt;xs:complexType&gt; &lt;xs:sequence&gt; &lt;xs:element name="name" type="fathersName" /&gt; &lt;/xs:sequence&gt; &lt;/xs:complexType&gt; &lt;/xs:element&gt; &lt;xs:complexType name="fathersName"&gt; &lt;xs:all&gt; &lt;xs:element name="firstname" type="xs:string" /&gt; &lt;xs:element name="surname" type="xs:string" /&gt; &lt;/xs:all&gt; &lt;/xs:complexType&gt; &lt;xs:complexType name="mothersName"&gt; &lt;xs:all&gt; &lt;xs:element name="firstname" type="xs:string" /&gt; &lt;xs:element name="surname" type="xs:string" /&gt; &lt;xs:element name="maidenname" type="xs:string" /&gt; &lt;/xs:all&gt; &lt;/xs:complexType&gt; &lt;xs:element name="parent"&gt; &lt;xs:complexType&gt; &lt;xs:choice maxOccurs="unbounded"&gt; &lt;xs:element ref="mother"/&gt; &lt;xs:element ref="father"/&gt; &lt;/xs:choice&gt; &lt;/xs:complexType&gt; &lt;/xs:element&gt; &lt;/xs:schema&gt; </code></pre> <p>Finally, you may write <code>mothersName</code> as an extension of <code>fathersName</code>, but this comes with a cost: the order of elements has to be (at least partially) fixed. Here's how the two type definitions would look:</p> <pre><code> &lt;!-- ... --&gt; &lt;xs:complexType name="fathersName"&gt; &lt;xs:sequence&gt; &lt;xs:element name="firstname" type="xs:string" /&gt; &lt;xs:element name="surname" type="xs:string" /&gt; &lt;/xs:sequence&gt; &lt;/xs:complexType&gt; &lt;xs:complexType name="mothersName"&gt; &lt;xs:complexContent&gt; &lt;xs:extension base="fathersName"&gt; &lt;xs:sequence&gt; &lt;xs:element name="maidenname" type="xs:string" /&gt; &lt;/xs:sequence&gt; &lt;/xs:extension&gt; &lt;/xs:complexContent&gt; &lt;/xs:complexType&gt; &lt;!-- ... --&gt; </code></pre>
    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.
 

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