XML - Schema Element with attribute and sequence of sub-elements <p>I have a XML schema as follows:</p> <pre><code>&lt;?xml version="1.0" encoding="ISO-8859-1"?&gt; &lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"&gt; &lt;xs:element name="labels"&gt; &lt;xs:complexType&gt; &lt;xs:sequence&gt; &lt;xs:element name="label" minOccurs="1" maxOccurs="unbounded"&gt; &lt;xs:complexType&gt; &lt;xs:sequence&gt; &lt;xs:element name="language" minOccurs="1" maxOccurs="unbounded"&gt; &lt;xs:complexType&gt; &lt;xs:simpleContent&gt; &lt;xs:extension base="xs:string"&gt; &lt;xs:attribute name="value" type="xs:string" /&gt; &lt;/xs:extension&gt; &lt;/xs:simpleContent&gt; &lt;/xs:complexType&gt; &lt;/xs:element&gt; &lt;/xs:sequence&gt; &lt;/xs:complexType&gt; &lt;/xs:element&gt; &lt;/xs:sequence&gt; &lt;/xs:complexType&gt; &lt;/xs:element&gt; &lt;/xs:schema&gt; </code></pre> <p><code>&lt;labels&gt;</code> can have many <code>&lt;label&gt;</code> elements, and a <code>&lt;label&gt;</code> element can have many <code>&lt;language&gt;</code> elements. Now what i need is for my <code>&lt;label&gt;</code> element to have a unique attribute called 'identifier'.</p> <p>I want to have a XML structure like this:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;labels xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:noNamespaceSchemaLocation='labels.xsd'&gt; &lt;label identifier="class_contact"&gt; &lt;language value="english"&gt;Contacts&lt;/language&gt; &lt;language value="afrikaans"&gt;Kontakte&lt;/language&gt; &lt;/label&gt; &lt;/labels&gt; </code></pre> <p>OK i changed it to this, now it allows for the identifier attribute but it does not enforce it to be unique.</p> <pre><code>&lt;?xml version="1.0" encoding="ISO-8859-1"?&gt; &lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"&gt; &lt;xs:element name="labels"&gt; &lt;xs:complexType&gt; &lt;xs:sequence&gt; &lt;xs:element name="label" maxOccurs="unbounded"&gt; &lt;xs:complexType&gt; &lt;xs:sequence&gt; &lt;xs:element name="language" minOccurs="1" maxOccurs="unbounded"&gt; &lt;xs:complexType&gt; &lt;xs:simpleContent&gt; &lt;xs:extension base="xs:string"&gt; &lt;xs:attribute name="value" type="xs:string" /&gt; &lt;/xs:extension&gt; &lt;/xs:simpleContent&gt; &lt;/xs:complexType&gt; &lt;/xs:element&gt; &lt;/xs:sequence&gt; &lt;xs:attribute name="identifier" type="xs:string" /&gt; &lt;/xs:complexType&gt; &lt;xs:unique name="UniqueLabelLanguage"&gt; &lt;xs:selector xpath="language" /&gt; &lt;xs:field xpath="@value" /&gt; &lt;/xs:unique&gt; &lt;xs:unique name="UniqueLabelIdentifier"&gt; &lt;xs:selector xpath="label" /&gt; &lt;xs:field xpath="@identifier" /&gt; &lt;/xs:unique&gt; &lt;/xs:element&gt; &lt;/xs:sequence&gt; &lt;/xs:complexType&gt; &lt;/xs:element&gt; &lt;/xs:schema&gt; </code></pre>