XML模式验证问题s4s-elt-invalid-content.1

时间:2014-03-21 00:18:26

标签: xml validation schema

我收到错误s4s-elt-invalid-content.1:'#AnonType_clienttourDatabase'的内容是无效的。元素'元素'无效,错位或过于频繁发生。

来自以下; 架构文件:

 <?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="tourDatabase">
        <xs:complexType>
            <xs:sequence>
                <xs:element maxOccurs="unbounded" name="client">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element name="name" type="xs:string"/>
                            <xs:element name="address" type="xs:string"/>
                            <xs:element name="county" type="xs:string"/>
                            <xs:element name="postcode" type="xs:string"/>
                            <xs:element name="dob" type="xs:date"/>
                        </xs:sequence>  
                                <xs:complexType>
                                    <xs:sequence>
                                        <xs:element maxOccurs="unbounded" name="clienttour">
                                            <xs:complexType>
                                                <xs:sequence>
                                                    <xs:element maxOccurs="unbounded" name="tourid" type="xs:integer"/>
                                                    <xs:element maxOccurs="unbounded" name="paid" type="xs:integer"/>
                                                </xs:sequence>
                                                    <xs:attribute name="ctourid" type="xs:integer" use="required"/>
                                            </xs:complexType>
                                        </xs:element>
                                    </xs:sequence>
                                </xs:complexType>
                        </xs:sequence>
                            <xs:attribute name="id" type="xs:integer" use="required"/>
                    </xs:complexType>
                </xs:element>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>

XML文件:

    <?xml version="1.0" encoding="UTF-8"?>
<!-- Set of clients Table -->
<tourDatabase
        xmlns:xs="http://www.w3.org/2001/XMLSchema"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <client id="1">
            <name>Fulton</name>
            <address>Turpis Road</address>
            <county>Stirlingshire</county>
            <postcode>FK8 5RD</postcode>
            <dob>1941-01-16</dob>
            <clientTour ctourid="1">
              <tourid>1</tourid>
              <paid>1</paid>
            </clientTour>
        </client>
        <client id="2">
            <name>Zachery</name>
            <address>Egestas Rd</address>
            <county>Herefordshire</county>
            <postcode>MM85 8DF</postcode>
            <dob>1993-02-13</dob>
            <clientTour ctourid="2">
              <tourid>1</tourid>
              <paid>1</paid>
            </clientTour>
        </client>
            <client id="3">
            <name>Lawrence</name>
            <address>Barrywhale close</address>
            <county>Anor Londo</county>
            <postcode>A0 2PX</postcode>
            <dob>1950-09-24</dob>
            <clientTour ctourid="3">
              <tourid>1</tourid>
              <paid>0</paid>
            </clientTour>
        </client>
        <client id="4">
            <name>Bert</name>
            <address>Old Long Johnston Road</address>
            <county>Blighttown</county>
            <postcode>B3L 4AS</postcode>
            <dob>1993-12-12</dob>
            <clientTour ctourid="4">
              <tourid>1</tourid>
              <paid>0</paid>
            </clientTour>
        </client>
        <client id="5">
            <name>Ernie</name>
            <address>Stevenson Avenue</address>
            <county>Perthshire</county>
            <postcode>B3P 7AS</postcode>
            <dob>1993-12-12</dob>
            <clientTour ctourid="5">
              <tourid>1</tourid>
              <paid>0</paid>
            </clientTour>
        </client>
        <client id="6">
            <name>Bertha</name>
            <address>Firelink crescent</address>
            <county>Stenns Fortress</county>
            <postcode>A8L 9AT</postcode>
            <dob>1973-01-21</dob>
            <clientTour ctourid="6">
              <tourid>1</tourid>
              <paid>1</paid>
            </clientTour>
        </client>
        <client id="7">
            <name>Oliver</name>
            <address>Old River</address>
            <county>Majula</county>
            <postcode>A3T 4PZ</postcode>
            <dob>1963-02-02</dob>
            <clientTour ctourid="7">
              <tourid>1</tourid>
              <paid>1</paid>
            </clientTour>
        </client>
        <client id="8">
            <name>Emerald Herald</name>
            <address>Old Long Johnston Road</address>
            <county>Blighttown</county>
            <postcode>B3L 4AS</postcode>
            <dob>1943-10-10</dob>
            <clientTour ctourid="8">
              <tourid>1</tourid>
              <paid>0</paid>
            </clientTour>
        </client>
</tourDatabase>

1 个答案:

答案 0 :(得分:0)

您的XML架构文件无效。您在complexType内无complexTypeclientTourclient的孩子,就像nameaddress等,因此它是sequence的一部分。还有一些其他问题。我根据你的实例修复了它:

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="tourDatabase">
        <xs:complexType>
            <xs:sequence>
                <xs:element maxOccurs="unbounded" name="client">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element name="name" type="xs:string"/>
                            <xs:element name="address" type="xs:string"/>
                            <xs:element name="county" type="xs:string"/>
                            <xs:element name="postcode" type="xs:string"/>
                            <xs:element name="dob" type="xs:date"/>
                            <xs:element maxOccurs="unbounded" name="clientTour">
                                <xs:complexType>
                                    <xs:sequence>
                                        <xs:element maxOccurs="unbounded" name="tourid" type="xs:integer"/>
                                        <xs:element maxOccurs="unbounded" name="paid" type="xs:integer"/>
                                    </xs:sequence>
                                    <xs:attribute name="ctourid" type="xs:integer" use="required"/>
                                </xs:complexType>
                            </xs:element>
                        </xs:sequence>  
                        <xs:attribute name="id" type="xs:integer" use="required"/>
                    </xs:complexType>
                </xs:element>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>