Re: Help with Groups

At 10:50 00/03/17 -0800, Bell, David I wrote:
>Kind Readers,
>
>I'm not quite sure how to express the following in XML Schema:
>
>I want a group such that each item in the group may appear zero or one times
>and there must be at least one element present.  For example, element <x>
>can contain elements chosen from the set {<a>, <b>, <c>, <d>}.  Each element
>in the set may appear at most once and element <x> must not be empty. 
>
>How do I express this in XML Schema?  Any help would be appreciated.

There appears not to have been an answer to your question; my apologies.

You say "set", so I assume there is not a required order to the elements.
You don't specify whether it would be acceptable to impose an order.  If so,
then your model is (using DTD notation, because it's more compact):

 ((a, b?, c?, d?) | (b, c?, d?) | (c, d?) | d)

If it is not acceptable to impose an order on the elements, then the language
you want can be defined using XML Schema, but not compactly.  Reducing the set
to three members because it's late and I'm getting tired, the content model
would be:

 ((a, ((b, c?)? | (c, b?))) 
  | (b, ((a, c?)? | (c, a?))) 
  | (c, ((a, b?)? | (b, a?))))
 
As you can see, the size of the model explodes pretty fast.  But like
any complex regular expression it's just a matter of grinding out the
variations until you have what you need.  (Most DTD designers I know
end up deciding it's better to impose an arbitrary order.)

At various times, it has been suggested that a length attribute be allowed
on the definition of a complex type, which would be applied to the total
length of the sequence of children.  That proposal would allow you to declare
your type this way:

  <complexType name="bell" minLength="1">
    <all>
      <element ref="a" minOccurs="0" maxOccurs="1"/>
      <element ref="b" minOccurs="0" maxOccurs="1"/>
      <element ref="c" minOccurs="0" maxOccurs="1"/>
      <element ref="d" minOccurs="0" maxOccurs="1"/>
    </all>
  </complexType>

The interactions with other mechanisms were not obviously problem-free,
however (how is length applied to mixed content?) so the WG has never 
adopted this proposal. 

-C. M. Sperberg-McQueen

Received on Tuesday, 9 May 2000 10:53:40 UTC