- From: C. M. Sperberg-McQueen <cmsmcq@blackmesatech.com>
- Date: Fri, 12 Feb 2010 15:56:58 -0700
- To: "Hintz, David" <david.hintz@siemens.com>
- Cc: "C. M. Sperberg-McQueen" <cmsmcq@blackmesatech.com>, "xmlschema-dev@w3.org" <xmlschema-dev@w3.org>
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