针对XSD的XML验证:元素必须没有字符或元素信息项

时间:2014-01-04 21:17:29

标签: xml validation xsd

为什么我的XML不能对以下XSD进行验证?

我的XML文件就是这个:

<?xml version="1.0" encoding="ISO-8859-1"?>
<!--DOCTYPE jocuri SYSTEM "JocuriIrimiaRaduSilviu.dtd"--> 
<!-- se decomenteaza linia de mai sus doar pentru validarea DTD-ului-->
<jocuri>
        <joc>
        <numeJoc>FIFA14</numeJoc>
        <developerJoc>EA SPORTS</developerJoc>
        <publisherJoc>EA</publisherJoc>
        <siteOficialJoc>www.easports.com</siteOficialJoc>
        <genJoc gen="MISC">SPORTS</genJoc>
        <anAparitieJoc>2013</anAparitieJoc>
        <ratingPEGI rating="3">3</ratingPEGI>
        <scorMetacritic>90</scorMetacritic>
        <pretJoc>60</pretJoc>
        <varianta platforma="NONE">XONE</varianta>
        <numarBucati>3</numarBucati>
    </joc>
    <joc>
        <numeJoc>FIFA14</numeJoc>
        <developerJoc>EA SPORTS</developerJoc>
        <publisherJoc>EA</publisherJoc>
        <siteOficialJoc>www.easports.com</siteOficialJoc>
        <genJoc gen="MISC">SPORTS</genJoc>
        <anAparitieJoc>2013</anAparitieJoc>
        <ratingPEGI rating="3">3</ratingPEGI>
        <scorMetacritic>90</scorMetacritic>
        <pretJoc>60</pretJoc>
        <varianta platforma="NONE">PS4</varianta>
        <numarBucati>3</numarBucati>
    </joc>
</jocuri>

我正在使用以下XSD:

<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="jocuri">
    <xs:annotation>
      <xs:documentation>DOCTYPE jocuri SYSTEM "JocuriIrimiaRaduSilviu.dtd" se decomenteaza linia de mai sus doar pentru validarea DTD-ului</xs:documentation>
    </xs:annotation>
    <xs:complexType>
      <xs:sequence>
        <xs:element name="joc" maxOccurs="unbounded" minOccurs="0">
          <xs:complexType>
            <xs:sequence>
              <xs:element type="xs:string" name="numeJoc"/>
              <xs:element type="xs:string" name="developerJoc"/>
              <xs:element type="xs:string" name="publisherJoc"/>
              <xs:element type="xs:anyURI" name="siteOficialJoc"/>
              <xs:element name="genJoc">
                <xs:complexType>
                    <xs:attribute name="gen" use="required">
                                <xs:simpleType>
                                    <xs:restriction base="xs:string">
                                        <xs:enumeration value="MISC"/>
                                        <xs:enumeration value="FPS"/>
                                        <xs:enumeration value="TPS"/>
                                        <xs:enumeration value="ACTION"/>
                                        <xs:enumeration value="RPG"/>
                                        <xs:enumeration value="MMORPG"/>
                                        <xs:enumeration value="RTS"/>
                                        <xs:enumeration value="RACING"/>
                                        <xs:enumeration value="SIMULATOR"/>
                                        <xs:enumeration value="SPORTS"/>
                                    </xs:restriction>
                                </xs:simpleType>
                        </xs:attribute>
                 </xs:complexType>
              </xs:element>
              <xs:element type="xs:short" name="anAparitieJoc"/>
              <xs:element name="ratingPEGI">
                <xs:complexType mixed="true">
                            <xs:attribute name="rating" use="required">
                                <xs:simpleType>
                                    <xs:restriction base="xs:positiveInteger">
                                        <xs:enumeration value="3"/>
                                        <xs:enumeration value="6"/>
                                        <xs:enumeration value="12"/>
                                        <xs:enumeration value="15"/>
                                        <xs:enumeration value="17"/>
                                        <xs:enumeration value="18"/>
                                    </xs:restriction>
                                </xs:simpleType>
                            </xs:attribute>
                        </xs:complexType>
              </xs:element>
              <xs:element type="xs:byte" name="scorMetacritic"/>
              <xs:element type="xs:byte" name="pretJoc"/>
              <xs:element name="varianta">
                <xs:complexType mixed="true">
                            <xs:attribute name="platforma" use="required">
                                <xs:simpleType>
                                    <xs:restriction base="xs:string">
                                        <xs:enumeration value="NONE"/>
                                        <xs:enumeration value="PS3"/>
                                        <xs:enumeration value="X360"/>
                                        <xs:enumeration value="PS4"/>
                                        <xs:enumeration value="XONE"/>
                                        <xs:enumeration value="PC"/>
                                        <xs:enumeration value="WII"/>
                                        <xs:enumeration value="WIIU"/>
                                    </xs:restriction>
                                </xs:simpleType>
                            </xs:attribute>
                        </xs:complexType>
              </xs:element>
              <xs:element type="xs:byte" name="numarBucati"/>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

由于某种原因,我无法针对XSD验证XML。他们都在我正在使用的网站上自行验证。

我正在使用http://www.utilities-online.info/xsdvalidation/#.Ushm77Sn4gB

1 个答案:

答案 0 :(得分:2)

尝试更改此内容,

  <xs:element name="genJoc">
    <xs:complexType>
        <xs:attribute name="gen" use="required">

这个

  <xs:element name="genJoc">
    <xs:complexType mixed="true">
        <xs:attribute name="gen" use="required">
在您的XSD中