Describe repeating XML nodes in W3C XML Schema?
Posted
by NotMyName
on Stack Overflow
See other posts from Stack Overflow
or by NotMyName
Published on 2010-04-06T20:44:31Z
Indexed on
2010/04/06
21:03 UTC
Read the original article
Hit count: 659
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?
© Stack Overflow or respective owner