ZVON > Tutorials > XML Schema and Relax NG Tutorial |
Intro / Search / ZVON |
Index | >> Example 8 / 10 << | Prev | Next | |
Now, we want the "root" element to have either "x" and "y" attributes, or "x" and "y" elements (but not both at the same time). I do not know, how to do this with XML Schema.
You can easily choose between a group of attributes and a group of elements.
Valid document <root x="1" y="2" xmlns=""/> Valid document <root y="10" x="5" xmlns=""/> Valid document <root xmlns=""> <x/> <y/> </root> Invalid document <root xmlns=""> <y/> <x/> </root> Invalid document <root x="1" xmlns=""> <y>3</y> </root> |
Correct Relax NG schema (correctRelax_0.rng) <grammar xmlns="http://relaxng.org/ns/structure/1.0" > <start> <element> <name ns="">root</name> <choice> <group> <element name="x"> <text/> </element> <element name="y"> <text/> </element> </group> <group> <attribute name="x"> <text/> </attribute> <attribute name="y"> <text/> </attribute> </group> </choice> </element> </start> </grammar> |