W3C home > Mailing lists > Public > xmlschema-dev@w3.org > June 2001

Re: Question about complexType with unordered child elements with at least one child element

From: Eddie Robertsson <eddie@allette.com.au>
Date: Wed, 27 Jun 2001 12:52:05 +1000
Message-ID: <3B394A55.2BA23686@allette.com.au>
To: vdv@dyomedea.com
CC: xmlschema-dev@w3.org
Hi,

> > I need some help.
> > I need a type that allows any order of child elements, every element can
> > appear no more than a single time.
> .../...
> > I need at least one child element.
>
> I don't think you can capture this with W3C XML Schema...
>
> Try another schema language :=) ...

Or a combination of more than one. This would be trivial to do by combining
Schematron with W3C XML Schema. With embedded Schematron that checks the
additional constraint your ApplicationRequest type would be:

 <xsd:complexType name="ApplicationRequest">
  <xsd:annotation>
   <xsd:appinfo>
    <sch:pattern name="At least one one child">
     <sch:rule context="ApplicationRequest">
      <sch:assert test="count(*) &gt;= 1">You must have at least one child
element of the <sch:name/> element.</sch:assert>
     </sch:rule>
    </sch:pattern>
   </xsd:appinfo>
  </xsd:annotation>
                <xsd:all>
                        <xsd:element name="PermissionRequestSet"
type="xsd:string" minOccurs="0"/>
                        <xsd:element name="LocationRequestSet"
type="xsd:string" minOccurs="0"/>
                        <xsd:element name="MapRequestSet" type="xsd:string"
minOccurs="0"/>
                        <xsd:element name="InfoRequestSet" type="xsd:string"
minOccurs="0"/>
                        <xsd:element name="GeoCodeRequestSet"
type="xsd:string" minOccurs="0"/>
                        <xsd:element name="GeoItemsRequestSet"
type="xsd:string" minOccurs="0"/>
                        <xsd:element name="RouteRequestSet" type="xsd:string"
minOccurs="0"/>
                </xsd:all>
 </xsd:complexType>

For more information about embedding Schematron within XML Schema see
http://www.xfront.com/ExtendingSchemas.html.

Cheers,
/Eddie
Received on Tuesday, 26 June 2001 22:52:21 GMT

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