Lists Home |
Date Index |
Roger L. Costello wrote:
> Below I have jotted down a few thoughts regarding XML Schemas which permit
> an unbounded number of occurrences. Namely, I recommend against using
> maxOccurs="unbounded" in an XML Schema. I am interested in hearing your
> thoughts on this.
My thoughts lead to the exact opposite conclusion:
you should never use anything *except* maxOccurs="unbounded"
(or maxOccurs="1") in a schema.
With very few exceptions, any attempt to devise a suitable
upper bound for any 'maxOccurs' value is bound to involve
wild-ass-guessery. How many paragraphs should one allow
in an HTML document? You can take this from a business logic
standpoint ("what's the longest web page anyone is ever
going to want to produce"), or a processing standpoint
(how many <p> elements can Mozilla cope with? What about
MSIE? Does your answer change depending on how old the
user's computer is?), but you'll never be able to come up
with a satisfactory number. Whatever number you choose
will either be too large as a meaningful resource constraint,
or it will be too small for some existing or future document.
What you advocate is reminiscent of the QUANTITY and CAPACITY
sections of the SGML declaration. These were a perpetual annnoyance
(the SGML declaration was the first thing that got dumped
when XML was being designed), and as far as I know they
never did anybody any good (i.e., they were never an accurate
indication of how large a document any particular application
could actually handle).
> 1. Don't use maxOccurs="unbounded"
> 2. Don't use recursive constructions
> 3. Set maxOccurs to a number no larger than the amount of resources you
> have available
I'd argue the exact opposite, mostly because (3) is in
practice impossible to answer, and rarely worth even trying
to answer in the first place.
There are only three sensible cardinalities: zero, one, and many.
There are only four sensible cardinality constraints: mandatory,
optional, mandatory+repeatable and mandatory+optional.
(Corrolary: "?", "+", and "*" operators as found in DTDs and Relax NG
are far more appropriate than WXS' separate minOccurs= and maxOccurs=