xml schema putting both sequence and all under one complexType node
Here is the xml file:
<section>
<number>1</number>
<title>A Title goes here...</title>
<code>TheCode</code>
<element></element>
<element></element>
</section>
In section node, there are number, title and code node. Their sequence must not be fixed. Then, there are multiple element under section node as well.
The idea is to use the following schema:
<xs:complexType name="Type-section">
<xs:all>
<xs:element name="number" minOccurs="0"></xs:element>
<xs:element name="code" minOccurs="1"></xs:element>
&开发者_如何学Golt;xs:element name="title" minOccurs="1"></xs:element>
</xs:all>
<xs:sequence>
<xs:element maxOccurs="unbounded" name="element"></xs:element>
</xs:sequence>
</xs:complexType>
But it is invalid. I just cant put "sequence" and "all" together in the same level. How can i fix it?
If the order must not be important, then a way you can do it is to list all the permutations and put it in as a choice. However it is going to be quite hard to maintain as the number of choices grows O(n!). I had to revert to sequence for some of the things I write because of limitations such as these on XML Schema.
e.g.
<choice>
<sequence>
<element name="a" />
<element name="b" />
<element name="c" />
</sequence>
<sequence>
<element name="a" />
<element name="c" />
<element name="b" />
</sequence>
<sequence>
<element name="b" />
<element name="a" />
<element name="c" />
</sequence>
<sequence>
<element name="b" />
<element name="c" />
<element name="a" />
</sequence>
<sequence>
<element name="c" />
<element name="a" />
<element name="b" />
</sequence>
<sequence>
<element name="c" />
<element name="b" />
<element name="a" />
</sequence>
</choice>
精彩评论