RE: XML Schema: Alternating "unbounded" elements

Mohan Raj writes:

>>  (f1 | f2 | f3 )* is exactly what i was looking for. thanks for the 
responses. 

You're most welcome.

>> i need help for one more issue. i have a situation 
>> where i would like to have something like 
>> h

That's easy, if it's really what you want.

>> one way to do this will be

>> <xs:sequence>
>> <element ref = "f1" minOccurs = "1" maxOccurs = "1">
>> <element ref = "f2" minOccurs = "1" maxOccurs = "1">
>> <element ref = "f3" minOccurs = "1" maxOccurs = "unbounded">
>> <element ref = "f4" minOccurs = "0" maxOccurs = "unbounded">
>> </xs:sequence>

No, that's equivalent to:  (f1, f2, f3+, f4*)

The correct translation of (f1?, f2?, f3*, f4+) is:

<xs:sequence>
<element ref = "f1" minOccurs = "0" maxOccurs = "1"/>
<element ref = "f2" minOccurs = "0" maxOccurs = "1"/>
<element ref = "f3" minOccurs = "0" maxOccurs = "unbounded">
<element ref = "f4" minOccurs = "1" maxOccurs = "unbounded">
</xs:sequence>

Remember: * is 0 or more, + is one or more, ? is optional (0 or 1)

>> but this imposes a sequence and requires the fields 
>> to be ordered from f1  through f4. how can i get around this?

Yes, and (f1?, f2?, f3*, f4+) is a sequence, because you separate with commas.  I 
suspect that what you're trying to say is:  elements f1, f2, f3 and f4 can 
occur mixed up in any order.  f1 and f2 are optional but occurs at most 
once, f3 occurs 0 or more times, and f4 one or more times, but in any order. 

There is not a convenient way to do this in schema.  For very small sets 
of these, you can spell out the combinations.  For example, up to 2 A 
elements and exactly one B element in any order is:

(B | (A,B) | (B,A) | (A,B,A) | (A,A,B) | (B,A,A))

As you can see, the combinationatorial explosion gets unweildy very fast, 
and you have to do the expansions carefully.  Most people just do:

(A|B)* for this, and use application logic to check the tighter 
restriction.  I hope this helps

------------------------------------------------------------------
Noah Mendelsohn                              Voice: 1-617-693-4036
IBM Corporation                                Fax: 1-617-693-8676
One Rogers Street
Cambridge, MA 02142
------------------------------------------------------------------

Received on Friday, 18 April 2003 21:42:10 UTC