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 Denis McCarthy <dm...@fexco.ie> on 2003/01/22 18:30:45 UTC

Choosing between 2 choices in an xml schema

Hi there,
I'm parsing a document using dom, and I want to enforce certain rules using
a schema.
Say there are 4 xml tags that I want to set rules for, <A>, <B>, <C>, <D>
and <E>.
I want to set up a rule where a combination of (say) <A>,<B> and <D>
appearing in a message are valid, and also
(say) <A>, <C> and <E>, but no other combination is valid. I would have
thought that something like
<xsd:choice>
<xsd:all>
<xsd:element name=<A>
<xsd:element name=<B>
<xsd:element name=<D>
</xsd:all>
<xsd:all>
<xsd:element name=<A>
<xsd:element name=<C>
<xsd:element name=<E>
</xsd:all>
</xsd:choice>
would be the way to do it, but apparently this is an error (I get the
following when I parse my Document)

Error:  choice content must be zero or more of element, group, choice,
sequence or any.  Saw "{1}".

Does anyone know of a way I can enforce this type of rule? Thanks
Denis McCarthy


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
your system administrator.

This footnote also confirms that this email message has been checked for 
the presence of computer viruses.

www.fexco.com
**********************************************************************


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


Re: Choosing between 2 choices in an xml schema

Posted by khalm <kr...@imk.fhg.de>.
Hi Dennis


Your Schema isn't valid because the all group can only appear as "top 
level" group  and in your Schema the all group is part of the choice 
group (and of course your example Schema isn't well formed :) ).

A (hopefully) valid Schema would look like this:
........
<xsd:complexType name="blub">
  <xsd:sequence>
    <xsd:element name="A" type="xsd:string"/>
    <xsd:choice>
       <xsd:sequence>
        <xsd:element name="B" type="xsd:string"/>
        <xsd:element name="D" type="xsd:string"/>
       </xsd:sequence>
       <xsd:sequence>
         <xsd:element name="C" type="xsd:string"/>
         <xsd:element name="E" type="xsd:string"/>
      </xsd:sequence>
    </xsd:choice>
 </xsd:sequence>
</xsd:complexType>
......

by adding minOccurs="0" to the element declaration you can make the 
elements optional. The only restriction you have, is the fixed order of 
element appearances: first element A then B then D (or A C E). As far as 
I know there is no possibility to implement an arbitrary order in this case.

Cheers
Kristian

Denis McCarthy wrote:

>Hi there,
>I'm parsing a document using dom, and I want to enforce certain rules using
>a schema.
>Say there are 4 xml tags that I want to set rules for, <A>, <B>, <C>, <D>
>and <E>.
>I want to set up a rule where a combination of (say) <A>,<B> and <D>
>appearing in a message are valid, and also
>(say) <A>, <C> and <E>, but no other combination is valid. I would have
>thought that something like
><xsd:choice>
><xsd:all>
><xsd:element name=<A>
><xsd:element name=<B>
><xsd:element name=<D>
></xsd:all>
><xsd:all>
><xsd:element name=<A>
><xsd:element name=<C>
><xsd:element name=<E>
></xsd:all>
></xsd:choice>
>would be the way to do it, but apparently this is an error (I get the
>following when I parse my Document)
>
>Error:  choice content must be zero or more of element, group, choice,
>sequence or any.  Saw "{1}".
>
>Does anyone know of a way I can enforce this type of rule? Thanks
>Denis McCarthy
>
>
>**********************************************************************
>This email and any files transmitted with it are confidential and
>intended solely for the use of the individual or entity to whom they
>are addressed. If you have received this email in error please notify
>your system administrator.
>
>This footnote also confirms that this email message has been checked for 
>the presence of computer viruses.
>
>www.fexco.com
>**********************************************************************
>
>
>---------------------------------------------------------------------
>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