Subject: Conforming to a schema
Posted By: Chamkaur Post Date: 1/7/2007 8:06:13 PM
Hi there,

Is it possible to a create a schema that allows an xml document to have repeating child nodes of a parent to be appearing in any order?  For example, the following is a sample of my xml document.

<parent>
  <child1>A</child1>
  <child1>B</child1>
  <child2>C</child2>
  <child1>D</child1>
  <child3>E</child3>
  <child3>F</child3>
  <child2>G</child2>
</parent>

With my current schema as shown, the xml document obviouslt doesnt conforms to the schema.  How can I change my schema document so that it will allow for any order and with the possiblity that the different child elements to be repeating?

<xs:element name="parent">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="child1" maxOccurs="unbounded"/>
                <xs:element ref="child2" maxOccurs="unbounded"/>
                <xs:element ref="child3" maxOccurs="unbounded"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>

thanks



Reply By: mhkay Reply Date: 1/8/2007 5:03:31 AM
Not exactly on-topic for an XSLT forum...

You can write

    <xs:element name="parent">
        <xs:complexType>
            <xs:choice maxOccurs="unbounded">
                <xs:element ref="child1" />
                <xs:element ref="child2" />
                <xs:element ref="child3" />
            </xs:choice>
        </xs:complexType>
    </xs:element>

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference

Go to topic 54519

Return to index page 71
Return to index page 70
Return to index page 69
Return to index page 68
Return to index page 67
Return to index page 66
Return to index page 65
Return to index page 64
Return to index page 63
Return to index page 62