Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Describe repeating XML nodes in W3C XML Schema?

Tags:

xml

schema

xsd

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">
    <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?

like image 934
NotMyName Avatar asked Apr 06 '10 20:04

NotMyName


1 Answers

Schematron. :)

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

like image 171
lexicore Avatar answered Sep 17 '22 10:09

lexicore