views:

184

answers:

2

I have an XML document like:

<Root>
    <Bravo />
    <Alpha />
    <Charlie />
    <Charlie />
    <Delta />
    <Foxtrot />
    <Charlie />
</Root>

The order of the nodes does not matter. Each node may appear zero or one times, except for Charlie. Charlie may appear zero, one, or arbitrarily many times. The straightforward way to express this in XSD is:

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
    <xsd:element name="Root">
        <xsd:complexType>
            <xsd:all>
                <xsd:element name="Alpha" minOccurs="0" maxOccurs="1" />
                <xsd:element name="Bravo" minOccurs="0" maxOccurs="1" />
                <xsd:element name="Charlie" minOccurs="0" maxOccurs="unbounded" />
                <xsd:element name="Delta" minOccurs="0" maxOccurs="1" />
                <xsd:element name="Echo" minOccurs="0" maxOccurs="1" />
                <xsd:element name="Foxtrot" minOccurs="0" maxOccurs="1" />
            </xsd:all>
        </xsd:complexType>
    </xsd:element>
</xsd:schema>

But this does not work, because xsd:all does not allow for maxOccurs greater than 1. Since I cannot use xsd:all, what should I use?

+2  A: 

Schematron. :)

I am not 100% sure, but I think this model cannot be expressed in XML Schema.

lexicore
A: 

You could use xsd:sequence, but then the order would be important which you have stated in the question will not be guaranteed.

Looking at: http://www.w3.org/TR/2004/REC-xmlschema-1-20041028/structures.html#element-group it seems that there is not a model group that you can use, although maybe you could just define them in the complexType without using a content group?

JonathanJ
There has to be an indicator: sequence, choice, all. Yet none of those on their own match what I need.
NotMyName