- From: C. M. Sperberg-McQueen <cmsmcq@acm.org>
- Date: Sun, 25 Jan 2009 17:37:55 -0700
- To: Eduardo Oliveira <eduardo.oliveirared@gmail.com>
- Cc: "C. M. Sperberg-McQueen" <cmsmcq@acm.org>, xmlschema-dev@w3.org
On 24 Jan 2009, at 12:51 , Eduardo Oliveira wrote:
> Thereīs much time since the last message, but I have a problem with
> the given solution.
> Since I use the model below, I canīt force the element to be
> declared, or in other words, the minOccurs does not run.
>
> The piece of code given from "George Cristian Bina":
>
> <xs:complexType>
> <xs:choice maxOccurs="unbounded">
> <xs:element name="a"/>
> <xs:element name="b"/>
> <xs:element name="c"/>
> <xs:element name="x"/>
> </xs:choice>
> </xs:complexType>
>
> Suppose I wish the <xs:element name="a"/> to always be received,
> so I change the code to the code below, but the minOccurs does not
> run.
>
> <xs:complexType>
> <xs:choice maxOccurs="unbounded">
> <xs:element name="a" minOccurs="1"/>
> <xs:element name="b"/>
> <xs:element name="c"/>
> <xs:element name="x"/>
> </xs:choice>
> </xs:complexType>
>
> Does anyone has an idea how can I solve this?
You want a sequence of one or more elements, which must contain at least
one 'a', and may contain any number of b, c, or x elements?
In a conventional regular expression, you might write
(b|c|x)*, a, (a|b|c|x)*
and you can do the same in XSD 1.0:
<xsd:complexType name="oliveira">
<xsd:sequence>
<xsd:choice minOccurs="0" maxOccurs="unbounded">
<xsd:element ref="my:b" />
<xsd:element ref="my:c" />
<xsd:element ref="my:x" />
</xsd:choice>
<xsd:element ref="my:a" />
<xsd:choice minOccurs="0" maxOccurs="unbounded">
<xsd:element ref="my:a" />
<xsd:element ref="my:b" />
<xsd:element ref="my:c" />
<xsd:element ref="my:x" />
</xsd:choice>
</xsd:sequence>
</xsd:complexType>
I hope this helps.
--
C. M. Sperberg-McQueen
http://cmsmcq.com/mib
Received on Monday, 26 January 2009 00:38:07 UTC