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

Re: Using xs:all question

From: C. M. Sperberg-McQueen <cmsmcq@blackmesatech.com>
Date: Fri, 12 Feb 2010 15:56:58 -0700
Cc: "C. M. Sperberg-McQueen" <cmsmcq@blackmesatech.com>, "xmlschema-dev@w3.org" <xmlschema-dev@w3.org>
Message-Id: <6793CD30-E342-499C-9F71-D8F5195AFAF0@blackmesatech.com>
To: "Hintz, David" <david.hintz@siemens.com>

On 12 Feb 2010, at 10:23 , Hintz, David wrote:

> Hi,
>
> I want to define an element <a> that allows <b> or <c> in any order.  
> Elements <b> and <c> are both optional, but <a> cannot be empty  
> (requires at least one of <b> or <c>).
>
> I thought this would work, but no joy (insists that both <b> and <c>  
> are required) with Arbortext Editor:
>
>   <xs:element name="a">
>     <xs:complexType>
>       <xs:all minOccurs="0">
>         <xs:element ref="b"/>
>         <xs:element ref="c"/>
>       </xs:all>
>     </xs:complexType>
>   </xs:element>
>
> Is there an easy way to do what I want using <xs:all>?  I know how  
> to do it otherwise, but <xs:all> seems much more elegant.

There is not a way to express this with xsd:all, that I know of.
In XSD 1.1, of course, you can add an assertion to the
declaration to take care of it:

   <xs:assert test="./b or ./c"/>

or

   <xs:assert test="child::*"/>

In both XSD 1.0 and 1.1, of course, the constraint can be
expressed with a content model; I suspect this is what you
have in mind as the less elegant way of defining it:

   <xs:choice>
     <xs:sequence>
       <xs:element ref="a"/><xs:element ref="b" minOccurs="0"/>
     </xs:sequence>
     <xs:sequence>
       <xs:element ref="b"/><xs:element ref="a" minOccurs="0"/>
     </xs:sequence>
   </xs:choice>

I hope this helps.

-- 
****************************************************************
* C. M. Sperberg-McQueen, Black Mesa Technologies LLC
* http://www.blackmesatech.com
* http://cmsmcq.com/mib
* http://balisage.net
****************************************************************
Received on Friday, 12 February 2010 22:57:31 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 23:15:55 UTC