[XMLSCHEMA-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Issue with repeating tags using substitution groups

From: David Broker <davidb@warpedweb.net>
Date: Mon, 7 Apr 2008 16:25:44 +1000
Message-ID: <671d7caa0804062325m25c2da33kd75fd98c6ace0b49@mail.gmail.com>
To: xmlschema-dev@w3.org
Issue with repeating tags using substitution groups
Hi,

I'm currently having an issue with defining a schema for some existing XML
(i.e. the XML structure cannot change)

The structure looks like this:

<document>
   <letter>
 <header>...</header>
 <data1>...</data1>
 <data2>...</data2>
   </letter>
   <letter>
 <header>...</header>
 <data2>...</data2>
 <data4>...</data4>
 <data1>...</data1>

   </letter>
</document>


Each letter is repeated, with a header first, then a mixture of "data" tag
which can be in any order,
but can only occur once. The "data" tags are defined by substitution groups
and are complex types.

Here is my schema:

<xs:element name="document">
 <xs:complexType>
  <xs:sequence>
   <xs:element name="letter" type="letter" minOccurs="1"
maxOccurs="unbounded" />
  </xs:sequence>
 </xs:complexType>
</xs:element>

<xs:complexType name="letter">
 <xs:sequence>
  <xs:element ref="header" />
  <xs:element ref="DataBlock" minOccurs="1" maxOccurs="unbounded" />
 </xs:sequence>
</xs:complexType>

<xs:element name="header">
....
</xs:element>

<xs:element name="DataBlock" type="DataBlockType" abstract="true" />
<xs:complexType name="DataBlockType" abstract="true" />

<xs:element name="data1" substitutionGroup="DataBlock">
 <xs:complexType>
  <xs:complexContent>
   <xs:extension base="DataBlockType">
    <xs:sequence>
     <xs:element name="id" type="xs:integer" />
    </xs:sequence>
   </xs:extension>
  </xs:complexContent>
 </xs:complexType>
</xs:element>

My problem is how to get the "DataBlock" tags to only repeat once.
The above workds fine execpt that the tags can be repeated. I have tried
combinations
of xs:choice, xs:all and xs:group but I cannot get it to work.

For example, this is valie, but shouldn't be:
<letter>
<header>...</header>
<data1>...</data1>
<data2>...</data2>
<data1>...</data1>
<data1>...</data2>
</letter>

Any ideas?

Thanks!
David
Received on Monday, 7 April 2008 08:07:13 GMT

Subscribe to the Stylus Scoop newsletter for helpful XML tips and tutorials.
Email
First Name
Last Name
Company

Download Stylus Studio 6 XML Enterprise Edition

Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2007 All Rights Reserved.