Вложена последователност в XSD

Бих искал да потвърдя този XML:

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

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

това го написах.

<?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>

Но това не потвърждава моя пример. Без „house“ или „flat“ и само мета, това работи.

Къде може да е проблемът ми?


person nicolas    schedule 27.09.2011    source източник
comment
Къде се опитвате да потвърдите XSD? W3C?   -  person FloppyDisk    schedule 27.09.2011
comment
@FloppyDisk: С lxml lib от python.   -  person nicolas    schedule 27.09.2011


Отговори (1)


Намерен !

Решението: добавете "xs:choice" за всяка "xs:sequence", като това:

<?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>
person nicolas    schedule 27.09.2011