Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: xml schema question

From: Jeni Tennison <jeni@------------.--->
To: Peter Menzel <peter.menzel@-----.-----------.-->
Date: 7/23/2004 2:33:00 PM
Hi Peter,

> The elements aa and bb are required to be there and they have to
> occur exactly once. Other sub elements of element can occur many
> times. Especially the order of the elements is random, so i may not
> use xsd:sequence.

This is one of the areas where XML Schema isn't very helpful because
the kind of model group that allows elements to occur in any order
(<xs:all>) only allows those elements to be optional or appear exactly
once.

The closest that you can get is to use a content model like:

  (otherElements*, ((aa, otherElements*, bb) |
                    (bb, otherElements*, aa)), otherElements*)

Use a model group to define otherElements. For example:

<xs:group name="otherElements">
  <xs:choice>
    <xs:element ref="cc" />
    <xs:element ref="dd" />
  </xs:choice>
</xs:group>

<xs:element name="element">
  <xs:complexType>
    <xs:sequence>
      <xs:group ref="otherElements" minOccurs="0"
                                    maxOccurs="unbounded" />
      <xs:choice>
        <xs:sequence>
          <xs:element ref="aa" />
          <xs:group ref="otherElements" minOccurs="0"
                                        maxOccurs="unbounded" />
          <xs:element ref="bb" />
        </xs:sequence>
        <xs:sequence>
          <xs:element ref="bb" />
          <xs:group ref="otherElements" minOccurs="0"
                                        maxOccurs="unbounded" />
          <xs:element ref="aa" />
        </xs:sequence>
      </xs:choice>
      <xs:group ref="otherElements" minOccurs="0"
                                    maxOccurs="unbounded" />
    </xs:sequence>
  </xs:complexType>
</xs:element>

It's much easier in RELAX NG, in which you can use interleave as
follows:

  <element name="element">
    <interleave>
      <element name="aa" />
      <element name="bb" />
      <zeroOrMore>
        <element name="cc" />
      </zeroOrMore>
      <zeroOrMore>
        <element name="dd" />
      </zeroOrMore>
    </interleave>
  </element>

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/

From rob@k...  Fri Jul 23 08:42:23 2004
Return-Path: <rob@k...>
X-Original-To: xmlschema-dev@l


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent