Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > <xs:all> with unbounded elements

Reply
Thread Tools

<xs:all> with unbounded elements

 
 
nosferatu_1_1@yahoo.com
Guest
Posts: n/a
 
      02-23-2005
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

 
Reply With Quote
 
 
 
 
David Carlisle
Guest
Posts: n/a
 
      02-23-2005

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

 
Reply With Quote
 
 
 
 
nosferatu_1_1@yahoo.com
Guest
Posts: n/a
 
      02-23-2005
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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
The usage of <xs:choice maxOccurs="unbounded"> mavis XML 2 06-01-2006 05:02 PM
The usage of <xs:choice maxOccurs="unbounded"> Mavis Java 0 06-01-2006 06:12 AM
Creating araays as unbounded elements instead of "ArrayOf" elements John Harvey ASP .Net Web Services 0 01-09-2006 06:02 PM
How to skip the unbounded column...? new bie Maheshkumar.R ASP .Net Datagrid Control 1 06-16-2005 02:10 PM
Unbounded Datagrid Fabiano ASP .Net Web Controls 3 05-11-2004 01:21 AM



Advertisments