The xml schema checks that the restriction enumeration value is only occus once

I am creating an xsd schema to validate some xml

I would like to limit xml, so it is not possible to enter the same element twice:

<branches> <branche>Bank</branche> <branche>Bank</branche> </branches> 

But it should be possible to use 2 different elements:

 <branches> <branche>Bank</branche> <branche>Insurance</branche> </branches> 

So, I have the following code:

 <!-- definition of simple elements --> <xs:simpleType name="branche"> <xs:restriction base="xs:string"> <xs:enumeration value="Bank" maxOccurs="1"/> <xs:enumeration value="Insurance" maxOccurs="1"/> </xs:restriction> </xs:simpleType> <xs:element name="branches" minOccurs="0"> <!-- minOccurs becouse i want it to be posible to leave out the whole <branches> tag --> <xs:complexType> <xs:sequence> <xs:element name="branche" type="branche" minOccurs="0" maxOccurs="2" /> </xs:sequence> </xs:complexType> </xs:element> 

using maxOccurs="1" does not limit it to just one value, because the "branche" tag can occur twice.

I want the value ( <branche>value</branche> ) to be unique.

Thnx!

+4
source share
2 answers

See examples of personality restrictions here . Sort of:

 <xs:element name="branches" ...> <xs:unique name="..."> <xs:selector xpath="branche"/> <xs:field xpath="."/> </xs:key> </xs:element> 

Not quite sure of the syntax, but you get the idea.

+4
source

Fixed with the following code:

 <xs:element name="branches" minOccurs="0"> <xs:complexType> <xs:sequence> <xs:element name="branche" type="branche" minOccurs="0" maxOccurs="2" /> </xs:sequence> </xs:complexType> <xs:unique name="brancheUnique"> <xs:selector xpath="branche"/> <xs:field xpath="."/> </xs:unique> </xs:element> 

thnx lexicore to point me in the right direction

+3
source

All Articles