Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Issue with repeating tags using substitution groups

From: "David Broker" <davidb@---------.--->
To: xmlschema-dev@--.---
Date: 4/8/2008 9:23:00 PM
Thanks Michael,

I was beginning to think that myself.

I've decided to ignore the the fact that the header tag must be first and
add all the children of <letter> to a group using <xsd:all>. The most
important constraint is that the "data" tags can appear only once and in any
order.

My main aim was to not have to add each "data" element to a group but it
doesn't look like I will be able to avoid that.

Here is the resulting schema:

<xs:element name="document">
 <xs:complexType>
  <xs:sequence>

   <xs:element name="letter" minOccurs="1" maxOccurs="unbounded">
    <xs:complexType>
     <xs:group ref="dataBlockGroup"/>

    </xs:complexType>
   </xs:element>
  </xs:sequence>
 </xs:complexType>
</xs:element>
<xs:group name="dataBlockGroup">
 <xs:all>
  <xs:element ref="header" minOccurs="0" maxOccurs="1"/>
  <xs:element ref="data1" minOccurs="0" maxOccurs="1"/>
 </xs:all>
</xs:group>
<xs:element name="header">
 <xs:complexType>
  <xs:sequence>
   <xs:element name="headerId" type="xs:integer" />
  </xs:sequence>
 </xs:complexType>
</xs:element>
<xs:element name="data1">
 <xs:complexType>
  <xs:sequence>

   <xs:element name="id" type="xs:integer" />
  </xs:sequence>

 </xs:complexType>
</xs:element>

Thank you Michael & Borris for you help.

Regards,
David

On Mon, Apr 7, 2008 at 6:30 PM, Michael Kay <mike@s...> wrote:

>    I don't think this can be done in XML Schema 1.0.
> >
> > When you're trying to write a schema to describe an existing XML
> > document structure, it's often the case that not all the constraints can be
> > expressed.
> >
> > Michael Kay
> > http://www.saxonica.com/
> >
> >  ------------------------------
> > *From:* xmlschema-dev-request@w... [mailto:
> > xmlschema-dev-request@w...] *On Behalf Of *David Broker
> > *Sent:* 07 April 2008 07:26
> > *To:* xmlschema-dev@w...
> > *Subject:* 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
> >
> >
>


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