Help needed with complex schema definition

Gili Korman

Usenet Archive
Joined
Sep 24, 2003
Messages
4
Reaction score
0
Hi all,

I need to create an XSD schema that will reperesent the following:

<LIST>
<ITEM1/> 0-unbounded
<ITEM3/> 0-unbounded
</LIST>

or

<LIST>
<ITEM2/> 0-unbounded
<ITEM3/> 0-unbounded
</LIST>

The problem is that within the LIST item, the order of the elements does not matter! I found that I can't use the all model with the choice model as parent. Other solutions I tried resulted in ambigouos definition of the ITEM3 element due to "Unique Particle Attribution rule".

This is the current unsatisfactory schema, since it contains sequence which forces unwanted order:

<xs:complexType name="ListType">
<xs:sequence>
<xs:choice minOccurs="0">
<xs:element name="ITEM1" type="ITEM1Type" minOccurs="0" maxOccurs="unbounded"/> <xs:element name="ITEM2" type="ITEM2Type" minOccurs="0" maxOccurs="unbounded"/> </xs:choice> <xs:element name="ITEM3" type="ITEM3Type" minOccurs="0" maxOccurs="unbounded"/> </xs:complexType>

Any ideas?

Thanks in advance,

Gili Korman
ITG
 

Klaus Johannes Rusch

Usenet Archive
Joined
May 16, 2002
Messages
156
Reaction score
0
Gili said:
The problem is that within the LIST item, the order of the elements does not matter! I found that I can't use the all model with the choice model as parent. Other solutions I tried resulted in ambigouos definition of the ITEM3 element due to "Unique Particle Attribution rule".

This is the current unsatisfactory schema, since it contains sequence which forces unwanted order:

How about

<xs:element name="list">
<xs:complexType>
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:choice>
<xs:element ref="item1" minOccurs="1" maxOccurs="1"/>
<xs:element ref="item2" minOccurs="1" maxOccurs="1"/>
<xs:element ref="item3" minOccurs="1" maxOccurs="1"/>
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>
 

Eric Sirois

Usenet Archive
Joined
Jun 28, 2001
Messages
64
Reaction score
0
Hello if you want the item to appear in any order any number of times try the following:

<xs:complexType name="ListType">
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="ITEM1" type="ITEM1Type" />
<xs:element name="ITEM2" type="ITEM2Type" />
<xs:element name="ITEM3" type="ITEM3Type" />
</xs:choice>
</xs:complexType>

or are you trying to model that ITEM1 and ITEM2 can only appear once along with ITEM3, but there should be able to appear in any order any number of times.

Is this valid:
<LIST>
<ITEM3/>
<ITEM1/>
<ITEM1/>
</LIST>

but not:

<LIST>
<ITEM3/>
<ITEM1/>
<ITEM2/>
</LIST>

Kind regards,
Eric
 

C. M. Sperberg-McQueen

Usenet Archive
Joined
Jul 2, 2003
Messages
95
Reaction score
0
Hi all,

I need to create an XSD schema that will reperesent the following:

<LIST>
<ITEM1/> 0-unbounded
<ITEM3/> 0-unbounded
</LIST>

or

<LIST>
<ITEM2/> 0-unbounded
<ITEM3/> 0-unbounded
</LIST>

I'm not sure what this is trying to say. Can you try again?
The problem is that within the LIST item, the order of the elements does not matter!

Do you mean "it does not matter" in the sense that all possible orders should be allowed in the input? or in the sense that the order cannot possibly carry any information? (If the order cannot possibly carry any information, then a fixed order is usually a good way to go.)
Any ideas?

Not until I understand better what it is you're trying to do.

-C. M. Sperberg-McQueen
World Wide Web Consortium
 

Gili Korman

Usenet Archive
Joined
Sep 24, 2003
Messages
4
Reaction score
0
I'm not sure what this is trying to say. Can you try again?

Do you mean "it does not matter" in the sense that all possible orders should be allowed in the input? or in the sense that the order cannot possibly carry any information? (If the order cannot possibly carry any information, then a fixed order is usually a good way to go.)

Not until I understand better what it is you're trying to do.

-C. M. Sperberg-McQueen
World Wide Web Consortium

Sorry if I have been ambigouos, let me try to explain my list constraints:

A. ITEM1 and ITEM2 can not co-exist in the list.
B. The list can contain any number of ITEM1 (0-unbounded) OR any number of ITEM2 (0-unbounded), but only one of the types in a list. C. ITEM3 can also appear in the list, any number of times (0-unbounded), with or without the list having other elements. D. The order of the list does not carry any information, and so it does not matter.

So, Klaus and Eric's schemas will not be good because they allow ITEM1 and ITEM2 types in the same list.

To Eric:

<LIST>
<ITEM3/>
<ITEM1/>
<ITEM2/>
</LIST>

is not OK.

<LIST>
<ITEM3/>
<ITEM1/>
<ITEM1/>
</LIST>

is OK.

Thanks for your input, hoping for salvation...
 

Gili Korman

Usenet Archive
Joined
Sep 24, 2003
Messages
4
Reaction score
0
I would like to stress that since the order of the items in the list does not matter, I am required to allow any order - and that is the real problem !
 

C. M. Sperberg-McQueen

Usenet Archive
Joined
Jul 2, 2003
Messages
95
Reaction score
0
..., let me try to explain my list
constraints:

A. ITEM1 and ITEM2 can not co-exist in the list.
B. The list can contain any number of ITEM1 (0-unbounded) OR any number of ITEM2 (0-unbounded), but only one of the types in a list. C. ITEM3 can also appear in the list, any number of times (0-unbounded), with or without the list having other elements. D. The order of the list does not carry any information, and so it does not matter.

So, Klaus and Eric's schemas will not be good because they allow ITEM1 and ITEM2 types in the same list.

Well, I repeat what I said earlier: if the order of the items in the list does not carry any information, it is usually better practice to specify a fixed order. Otherwise, you wind up with fierce, protracted arguments between people who want to argue that

<LIST1/><LIST1/><LIST3/>

must be treated subtly differently from

<LIST3/><LIST1/><LIST1/>

or

<LIST1/><LIST3/><LIST1/>

and people who argue, on the contrary, that because the order of items carries no information, these must NOT be treated separately. It is better to nip such disagreements in the bud.

I am almost unwilling to tell you how to do what you say you want to do, on the grounds that I am convinced you shouldn't do it, but if you are determined to provide an opening for such disagreements, honesty compels me to note that it's actually not impossible, just verbose. In regex notation, what you want is

(list3* ((list1 (list1 | list3)*) | (list2 (list2 | list3)*))?)

that is: any number of list3 elements, followed optionally by a mixed list of list1 and list3, or by a mixed list of list2 and list3. In
XML Schema terms:

<xsd:complexType name="LISTtype">
<xsd:annotation><xsd:documentation>
<div xmlns="http://www.w3.org/1999/xhtml">
<p>A content model which allows any number of either LIST1 or LIST2 elements, together with any number of LIST3 elements, in any order.</p> <p>The problem with this model is that it is intended to convey the idea that "order doesn't matter" but will, by allowing different orderings of the same material, inevitably lead some users and some programmers to believe that there may be meaningful differences in meaning based on order. </p> </div></xsd:documentation></xsd:annotation> <xsd:sequence> <xsd:element ref="LIST3" minOccurs="0" maxOccurs="unbounded"/> <xsd:choice minOccurs="0"> <xsd:sequence> <xsd:element ref="LIST1"/> <xsd:choice minOccurs="0" maxOccurs="unbounded"> <xsd:element ref="LIST1"/> <xsd:element ref="LIST3"/> </xsd:choice> </xsd:sequence> <xsd:sequence> <xsd:element ref="LIST2"/> <xsd:choice minOccurs="0" maxOccurs="unbounded"> <xsd:element ref="LIST2"/> <xsd:element ref="LIST3"/> </xsd:choice> </xsd:sequence> </xsd:choice> </xsd:sequence> </xsd:complexType>

The basic idea is that the instances of this content model will inevitably be either mixtures of LIST1 and LIST3, or of LIST2 and LIST3, or just sequences of LIST3. As long as you are just getting LIST3 elements, you can't tell which of these three possibilities is being realized. Once you see a LIST1 or a LIST2, however, you know which path to take through the regular expression and the other kind of list is no longer an option. Some people have said this content-model pattern reminds them of a harpoon: once the barb is in, the harpoon only goes one direction.

The more restrictive alternative is somewhat simpler:

<xsd:complexType name="simplerLISTtype">
<xsd:annotation><xsd:documentation>
<div xmlns="http://www.w3.org/1999/xhtml">
<p>A simpler content model which prescribes an order and thus makes it impossible for variations in the order of elements to exist, let alone carry information. </p> <p>The only problem with this model is that some users will wish to convey subtle shades of meaning by putting the elements in different orders. The biggest virtue of this model is that it makes such behavior impossible. (If the shades of meaning are documented, they are worth having; otherwise, they are an illusion and only lead to tears down the road.) </p> </div></xsd:documentation></xsd:annotation> <xsd:sequence> <xsd:choice minOccurs="0"> <xsd:element ref="LIST1" maxOccurs="unbounded"/> <xsd:element ref="LIST2" maxOccurs="unbounded"/> </xsd:choice> <xsd:element ref="LIST3" minOccurs="0" maxOccurs="unbounded"/> </xsd:sequence> </xsd:complexType>

I hope this helps.

-C. M. Sperberg-McQueen
 

Gili Korman

Usenet Archive
Joined
Sep 24, 2003
Messages
4
Reaction score
0
That was a really great help. I had to use the first solution as my requirements were to allow all orders...
Thanks a lot!
 

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

No members online now.

Forum statistics

Threads
548,208
Messages
3,104,799
Members
249,594
Latest member
henrywalsh

Latest Threads

Top