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

Re: how does one represent an alternating set of elements?

From: G. Ken Holman <gkholman@CraneSoftwrights.com>
Date: Sat, 16 Feb 2002 12:34:43 -0500
Message-Id: <5.1.0.14.0.20020216121112.021e8d20@pop1.attglobal.net>
To: <xmlschema-dev@w3.org>
At 2002-02-16 11:29 -0500, I wrote:
>At 2002-02-16 08:14 -0500, Steve Baker wrote:
>>Sorry John: the all in my last post should of course have been a
>>sequence.  IE
>>
>><?xml version = "1.0" encoding = "UTF-8"?>
>><xsd:schema xmlns:xsd = "http://www.w3.org/2001/XMLSchema">
>>
>>   <xsd:element name='A' type='xsd:anyType'/>
>>   <xsd:element name='B' type='xsd:anyType'/>
>>
>>   <xsd:element name='seqAB'>
>>     <xsd:complexType>
>>       <xsd:sequence>
>>         <xsd:group ref='seqABgroup' minOccurs='0' maxOccurs='unbounded'/>
>>         <xsd:element ref='A' minOccurs='0'/>
>>       </xsd:sequence>
>>     </xsd:complexType>
>>   </xsd:element>
>>
>>   <xsd:group name='seqABgroup'>
>>     <xsd:sequence>
>>         <xsd:element ref='A'/>
>>         <xsd:element ref='B'/>
>>     </xsd:sequence>
>>   </xsd:group>
>>
>></xsd:schema>
>
>When I try the above with the sequence (A, B, A) as requested by the 
>original poster, the MSV tool complains that it is missing a B.
>
>I think this is because of "Schema Component Constraint: Unique Particle 
>Attribution" in that you cannot have "A" selectable both from the group 
>and from the subsequent following standalone element.  This is because the 
>validator jumps into the group on the detection of the second "A" and is, 
>therefore, looking for the mandatory following "B".

I tried a RELAX-NG version of your suggestion, Steve, and it works just 
fine because there is no such unambiguous particle rule in RELAX-NG.  I've 
copied it below.

So your proposal is sound, except for the ambiguity constraint ... the 
wording in XML Schema Part 1 reads:

   A content model must be formed such that during ·validation· of an
   element information item sequence, the particle contained directly,
   indirectly or ·implicitly· therein with which to attempt to
   ·validate· each item in the sequence in turn can be uniquely
   determined without examining the content or attributes of that item,
   and without any information about the items in the remainder of the
   sequence.

I still can't figure out a way around this ambiguity to meet the original 
poster's needs.

..................... Ken

T:\ftemp>type utz1.xml
<seqAB>
   <A/>
</seqAB>
T:\ftemp>type utz2.xml
<seqAB>
   <A/>
   <B/>
</seqAB>
T:\ftemp>type utz3.xml
<seqAB>
   <A/>
   <B/>
   <A/>
</seqAB>
T:\ftemp>type utz4.xml
<seqAB>
   <A/>
   <B/>
   <A/>
   <B/>
</seqAB>
T:\ftemp>type utz5.xml
<seqAB>
   <B/>
   <A/>
   <B/>
</seqAB>
T:\ftemp>type utz6.xml
<seqAB>
   <A/>
   <B/>
   <B/>
   <A/>
   <B/>
</seqAB>
T:\ftemp>type holman.rnx
start = element seqAB
  {
   (
    element A { empty },
    element B { empty }
   )*,
   element A { empty }?
  }

T:\ftemp>rnx holman.rnx utz1.xml utz2.xml utz3.xml utz4.xml utz5.xml utz6.xml
start parsing a grammar.
validating utz1.xml
the document is valid.
--------------------------------------
validating utz2.xml
the document is valid.
--------------------------------------
validating utz3.xml
the document is valid.
--------------------------------------
validating utz4.xml
the document is valid.
--------------------------------------
validating utz5.xml
Error at line:2, column:7 of file:/T:/ftemp/utz5.xml
   tag name "B" is not allowed. Possible tag names are: <A>

the document is NOT valid.
--------------------------------------
validating utz6.xml
Error at line:4, column:7 of file:/T:/ftemp/utz6.xml
   tag name "B" is not allowed. Possible tag names are: <A>

the document is NOT valid.

T:\ftemp>


--
Upcoming: 3-days XSLT/XPath and/or 2-days XSLFO - Feb 18-22, 2002

G. Ken Holman                mailto:gkholman@CraneSoftwrights.com
Crane Softwrights Ltd.         http://www.CraneSoftwrights.com/x/
Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (Fax:-0995)
ISBN 0-13-065196-6                        Definitive XSLT & XPath
ISBN 1-894049-08-X  Practical Transformation Using XSLT and XPath
ISBN 1-894049-07-1               Practical Formatting Using XSLFO
XSL/XML/DSSSL/SGML/OmniMark services, books(electronic, printed),
articles, training(instructor-live,Internet-live,web/CD,licensed)
Next public training:         2002-02-18,21,27,03-04,05,06,11,15,
-              04-08,09,10,11,05-06,07,09,10,06-04,07,10,11,13,14
Received on Saturday, 16 February 2002 12:34:59 GMT

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