1

Topic: XSD: restriction on kol-in and uniqueness of elements in sequence

The simplified example: it is necessary to transfer in a tag urls the certain links grouped in operating systems: ios, android, winphone with observance resulted below conditions:
1) in a tag urls one element should be specified at least;
2) on each of operating systems cannot be more than one link.
It is necessary to think over a format of transmission and XSD for .
Variant 1:

<xs:schema xmlns:xs = "http://www.w3.org/2001/XMLSchema">
<xs:element name = "urls">
<xs:complexType>
<xs:sequence>
<xs:element name = "ios" type = "xs:string" minOccurs = "0"/>
<xs:element name = "android" type = "xs:string" minOccurs = "0"/>
<xs:element name = "winphone" type = "xs:string" minOccurs = "0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

Normally fulfills (successfully ) for resulted below examples:

<urls>
<ios> url1 </ios>
<android> url2 </android>
<winphone> url3 </winphone>
</urls>

<urls>
<ios> url1 </ios>
<android> url2 </android>
</urls>

But, unfortunately, does not swear on a variant. I.e. compulsion of an element is not checked.

<urls>
</urls>

Changeover

<xs:sequence>

on

<xs:sequence minOccurs = "1">

effect on gives.
Variant 2

<xs:schema xmlns:xs = "http://www.w3.org/2001/XMLSchema">
<xs:element name = "urls">
<xs:complexType>
<xs:sequence>
<xs:element name = "url" maxOccurs = "unbounded">
<xs:complexType>
<xs:simpleContent>
<xs:extension base = "xs:string">
<xs:attribute name = "type">
<xs:simpleType>
<xs:restriction base = "xs:string">
<xs:enumeration value = "ios"/>
<xs:enumeration value = "android"/>
<xs:enumeration value = "winphone"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

Normally fulfills (successfully ) for resulted below an example:

<urls>
<url type = "ios"> url1 </url>
<url type = "android"> url2 </url>
</urls>

But, unfortunately, does not swear on a variant where for android it is given more than one element. ., uniqueness is not checked.

<urls>
<url type = "ios"> url1 </url>
<url type = "android"> url2 </url>
<url type = "android"> url3 </url>
</urls>

Whether there is a possibility  my case at level XSD?

2

Re: XSD: restriction on kol-in and uniqueness of elements in sequence

AmKad wrote:

the Variant 2

<xs:element name = "urls">
<xs:complexType>
<xs:sequence>
............
</xs:sequence>
</xs:complexType>
<xs:key name = "keyURL">
<xs:selector xpath = "url"/>
<xs:field xpath = "type"/>
</xs:key>
</xs:element>

3

Re: XSD: restriction on kol-in and uniqueness of elements in sequence

_Vasilisk _;
Thanks. That is necessary. Esteemed about it on msdn and w3.org .

<xs:schema xmlns:xs = "http://www.w3.org/2001/XMLSchema">
<xs:element name = "urls">
<xs:complexType>
<xs:sequence>
<xs:element name = "url" maxOccurs = "unbounded">
<xs:complexType>
<xs:simpleContent>
<xs:extension base = "xs:string">
<xs:attribute name = "type">
<xs:simpleType>
<xs:restriction base = "xs:string">
<xs:enumeration value = "ios"/>
<xs:enumeration value = "android"/>
<xs:enumeration value = "winphone"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:key name = "keyURL">
<xs:selector xpath = "url"/>
<xs:field xpath = "type"/>
</xs:key>
</xs:element>
</xs:schema>