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