开发者

Nested sequence in XSD

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 ?


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜