Note that there are some explanatory texts on larger screens.

plurals
  1. POXML / XSD how to create a key
    primarykey
    data
    text
    <p>I am having problems defining a key in XML Schema.</p> <p><strong>CODE:</strong></p> <p>XSD:</p> <pre><code> &lt;xsd:element name="players"&gt; &lt;xsd:complexType&gt; &lt;xsd:sequence&gt; &lt;xsd:element name="player" minOccurs="0" maxOccurs="unbounded"&gt; &lt;xsd:complexType&gt; &lt;xsd:all&gt; &lt;xsd:element name="date-of-birth" type="xsd:date"&gt;&lt;/xsd:element&gt; &lt;xsd:element name="gender"&gt; &lt;xsd:simpleType&gt; &lt;xsd:restriction base="xsd:string"&gt; &lt;xsd:enumeration value="MALE" /&gt; &lt;xsd:enumeration value="FEMALE" /&gt; &lt;/xsd:restriction&gt; &lt;/xsd:simpleType&gt; &lt;/xsd:element&gt; &lt;/xsd:all&gt; &lt;xsd:attribute name="username" type="xsd:string" use="required" /&gt; &lt;/xsd:complexType&gt; &lt;xsd:key name="playerkey"&gt; &lt;xsd:selector xpath="players/player" /&gt; &lt;xsd:field xpath="username" /&gt; &lt;/xsd:key&gt; &lt;/xsd:element&gt; &lt;/xsd:sequence&gt; &lt;/xsd:complexType&gt; &lt;/xsd:element&gt; </code></pre> <p>Note that this is only an exzerpt from the full code, but it shows all necessary information.</p> <p>XML</p> <pre><code>&lt;t:players&gt; &lt;t:player username="Super Mario"&gt; &lt;t:gender&gt;FEMALE&lt;/t:gender&gt; &lt;t:date-of-birth&gt;1995-11-29&lt;/t:date-of-birth&gt; &lt;/t:player&gt; &lt;t:player username="Super Mario"&gt; &lt;t:date-of-birth&gt;1991-10-12&lt;/t:date-of-birth&gt; &lt;t:gender&gt;MALE&lt;/t:gender&gt; &lt;/t:player&gt; &lt;/t:players&gt; </code></pre> <p><strong>PROBLEM:</strong></p> <p>As you can see I have created two players with both the name "Super Mario". Since the key should be unique this should throw and error, but xmllins does validate the files correctly</p> <p><strong>QUESTION:</strong></p> <p>How do I define the key correctly, that the elements are necessary to be unique.</p>
    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. 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