ZVON > Tutorials > XML Schema and Relax NG Tutorial |
Intro / Search / ZVON |
Index | >> Example 6 / 8 << | Prev | Next | |
Please, send all comments, bug-reports, and contributions to Jiri.Jirat@systinet.com. Thank you very much.
XML Schema keys: restriction, sequence, allWe can "change" the "all" type to "sequence". Schema Component Constraint: Particle Derivation OK (Sequence:All - RecurseUnordered)
Valid document <root xsi:noNamespaceSchemaLocation="correct_0.xsd" xmlns="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > <x>1</x> <y>1</y> </root> Invalid document <root xsi:noNamespaceSchemaLocation="correct_0.xsd" xmlns="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > <y>1</y> <x>1</x> </root> |
Correct XML Schema (correct_0.xsd) <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" > <xsd:element name="root" type="BBB"/> <xsd:complexType name="AAA"> <xsd:all maxOccurs="1"> <xsd:element name="x" type="xsd:string" minOccurs="1" maxOccurs="1"/> <xsd:element name="y" type="xsd:string" minOccurs="1" maxOccurs="1"/> </xsd:all> </xsd:complexType> <xsd:complexType name="BBB"> <xsd:complexContent> <xsd:restriction base="AAA"> <xsd:sequence maxOccurs="1"> <xsd:element name="x" type="xsd:string" minOccurs="1" maxOccurs="1"/> <xsd:element name="y" type="xsd:string" minOccurs="1" maxOccurs="1"/> </xsd:sequence> </xsd:restriction> </xsd:complexContent> </xsd:complexType> </xsd:schema> |
We can "change" the "all" type to "sequence". We can define the sequence reordered. Schema Component Constraint: Particle Derivation OK (Sequence:All - RecurseUnordered)
Valid document <root xsi:noNamespaceSchemaLocation="correct_0.xsd" xmlns="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > <y>1</y> <x>1</x> </root> Invalid document <root xsi:noNamespaceSchemaLocation="correct_0.xsd" xmlns="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > <x>1</x> <y>1</y> </root> |
Correct XML Schema (correct_0.xsd) <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" > <xsd:element name="root" type="BBB"/> <xsd:complexType name="AAA"> <xsd:all maxOccurs="1"> <xsd:element name="x" type="xsd:string" minOccurs="1" maxOccurs="1"/> <xsd:element name="y" type="xsd:string" minOccurs="1" maxOccurs="1"/> </xsd:all> </xsd:complexType> <xsd:complexType name="BBB"> <xsd:complexContent> <xsd:restriction base="AAA"> <xsd:sequence maxOccurs="1"> <xsd:element name="y" type="xsd:string" minOccurs="1" maxOccurs="1"/> <xsd:element name="x" type="xsd:string" minOccurs="1" maxOccurs="1"/> </xsd:sequence> </xsd:restriction> </xsd:complexContent> </xsd:complexType> </xsd:schema> |
When we derive "sequence" from "all", we cannot map each element from the "all" group to more than one element from the "sequence" group. Schema Component Constraint: Particle Derivation OK (Sequence:All - RecurseUnordered), 2.1 . In our example, we want to have two "x" elements in the sequence and that's not allowed.
Incorrect XML Schema (incorrect_0.xsd) <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" > <xsd:element name="root" type="BBB"/> <xsd:complexType name="AAA"> <xsd:all maxOccurs="1"> <xsd:element name="x" type="xsd:string" minOccurs="1" maxOccurs="1"/> <xsd:element name="y" type="xsd:string" minOccurs="1" maxOccurs="1"/> </xsd:all> </xsd:complexType> <xsd:complexType name="BBB"> <xsd:complexContent> <xsd:restriction base="AAA"> <xsd:sequence maxOccurs="1"> <xsd:element name="x" type="xsd:string" minOccurs="1" maxOccurs="1"/> <xsd:element name="y" type="xsd:string" minOccurs="1" maxOccurs="1"/> <xsd:element name="x" type="xsd:string" minOccurs="1" maxOccurs="1"/> </xsd:sequence> </xsd:restriction> </xsd:complexContent> </xsd:complexType> </xsd:schema> |