You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Robert Dare <da...@netrox.net> on 2004/04/29 20:35:51 UTC

Issue with choice of group elements:

Hello,

I am getting a Schema Validation failure using Xerces 2.6.2
with JSDK 1.4.2.

My Schema is like this:

<xs:group name="Input1">
  <xs:sequence>
    <xs:element ref="dog" maxOccurs="1" minOccurs="1" />
    <xs:element ref="cat" maxOccurs="1" minOccurs="1" />
  </xs:sequence>
</xs:group>

<xs:group name="Input2">
  <xs:sequence>
    <xs:element ref="dog" maxOccurs="1" minOccurs="1" />
    <xs:element ref="cat" maxOccurs="1000" minOccurs="1" />
  </xs:sequence>
</xs:group>

<xs:group name="Input3">
  <xs:sequence>
    <xs:element ref="dog" maxOccurs="1000" minOccurs="1" />
    <xs:element ref="cat" maxOccurs="1" minOccurs="1" />
  </xs:sequence>
</xs:group>

<xs:element name="Animals">
  <xs:complextType>
    <xs:choice>
      <xs:group ref="Input1" />
      <xs:group ref="Input2" />
      <xs:group ref="Input3" />
    </xs:choice>
  </xs:complexType>
</xs:element>


I would expect from this schema that <animals> would be
allowed to have 1 cat and 1 dog.  If it has more than one
dog, there should be only 1 cat and vice-versa.

When I generate XML with 1 can and multiple DOGs, Xerces
gives me the following error:

Error on line 15: cvc-complex-type.2.4.d: Invalid content was found
starting with element 'DOG'. No child element is expected at this point.


If I move around the order of the groups in the choice block,
only the first instance gets used in the validation.

Is there a workaround for this?

Can anyone suggest an alternative way to write a schema that
would enforce this restriction?

Thanks!

Rob.



---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


Re: Issue with choice of group elements:

Posted by Robert Dare <da...@netrox.net>.
Thanks!!

This works fine when I have Cat, Dog, Dog, Dog,
but if I have Cat, Cat, Cat, Dog it fails.  I suppose
this is because when parsing, it would have to look
like Cat, Dog, Cat, Cat, Cat ...

I will keep working on this.

Thanks for your help!


>
> From: "Robert Dare" <da...@netrox.net>
>> I would expect from this schema that <animals> would be
>> allowed to have 1 cat and 1 dog.  If it has more than one
>> dog, there should be only 1 cat and vice-versa.
>>
>> When I generate XML with 1 can and multiple DOGs, Xerces
>> gives me the following error:
>>
>> Error on line 15: cvc-complex-type.2.4.d: Invalid content was found
>> starting with element 'DOG'. No child element is expected at this point.
>
> You always seem to have one dog and one cat,
> and perhaps more dogs or cats, but not both
>
> How about this schema idea (not tested)....
>
> <xs:element name="Animals">
>   <xs:complextType>
>     <xs:sequence>
>       <xs:element ref="dog" maxOccurs="1" minOccurs="1" />
>       <xs:element ref="cat" maxOccurs="1" minOccurs="1" />
>       <xs:choice>
>         <xs:group ref="Cats" />
>         <xs:group ref="Dogs" />
>      </xs:choice>
>     </xs:sequence>
>   </xs:complexType>
> </xs:element>
>
> <xs:group name="Cats">
>   <xs:sequence>
>     <xs:element ref="cat" maxOccurs="0" minOccurs="100" />
>   </xs:sequence>
> </xs:group>
>
> <xs:group name="Dogs">
>   <xs:sequence>
>     <xs:element ref="dog" maxOccurs="0" minOccurs="1000" />
>   </xs:sequence>
> </xs:group>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-user-help@xml.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


Re: Issue with choice of group elements:

Posted by Robert <rv...@xs4all.nl>.
From: "Robert Dare" <da...@netrox.net>
> I would expect from this schema that <animals> would be
> allowed to have 1 cat and 1 dog.  If it has more than one
> dog, there should be only 1 cat and vice-versa.
> 
> When I generate XML with 1 can and multiple DOGs, Xerces
> gives me the following error:
> 
> Error on line 15: cvc-complex-type.2.4.d: Invalid content was found
> starting with element 'DOG'. No child element is expected at this point.

You always seem to have one dog and one cat,
and perhaps more dogs or cats, but not both

How about this schema idea (not tested)....

<xs:element name="Animals">
  <xs:complextType>
    <xs:sequence>
      <xs:element ref="dog" maxOccurs="1" minOccurs="1" />
      <xs:element ref="cat" maxOccurs="1" minOccurs="1" />
      <xs:choice>
        <xs:group ref="Cats" />
        <xs:group ref="Dogs" />
     </xs:choice>
    </xs:sequence>
  </xs:complexType>
</xs:element>

<xs:group name="Cats">
  <xs:sequence>
    <xs:element ref="cat" maxOccurs="0" minOccurs="100" />
  </xs:sequence>
</xs:group>

<xs:group name="Dogs">
  <xs:sequence>
    <xs:element ref="dog" maxOccurs="0" minOccurs="1000" />
  </xs:sequence>
</xs:group>



---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org