P
Peter Aberline
Hi all,
I'm trying to write a schema which defines the following document.
<root>
<letters>
<a>A</a>
<dog>DOG<dog>
<b>B</b>
<fish>FISH</fish>
<c>C</c>
</letters>
<letters>
<cat>CAT<cat>
<c>C</c>
<b>B</b>
<a>A</a>
</letters>
<letters>
...
</letters>
</root>
I want my schema to define the following rules:
1: The letters element must contain a, b, and c elements in any order.
2: The letters element can also contain any number of other elements,
in any order, such as dog, cat, fish etc.
I'm having much trouble developing a schema that can enforce both
these rules simultaneously:
Requirement 1 is easy to achieve using the xs:all tag. Unfortunately,
xs:any is not allowed to be a child of xs:all, which makes requirement
2 difficult.
The following schema allows requirement 2, but not 1:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<xs:element name="a" type="xs:string"/>
<xs:element name="b" type="xs:string"/>
<xs:element name="c" type="xs:string"/>
<xs:element name="letters">
<xs:complexType>
<xs:sequence>
<xs:any namespace="##any" processContents="skip"
minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="a"/>
<xs:any namespace="##any" processContents="skip"
minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="b"/>
<xs:any namespace="##any" processContents="skip"
minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="c"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:element ref="letters" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
This schema allows requirement 1, but not 2:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<xs:element name="a" type="xs:string"/>
<xs:element name="b" type="xs:string"/>
<xs:element name="c" type="xs:string"/>
<xs:element name="letters">
<xs:complexType>
<xs:all>
<xs:element ref="a"/>
<xs:element ref="b"/>
<xs:element ref="c"/>
</xs:all>
</xs:complexType>
</xs:element>
<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:element ref="letters" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Are these requirements mutually exclusive? Is there anyway achieve
what I want using xsd schema's?
Any help from the schema guru's out there will be greatly appreciated.
thanks,
Peter
I'm trying to write a schema which defines the following document.
<root>
<letters>
<a>A</a>
<dog>DOG<dog>
<b>B</b>
<fish>FISH</fish>
<c>C</c>
</letters>
<letters>
<cat>CAT<cat>
<c>C</c>
<b>B</b>
<a>A</a>
</letters>
<letters>
...
</letters>
</root>
I want my schema to define the following rules:
1: The letters element must contain a, b, and c elements in any order.
2: The letters element can also contain any number of other elements,
in any order, such as dog, cat, fish etc.
I'm having much trouble developing a schema that can enforce both
these rules simultaneously:
Requirement 1 is easy to achieve using the xs:all tag. Unfortunately,
xs:any is not allowed to be a child of xs:all, which makes requirement
2 difficult.
The following schema allows requirement 2, but not 1:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<xs:element name="a" type="xs:string"/>
<xs:element name="b" type="xs:string"/>
<xs:element name="c" type="xs:string"/>
<xs:element name="letters">
<xs:complexType>
<xs:sequence>
<xs:any namespace="##any" processContents="skip"
minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="a"/>
<xs:any namespace="##any" processContents="skip"
minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="b"/>
<xs:any namespace="##any" processContents="skip"
minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="c"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:element ref="letters" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
This schema allows requirement 1, but not 2:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<xs:element name="a" type="xs:string"/>
<xs:element name="b" type="xs:string"/>
<xs:element name="c" type="xs:string"/>
<xs:element name="letters">
<xs:complexType>
<xs:all>
<xs:element ref="a"/>
<xs:element ref="b"/>
<xs:element ref="c"/>
</xs:all>
</xs:complexType>
</xs:element>
<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:element ref="letters" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Are these requirements mutually exclusive? Is there anyway achieve
what I want using xsd schema's?
Any help from the schema guru's out there will be greatly appreciated.
thanks,
Peter