[XMLSCHEMA-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: inquiry into the <choice> element behavior

From: Michael Kay <mike@saxonica.com>
Date: Fri, 31 Oct 2008 17:14:32 -0000
To: "'Alex Porras'" <alex.porras@dds.mediaocean.com>, <xmlschema-dev@w3.org>
Message-ID: <EC795E8167114F58A3E3C39EF8CBD872@Sealion>
RE: inquiry into the <choice> element behavior

> 
> Thanks for your prompt response.  If you could be so kind to 
> help me understand the result when the maxOccurs exists at 
> both the choice and the nested elements, it would be greatly 
> appreciated

I'm not sure how familiar you are with grammars and regular expressions.

In a regular expression, (a|b)* matches any string containing only a and b
characters, for example abab, aab, a, b, aaabbaabbb, and also the empty
string. By contrast, (a*|b*) matches a string consisting entirely of a's or
entirely of b's, for example aaaa or bbbb.

A maxOccurs="unbounded" on xs:element is like the "*" in a* or b*. A
maxOccurs on xs:choice is like the "*" after the parentheses.

> 
> <xs:choice maxOccurs="unbounded">
>      <xs:element name="foo" type="xs:string" maxOccurs="unbounded"/>
>      <xs:element name="bar" type="xs:string" 
> maxOccurs="unbounded"/> </xs:choice>
> 
> This would allow any number of both "foo" *and* "bar" 
> elements, right? 
> Does this contradict the purpose of the choice element to 
> begin with, or am I just misunderstanding the function of the 
> choice element?  In other words, how is scenario 2 different 
> than just having the elements on their own, without the 
> choice element?

You're asking how is (f*|b*)* different from f*b*? In the second case, all
the foo's have to come before the first bar. However, (f*|b*)* is equivalent
to (f|b)*, at least in the sense that it matches the same strings. (It might
match them in a different way, which can be relevant when using regexes).

Michael Kay
http://www.saxonica.com/
Received on Friday, 31 October 2008 17:15:24 GMT

Subscribe to the Stylus Scoop newsletter for helpful XML tips and tutorials.
Email
First Name
Last Name
Company

Download Stylus Studio 6 XML Enterprise Edition

Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2007 All Rights Reserved.