1

I would like to validate this XML:

<meta>
    <house>
        <big ... />
        <little ... />
        <big ... />
    </house>

    <flat>
        <red ... />
        <red ... />
        <yellow ... />
    </flat>
</meta>

I wrote that.

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="meta">
        <xs:complexType>
            <xs:sequence minOccurs="0" maxOccurs="unbounded">
                <xs:element name="house">
                    <xs:complexType>
                        <xs:sequence minOccurs="0" maxOccurs="unbounded">
                            <xs:element name='big' />
                            <xs:element name='little' />
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
                <xs:element name="flat">
                    <xs:complexType>
                        <xs:sequence minOccurs="0" maxOccurs="unbounded">
                            <xs:element name='red'/>
                            <xs:element name='yellow'/>
                        </xs:sequence>
                     </xs:complexType>
                 </xs:element>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>

But that does not validate my example. Without 'house' or 'flat', and only meta, that worked.

Where could be my problem ?

2
  • Where are you trying to validate the XSD? W3C? Commented Sep 27, 2011 at 13:25
  • @FloppyDisk: With the lxml lib from python. Commented Sep 27, 2011 at 13:47

1 Answer 1

0

Found !

The solution: add a "xs:choice" for each "xs:sequence", like this:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="meta">
        <xs:complexType>
            <xs:sequence minOccurs="0" maxOccurs="unbounded">
               <xs:choice>
                <xs:element name="house">
                    <xs:complexType>
                        <xs:sequence minOccurs="0" maxOccurs="unbounded">
                            <xs:choice>
                                <xs:element name='big' />
                                <xs:element name='little' />
                            </xs:choice>
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
                <xs:element name="flat">
                    <xs:complexType>
                        <xs:sequence minOccurs="0" maxOccurs="unbounded">
                            <xs:choice>
                                <xs:element name='red'/>
                                <xs:element name='yellow'/>
                            </xs:choice>
                        </xs:sequence>
                     </xs:complexType>
                 </xs:element>
               </xs:choice>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.