ZVON > Tutorials > XML Schema and Relax NG Tutorial |
Intro / Search / ZVON |
Index | >> Example 4 / 6 << | Prev | Next | |
We will use "key" element to define, that the elements "a" under "root" element must have unique value of "id" element.
Valid document <root xsi:noNamespaceSchemaLocation="incorrect_0.xsd" xmlns="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > <a> <id>x</id> </a> <a> <id>y</id> </a> <a> <id>z</id> </a> </root> Valid document <root xsi:noNamespaceSchemaLocation="incorrect_0.xsd" xmlns="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > <a> <id xsi:nil="true"/> </a> <a> <id>y</id> </a> <a> <id>z</id> </a> </root> |
Incorrect XML Schema (incorrect_0.xsd) <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" > <xsd:element name="root" type="myList"> <xsd:key name="myId"> <xsd:selector xpath="./a"/> <xsd:field xpath="id"/> </xsd:key> </xsd:element> <xsd:complexType name="myList"> <xsd:sequence minOccurs="1"> <xsd:element name="a" minOccurs="1" maxOccurs="unbounded"> <xsd:complexType> <xsd:sequence minOccurs="1"> <xsd:element name="id" type="xsd:NCName" nillable="true"/> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:sequence> </xsd:complexType> </xsd:schema> |