ZVON > Tutorials > XML Schema and Relax NG Tutorial |
Intro / Search / ZVON |
Index | >> Example 1 / 2 << | Prev | Next | |
Please, send all comments, bug-reports, and contributions to Jiri.Jirat@systinet.com. Thank you very much.
XML Schema keys: sequence, extensionWhen we extend the complexType, which contains a sequence A with a sequence B, then the sequence B will be appended to sequence A.
Valid document <root xsi:noNamespaceSchemaLocation="correct_0.xsd" xmlns="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > <x>1</x> <x>2</x> <x>3</x> <y>1</y> <y>2</y> <y>3</y> </root> Invalid document <root xsi:noNamespaceSchemaLocation="correct_0.xsd" xmlns="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > <y>1</y> <y>2</y> <y>3</y> <x>1</x> <x>2</x> <x>3</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:sequence> <xsd:element name="x" type="xsd:string" minOccurs="3" maxOccurs="3"/> </xsd:sequence> </xsd:complexType> <xsd:complexType name="BBB"> <xsd:complexContent> <xsd:extension base="AAA"> <xsd:sequence> <xsd:element name="y" type="xsd:string" minOccurs="3" maxOccurs="3"/> </xsd:sequence> </xsd:extension> </xsd:complexContent> </xsd:complexType> </xsd:schema> |
We can simulate the same behaviour in Relax NG using the "define" and "ref" elements.
Valid document <root xmlns=""> <x>1</x> <x>2</x> <x>3</x> <y>1</y> <y>2</y> <y>3</y> </root> Invalid document <root xmlns=""> <y>1</y> <y>2</y> <y>3</y> <x>1</x> <x>2</x> <x>3</x> </root> |
Correct Relax NG schema (correctRelax_0.rng) <grammar ns="" xmlns="http://relaxng.org/ns/structure/1.0" > <start> <element name="root"> <ref name="BBB"/> </element> </start> <define name="AAA"> <element name="x"> <text/> </element> <element name="x"> <text/> </element> <element name="x"> <text/> </element> </define> <define name="BBB"> <ref name="AAA"/> <element name="y"> <text/> </element> <element name="y"> <text/> </element> <element name="y"> <text/> </element> </define> </grammar> |