s4s-elt-must-match.1:xml架构中的错误

时间:2013-10-11 09:09:54

标签: xml xsd

我在尝试验证xml架构时遇到以下错误 -

16: 24  s4s-elt-must-match.1: The content of 'member' must match (annotation?, (simpleType | complexType)?, (unique | key | keyref)*)). A problem was found starting at: complextype.
31: 21  s4s-elt-must-match.1: The content of 'intake' must match (annotation?, (simpleType | complexType)?, (unique | key | keyref)*)). A problem was found starting at: complextype.

以下是架构 -

<?xml version="1.0"?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.w3schools.com"
xmlns="http://www.w3schools.com"
elementFormDefault="qualified">

<xs:element name="record">
    <xs:complexType>
        <xs:sequence>
            <xs:element name="id" minOccurs="1" maxOccurs="1">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element name="hof" type="xs:string" minOccurs="1" maxOccurs="1"/>
                        <xs:element name="member" minOccurs="1" maxOccurs="unbounded">
                            <xs:complextype>
                                <xs:all>
                                    <xs:element name="name" type="xs:string"/>
                                    <xs:element name="age" type="xs:nonNegativeInteger"/>
                                    <xs:element name="sex" type="xs:string"/>
                                    <xs:element name="occupation" type="xs:string" minOccurs="0"/>
                                    <xs:element name="pregnant" type="xs:boolean" minOccurs="0"/>
                                    <xs:element name="lactating" type="xs:boolean" minOccurs="0"/>
                                </xs:all>
                            </xs:complextype>
                        </xs:element>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
            <xs:element name="intake" minOccurs="1" maxOccurs="1">
                <xs:complextype>
                    <xs:sequence>
                        <xs:element name="food" minOccurs="0" maxOccurs="unbounded">
                            <xs:complextype>
                                <xs:sequence>
                                    <xs:element name="name" type="xs:string" minOccurs="1" maxOccurs="1"/>
                                    <xs:element name="amount" type="xs:decimal" minInclusive="0" minOccurs="1" maxOccurs="1"/>
                                </xs:sequence>
                            </xs:complextype>
                        </xs:element>
                    </xs:sequence>
                </xs:complextype>
            </xs:element>
        </xs:sequence>
    </xs:complexType>
</xs:element>

</xs:schema>

这是相应的XML文件 -

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<record xmlns="http://www.w3schools.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3schools.com record.xsd">
    <id>
        <hof>ABC</hof>
        <member>
            <name>ABC</name>
            <age>35</age>
            <sex>Male</sex>
            <occupation>Manual Laboror</occupation>
        </member>
        <member>
            <name>DEF</name>
            <age>30</age>
            <sex>Female</sex>
            <occupation>House Wife</occupation>
            <pregnant>no</pregnant>
            <lactating>no</lactating>
        </member>
        <member>
            <name>ghi</name>
            <age>2</age>
            <sex>Female</sex>
        </member>
    </id>
    <intake>
        <food>
            <name>rice</name>
            <amount>800</amount>
        </food>
        <food>
            <name>dal</name>
            <amount>200</amount>
        </food>
    </intake>
</record>

我已经尝试了here提供的解决方案,但无法让它发挥作用。

1 个答案:

答案 0 :(得分:0)

问题出在您的架构文档中。 XML区分大小写,因此所有出现的

<xs:complextype>

应该是

<xs:complexType>
用资本&#34; T&#34; (同样匹配的结束标签)。

相关问题