W3C home > Mailing lists > Public > xmlschema-dev@w3.org > January 2009

Re: Ignore Order while validating XSD

From: Eduardo Oliveira <eduardo.oliveirared@gmail.com>
Date: Mon, 26 Jan 2009 09:55:06 -0200
Message-ID: <f7c898bc0901260355g2a73ab1fpbc8a443354ea5b7c@mail.gmail.com>
To: "C. M. Sperberg-McQueen" <cmsmcq@acm.org>
Cc: xmlschema-dev@w3.org
Hello Mr. Sperberg-McQueen!

Thatīs ok! Your solution run as I expected it to run!

I just took the freedom to make a little change to reduce the code size,
setting the element "a"īs maxOccurs="unbounded", eliminating the second
block  as below!

Thanks a lot!

Eduardo

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
  <xs:element name="root">
    <xs:complexType >
      <xs:sequence>
        <xs:choice minOccurs="0" maxOccurs="unbounded">
          <xs:element name="b"/>
          <xs:element name="c"/>
          <xs:element name="x"/>
        </xs:choice>
        <xs:element name="a" maxOccurs="unbounded"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

2009/1/25 C. M. Sperberg-McQueen <cmsmcq@acm.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 18:32:08 UTC

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