简体   繁体   中英

Why can I not validate an XML document against my XSD document?

XSD document:

<?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="esport">
  <xs:complexType>
  <xs:sequence>
    <xs:element name="dota">
        <xs:complexType>
        <xs:sequence>
            <xs:element name="team">
              <xs:complexType>
              <xs:sequence>
                <xs:attribute name="mmr" type="xs:integer">
                    <xs:restriction>
                        <xs:minInclusive value="3000"/>
                        <xs:maxInclusive value="7000"/>
                    </xs:restriction>
                </xs:attribute>
                <xs:element name="name" type="xs:string"/>
                <xs:element name="country" type="xs:string"/>
                <xs:element name="members">
                <xs:complexType>
                <xs:sequence>
                    <xs:attribute name="role" use="required">
                    <xs:restriction base="xs:string">
                            <xs:enumeration value="solomid"/>
                            <xs:enumeration value="support"/>
                            <xs:enumeration value="carry"/>
                            <xs:enumeration value="offlaner"/>
                    </xs:restriction>
                    </xs:attribute>
                    <xs:attribute name="kda_avg" use="required">
                    <xs:restriction base="xs:integer">
                        <xs:patern value="[0-999]/[0-999]/[0-999]"/>
                    </xs:restriction>
                    </xs:attribute>
                </xs:sequence>
                </xs:complexType>
                </xs:element>
            </xs:sequence>
            </xs:complexType>
            </xs:element>
        </xs:sequence>
        </xs:complexType>
    </xs:element>
    </xs:sequence>
  </xs:complexType>
</xs:element>
</xs:schema>

xml document:

<?xml version="1.0" encoding="utf-8"?>
<esport>
    <dota2>
        <team mmr="5660">
            <name> The Alliance</name>
            <country> Sweden </country>
            <members>
                <member role="solomid" kda_avg="12/5/4">s4</member>
                <member role="offlaner" kda_avg="9/6/5">Admiral</member>
                <member role="support" kda_avg="7/7/3">Akke</member>
                <member role="support" kda_avg="6/7/2">EGM</member>
                <member role="carry" kda_avg="15/6/5">Loda</member>
            </members>
        </team>
        <team>
            <name> Neolution Orange</name>
            <country> Malaysia </country>
            <members>
                <member role="carry" kda_avg="12/5/4">Mushi</member>
                <member role="support" kda_avg="9/6/5">Net</member>
                <member role="offlaner" kda_avg="7/7/3">ky.xy</member>
                <member role="support" kda_avg="6/7/2">XtincT</member>
                <member role="solomid" kda_avg="15/6/5">Ohaiyo</member>
            </members>
        </team>
    </dota2>
</esport>   

can you help me by providing solution to my problem:

Error 1: s4s-elt-must-match.1:
The content of 'sequence' must match (annotation?, (element | group | choice | sequence | any)*).
A problem was found starting at: attribute. Error 2:cvc-elt.1.a: Cannot find the declaration of element 'esport'.

The message is pretty clear: xs:attribute can't appear as a child of xs:sequence . I'm not sure how else one can say it. Your schema is invalid and needs to be fixed.

A very quick glance suggests another problem: the spelling xs:patern (sic) is wrong.

Also, as a matter of policy, you shouldn't use a namespace unless you own the domain. You don't own www.w3schools.com, so you shouldn't use that namespace.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM