W3C home > Mailing lists > Public > xmlschema-dev@w3.org > September 2006

Re: elements with different occurance limits

From: C. M. Sperberg-McQueen <cmsmcq@acm.org>
Date: Sun, 24 Sep 2006 19:54:59 -0600
Message-Id: <305A4EDD-4637-4410-9150-908ABA198A14@acm.org>
Cc: "C. M. Sperberg-McQueen" <cmsmcq@acm.org>, xmlschema-dev@w3.org
To: John Didion <johndidion@yahoo.com>


On 19 Sep 2006, at 10:37 , John Didion wrote:

>
> I have a complex type...let's call it Foo. Foo
> potentially has five child elements:...
> My first instinct was to write this as an all:
>
> ...
> But of cource, all doesn't allow any element to appear
> more than once. I also tried writing this as a big
> choice block, with sequences for each of the possible
> ways these elements could be ordered, but the parser
> complained about potential ambiguity.
>
> Here is the element definition from the DTD that I'm
> trying to convert to XSD: ...
>

The simplest thing, if exact compatibility wtih the DTD is not
required, is to impose an order and write the equivalent of

   (A, B, ((C+, D*, E*) | (D+, E*) | E+))

If the sequence of elements has no significance, there can't
really be much argument against fixing an order.

Exact compatibility with the DTD shouldn't really be required,
since the content model you give is not legal in XML or SGML
DTDs: it violates the determinism rules.

But if you really need elements A-E, with occurrence requirements
as you describe, in any order, then a simple approach is to fix
the content model by left-factoring it to make it deterministic;
the result would be both an improved (legal) DTD and a legal
schema.  You'll end up with a large but deterministic content
model.

     (
       (A, (
             (B, (C | D | E)+ )
             |
             ( (C | D | E)+, B, (C | D | E)* )
           )
       )
       |
       (B, (
             (A, (C | D | E)+ )
             |
             ( (C | D | E)+, A, (C | D | E)* )
           )
       )
       |
       ((C | D | E)+, (
             (A, (C | D | E)*, B, (C | D | E)*)
             |
             (B, (C | D | E)*, A, (C | D | E)*)
            )
       )
     )

I've indented to make the pattern easier to see: first the
possible orders with A first, then with B first, then with C or D
or E first.  Translate this (rather than the illegal content model
you show in DTD notation) into XML Schema notation, and
you should have what you need.

A third possibility is to encourage the XML Schema working group
to make 'all' a first-class interleave operator, so that the all-group
that was your first instinct is supported.  You can do that
by sending mail to www-xml-schema-comments@w3.org or by filing
comments on XML Schema 1.1 in http://www.w3.org/Bugs/Public

I hope this helps.

--C. M. Sperberg-McQueen
   World Wide Web Consortium
Received on Monday, 25 September 2006 12:56:38 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 11 January 2011 00:14:55 GMT