W3C home > Mailing lists > Public > xmlschema-dev@w3.org > May 2002

Re: Help: transforming "sequence" into "all" content model.

From: Eric van der Vlist <vdv@dyomedea.com>
Date: 12 May 2002 00:02:22 +0200
To: Emer Magnani <Emer.Magnani@di3.co.uk>
Cc: "'xmlschema-dev@w3.org'" <xmlschema-dev@w3.org>
Message-Id: <1021154543.18185.41.camel@ibook>

On Wed, 2002-05-08 at 11:41, Emer Magnani wrote:
> Hi,
> I have an xml schema that defines elements using the "sequence" content
> model.  I am trying to modify the schema so that it allows child elements to
> appear in any order.  Here is sample element:
code snipped.
> Looking at the definition of the "all" content model, it appears to me that
> the "all" content model cannot be used to express such a hierarchical
> structure.  Is there any work around?

Yes, there are *some* workarounds which are not generic but may help is
some cases.

First, if you can (and accept to) change the structure of your markup,
you can add a container to make your structure fit into the xs:all mold:


would do the trick.

Alternatively, in your case, transforming propertyA and propertyB into
attributes would also allow to specify your content model with a

Now, if you can't (or don't want to) change the structure of the
instance documents, the closest you can get to your document is through
using xs:choice:

<xs:element name="myNode>
    <xs:choice minOccurs="0" maxOccurs="0">
      <xs:element ref="propertyA"/>
      <xs:element ref="propertyB"/>
      <xs:element ref="myNode"/>

By doing so, you loose the constraint on propertyA and B occuring at
most one time. You can express this adding a constraint using a rule
based schema language such as schematron, but you may also have a
workaround hacking a xs:unique constraint and if you write:

<xs:element name="myNode>
    <xs:choice minOccurs="0" maxOccurs="0">
      <xs:element ref="propertyA"/>
      <xs:element ref="propertyB"/>
      <xs:element ref="myNode"/>
  <xs:unique name="checkPropertyA">
    <xs:selector xpath=".">
    <xs:field xpath="propertyA">

There would be a violation of the xs:unique rule if the path identified
by xs:field had more than one occurrence for an occurrence of the path
identified by the xs:selector (ie in clear if there was more than one
propertyA element.

Note that the error messsage in this case will probably be very
confusing for a end user :-) ...

Hope this helps.


See you in Barcelona.
Eric van der Vlist       http://xmlfr.org            http://dyomedea.com
http://xsltunit.org      http://4xt.org           http://examplotron.org
Received on Saturday, 11 May 2002 18:02:25 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 23:15:01 UTC