Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Alternative tags in element?

From: "G. Ken Holman" <gkholman@----------------.--->
To: "xmlschema-dev@--.---" <-------------@--.--->
Date: 5/2/2009 6:20:00 PM
At 2009-04-30 22:06 +1000, Paul Steckler wrote:
>   I want to create an element, say "Foo" that contains a sequence 
> of elements which
>have different tags, say "Bar" and "Glob".  So these would be legal:
>
>    <Foo><Glob/><Bar/></Foo>
>
>   <Foo><Bar/><Glob/></Foo>
>
>   <Foo><Bar/><Glob/><Bar/></Foo>
>
>In the complexType for Foo elements, can you specify that it 
>contains a sequence
>of alternative elements, in arbitrary order?

Yes, it could be called an "unbounded choice".

Unless, perhaps, by "alternative" you mean that they alternate from 
one to the other?  I'm guessing not.

>Or do I have to create a wrapper element
>for the alternatives and place them in a union?

Nope.

I hope the example below helps.

. . . . . . . Ken

t:\ftemp>type steckler1.xml
<Foo><Glob/><Bar/></Foo>

t:\ftemp>type steckler2.xml
<Foo><Bar/><Glob/></Foo>

t:\ftemp>type steckler3.xml
<Foo><Bar/><Glob/><Bar/></Foo>

t:\ftemp>type steckler4-bad.xml
<Foo><Bar/><Baz/></Foo>

t:\ftemp>type steckler.xsd
<?xml version="1.0" encoding="US-ASCII"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<xsd:annotation>
  <xsd:documentation xml:lang="en">
    Paul's example
  </xsd:documentation>
</xsd:annotation>

<xsd:element name="Foo">
   <xsd:complexType>
     <xsd:choice maxOccurs="unbounded">
       <xsd:element name="Bar"/>
       <xsd:element name="Glob"/>
     </xsd:choice>
   </xsd:complexType>
</xsd:element>

</xsd:schema>

t:\ftemp>w3cschema-saxon steckler.xsd steckler1.xml
No validation errors.

t:\ftemp>w3cschema-saxon steckler.xsd steckler2.xml
No validation errors.

t:\ftemp>w3cschema-saxon steckler.xsd steckler3.xml
No validation errors.

t:\ftemp>w3cschema-saxon steckler.xsd steckler4-bad.xml
Validation error on line 1 column 18 of steckler4-bad.xml:
   In content of element <Foo>: The content model does not allow 
element <Baz> to appear
   here. Expected one of: Bar, Glob (See 
http://www.w3.org/TR/xmlschema-1/#cvc-complex-type clause 2.4)
No validation errors.

t:\ftemp>

--
XQuery/XSLT/XSL-FO hands-on training - Los Angeles, USA 2009-06-08
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/x/
Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video
Video lesson:    http://www.youtube.com/watch?v=PrNjJCh7Ppg&fmt=18
Video overview:  http://www.youtube.com/watch?v=VTiodiij6gE&fmt=18
G. Ken Holman                 mailto:gkholman@C...
Male Cancer Awareness Nov'07  http://www.CraneSoftwrights.com/x/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal


From rjelliffe@a... Sun May 03 06:00:10 2009
Received: from maggie.w3.org ([193.51.208.68])
	by frink.w3.org with esmtp (Exim 


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