<xs:all> with unbounded elements

N

nosferatu_1_1

Hi,

I would like to create a schema that validate the following xml:

<music>
<pop/>
<rock/>
<pop/>
</music>

that is, <rock> should only appear once while <pop> can appear several
times. In addition, <pop> and <rock> elements can appear in any order.

I would propose the following (invalid) schema:

<xs:element name="music">
<xs:complexType>
<xs:all>
<xs:element name="rock"/>
<xs:element name="pop" maxOccurs="unbounded"/>
</xs:all>
</xs:complexType>
</xs:element>

This schema is invalid because the constraint maxOccurs within <xs:all>
cannot be greater that 1. (Nevertheless it represents what I'm looking
for)

It seems that neither <xs:all> nor <xs:sequence> nor <xs:choice> gives
this possibility. So my question is: is there another way of defining
such a behaviour with a schema ?

I tried to generate the schema with XMLSpy but it gave me something
like:

<xs:element name="music">
<xs:complexType>
<xs:sequence>
<xs:element name="pop"/>
<xs:element name="rock"/>
<xs:element name="pop"/>
</xs:sequence>
</xs:complexType>
</xs:element>

Which is not really usefull since I don't know in advance the number of
<pop> elements.

Thanks
 
D

David Carlisle

that is, <rock> should only appear once while <pop> can appear several
times. In addition, <pop> and <rock> elements can appear in any order.

in dtd syntax you need

(rock,pop*)|(pop+,rock,pop*)

It should be easy enough to translate that back to xsd syntax.

David
 
N

nosferatu_1_1

The problem is that if I add new elements like <metal>, <soul>, etc...
the syntax you propose becomes too complex to define. My real-life
problem has about 20 different elements.
And the translation to xsd gives a solution with similar complexity.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top