XSD: xs:sequence & xs:choice combination for xs:extension elements?
Posted
by bguiz
on Stack Overflow
See other posts from Stack Overflow
or by bguiz
Published on 2010-04-23T01:28:52Z
Indexed on
2010/04/23
11:43 UTC
Read the original article
Hit count: 281
Hi,
My question is about defining an XML schema that will validate the following sample XML:
<rules>
<other>...</other>
<bool>...</bool>
<other>...</other>
<string>...</string>
<other>...</other>
</rules>
The order of the child nodes does not matter. The cardinality of the child nodes is 0..unbounded.
All the child elements of the rules
node have a common base type, rule
, like so:
<xs:complexType name="booleanRule">
<xs:complexContent>
<xs:extension base="rule">
...
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="stringFilterRule">
<xs:complexContent>
<xs:extension base="filterRule">
...
</xs:extension>
</xs:complexContent>
</xs:complexType>
My current attempt at defining the schema for the rules
node is below. However,
- Can I nest
xs:choice
withinxs:sequence
? If, where do I specify themaxOccurs="unbounded"
attribute? Is there a better way to do this, such as an
xs:sequence
which specifies only the base type of its child elements?<xs:element name="rules"> <xs:complexType> <xs:sequence> <xs:choice> <xs:element name="bool" type="booleanRule" /> <xs:element name="string" type="stringRule" /> <xs:element name="other" type="someOtherRule" /> </xs:choice> </xs:sequence> </xs:complexType> </xs:element>
© Stack Overflow or respective owner