xsd:any as a child of xsd:all

Discussion in 'XML' started by Peter Aberline, Apr 5, 2004.

  1. 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
    Peter Aberline, Apr 5, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. bhchng
    Replies:
    0
    Views:
    653
    bhchng
    Jan 13, 2004
  2. davout
    Replies:
    0
    Views:
    549
    davout
    Apr 18, 2004
  3. Markus
    Replies:
    1
    Views:
    1,097
    Markus
    Nov 22, 2005
  4. leon
    Replies:
    0
    Views:
    427
  5. Jeff Rodriguez
    Replies:
    23
    Views:
    1,116
    David Schwartz
    Dec 9, 2003
Loading...

Share This Page