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 "Asleson, Ryan" <as...@BIWORLDWIDE.com> on 2004/08/23 14:20:46 UTC

XML Schema

Hello,

My apologies if this isn't the correct place to ask this question, but I
didn't know where else to go.  

Suppose I have a simple XML document that looks like this:

<?xml version="1.0"?>
<family>
	<father>Jack</father>
	<mother>Jill</mother>
	<son>Billy</son>
	<son>Joey</son>
	<daughter>Jane</daughter>
	<pet>Fido</pet>
</family>


The above XML is successfully validated by the schema shown below:


<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

    <xs:element name="father" type="xs:string"/>
    <xs:element name="mother" type="xs:string"/>
    <xs:element name="son" type="xs:string"/>
    <xs:element name="daughter" type="xs:string"/>
    <xs:element name="pet" type="xs:string"/>
    
    <xs:element name="family">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="father" minOccurs="0"/>
                <xs:element ref="mother" minOccurs="0"/>
                <xs:element ref="son" minOccurs="0" maxOccurs="unbounded"/>
                <xs:element ref="daughter" minOccurs="0"
maxOccurs="unbounded"/>
                <xs:element ref="pet" minOccurs="0" maxOccurs="unbounded"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>    


However, if the XML document is changed so that the "pet" element occurs
before the "daughter" element, a validation error is thrown.  The error
states that all instances of "pet" must occur after any instances of
"daughter."

This is the problem.  I don't want the order of child elements within the
"family" element to matter, or be validated.  I don't care what order the
father, mother, son, daughter, and pet tags are in, nor do I want to
validate the order.

How can I specify this in the XML schema?  According to the documentation
I've seen, the complexType tag must use an occurrence indicator of all,
choice, or sequence.  All might work, since order doesn't matter, but
apparently it specifies that each child element can occur once and only once
once, which doesn't work.  Choice doesn't work because only one of the
elements can appear.  Sequence might work because it allows me to specify
multiple occurrences of child elements, but it enforces the order of the
child elements, which I don't want.

How can I specify this complex type in the XML schema?  I'm sure it can be
done, I'm just not sure how.

Thank you very much!!



This e-mail message is being sent solely for use by the intended recipient(s) and may contain confidential information.  Any unauthorized review, use, disclosure or distribution is prohibited.  If you are not the intended recipient, please contact the sender by phone or reply by e-mail, delete the original message and destroy all copies. Thank you.

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


Re: XML Schema

Posted by Mik Lernout <mi...@futurestreet.org>.
Hey,

The mailing list your question should be directed to is the 
xmlschema-dev mailing list at www.w3.org.
The fact that the order is validated has to do with the sequence you 
have defined in your schema, if you change 'sequence' to 'all' you will 
achieve what you want.
I should add though that there is a real tendency for schema's to use 
fixed-order as much as possible: it eases development against the schema 
and allows highly optimized validation techiniques...

Hope that helps,

Mik


Asleson, Ryan wrote:

>Hello,
>
>My apologies if this isn't the correct place to ask this question, but I
>didn't know where else to go.  
>
>Suppose I have a simple XML document that looks like this:
>
><?xml version="1.0"?>
><family>
>	<father>Jack</father>
>	<mother>Jill</mother>
>	<son>Billy</son>
>	<son>Joey</son>
>	<daughter>Jane</daughter>
>	<pet>Fido</pet>
></family>
>
>
>The above XML is successfully validated by the schema shown below:
>
>
><?xml version="1.0"?>
><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
>
>    <xs:element name="father" type="xs:string"/>
>    <xs:element name="mother" type="xs:string"/>
>    <xs:element name="son" type="xs:string"/>
>    <xs:element name="daughter" type="xs:string"/>
>    <xs:element name="pet" type="xs:string"/>
>    
>    <xs:element name="family">
>        <xs:complexType>
>            <xs:sequence>
>                <xs:element ref="father" minOccurs="0"/>
>                <xs:element ref="mother" minOccurs="0"/>
>                <xs:element ref="son" minOccurs="0" maxOccurs="unbounded"/>
>                <xs:element ref="daughter" minOccurs="0"
>maxOccurs="unbounded"/>
>                <xs:element ref="pet" minOccurs="0" maxOccurs="unbounded"/>
>            </xs:sequence>
>        </xs:complexType>
>    </xs:element>
></xs:schema>    
>
>
>However, if the XML document is changed so that the "pet" element occurs
>before the "daughter" element, a validation error is thrown.  The error
>states that all instances of "pet" must occur after any instances of
>"daughter."
>
>This is the problem.  I don't want the order of child elements within the
>"family" element to matter, or be validated.  I don't care what order the
>father, mother, son, daughter, and pet tags are in, nor do I want to
>validate the order.
>
>How can I specify this in the XML schema?  According to the documentation
>I've seen, the complexType tag must use an occurrence indicator of all,
>choice, or sequence.  All might work, since order doesn't matter, but
>apparently it specifies that each child element can occur once and only once
>once, which doesn't work.  Choice doesn't work because only one of the
>elements can appear.  Sequence might work because it allows me to specify
>multiple occurrences of child elements, but it enforces the order of the
>child elements, which I don't want.
>
>How can I specify this complex type in the XML schema?  I'm sure it can be
>done, I'm just not sure how.
>
>Thank you very much!!
>
>
>
>This e-mail message is being sent solely for use by the intended recipient(s) and may contain confidential information.  Any unauthorized review, use, disclosure or distribution is prohibited.  If you are not the intended recipient, please contact the sender by phone or reply by e-mail, delete the original message and destroy all copies. Thank you.
>
>---------------------------------------------------------------------
>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: XML Schema

Posted by Ankit Pasricha <an...@ca.ibm.com>.



Another thing u can try is the following:


<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

    <xs:element name="father" type="xs:string"/>
    <xs:element name="mother" type="xs:string"/>
    <xs:element name="son" type="xs:string"/>
    <xs:element name="daughter" type="xs:string"/>
    <xs:element name="pet" type="xs:string"/>

    <xs:element name="family">
        <xs:complexType>
            <xs:sequence>
                  <xs:choice minOccurs="0" maxOccurs="unbounded"/>
                        <xs:element ref="father"/>
                        <xs:element ref="mother"/>
                        <xs:element ref="son"/>
                        <xs:element ref="daughter"/>
                        <xs:element ref="pet"/>
                  </xs:choice>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>

That will allow multiple sets of parents but allows any order.


Ankit Pasricha
XML Parser Development
IBM Toronto Lab
8200 Warden Avenue, Ontario L6G 1C7
Phone: (905) 413 4941


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