模式有效性错误:元素'游戏':没有可用于验证根的匹配全局声明

时间:2012-04-22 20:49:31

标签: xml xsd

我已经检查了相关的问题,我一直在寻找解决这个问题,但我想我不会找到补救措施。这是我的xml文件的代码

<?xml version="1.0" encoding="UTF-8"?>



<game xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:noNamespaceSchemaLocation="game.xsd">
<info>
    <name>"Mensch, aergere dich nicht!"</name>
    <description>"Mensch ärgere dich nicht ist ein Gesellschaftsspiel für zwei bis sechs Personen."
                <i>"Das Spielbrett ist in der Einzelausgabe doppelseitig bedruckt" 
                    <b> "sodass Mensch ärgere dich nicht für maximal sechs Spieler"</b>
                </i>
                <b>"auf der einen und maximal vier Spieler auf der anderen Seite spielbar ist."
                </b>    
     </description>
    <started>2012-09-24-06:00</started>
    <players number="2">
        <screenname player="1">"Onat Derebek"</screenname>
        <screenname player="2">"Kutay Derebek"</screenname>
    </players>
    <rounds>1</rounds>
    <winner player="1"></winner>
</info>
<moves> 
<!-- Erste figuren -->
    <roll player="1">6</roll>
    <piece player="1" nr="1" field="26"/>

    <roll player="2">6</roll>
    <piece player="2" nr="5" field="36"/>

    <roll player="1">6</roll>
    <piece player="1" nr="1" field="32"/>


</moves>

这是我的xsd文件的代码

<element name="game">
    <complexType>
        <sequence>
            <element name="info" type="tns:infoType" maxOccurs="1" minOccurs="1"></element>
            <element name="moves" type="tns:movesType" maxOccurs="1" minOccurs="1"></element>
        </sequence>
    </complexType>
</element>


<complexType name="infoType">
    <sequence>
        <element name="name" type="string" maxOccurs="1"
            minOccurs="0">
        </element>
        <element name="description" type="tns:descriptionType"
            maxOccurs="1" minOccurs="0">
        </element>
        <element name="started" type="dateTime" maxOccurs="1"
            minOccurs="0">
        </element>
        <element name="players" minOccurs="0">
            <complexType>
                <sequence>
                    <element name="screenname" minOccurs="0" maxOccurs="4">
                        <complexType>
                            <simpleContent>
                                <extension base="string">
                                    <attribute name="player"
                                        type="tns:playerType" use="required">
                                    </attribute>
                                </extension>
                            </simpleContent>
                        </complexType>
                    </element>
                </sequence>

                <attribute name="number" type="tns:playerType" use="required"></attribute>
            </complexType>
        </element>
        <element name="rounds" type="int" minOccurs="0"></element>
        <element name="winner" minOccurs="0">
            <complexType>
                <attribute name="player" type="tns:playerType" use="required"></attribute>
            </complexType>
        </element>
    </sequence>
</complexType>

<complexType name="descriptionType" mixed="true">
    <choice maxOccurs="unbounded" minOccurs="1">
        <element name="i" type="tns:descriptionType"></element>
        <element name="b" type="tns:descriptionType"></element>
    </choice>
</complexType>


<complexType name="movesType">
    <choice minOccurs="0" maxOccurs="unbounded">
        <element name="roll" nillable="false">
            <complexType mixed="false">
                <simpleContent>
                    <extension base="tns:simpleIntType">
                        <attribute name="player" use="required">
                            <simpleType>
                                <restriction base="int">
                                    <minInclusive value="1"></minInclusive>
                                    <maxInclusive value="4"></maxInclusive>
                                </restriction>
                            </simpleType>
                        </attribute>
                    </extension>
                </simpleContent>
            </complexType>
        </element>
        <element name="piece">
            <complexType>
                <attribute name="nr" use="required">
                    <simpleType>
                        <restriction base="int">
                            <minInclusive value="1"></minInclusive>
                            <maxInclusive value="16"></maxInclusive>
                        </restriction>
                    </simpleType>
                </attribute>
                <attribute name="player" use="required">
                    <simpleType>
                        <restriction base="int">
                            <minInclusive value="1"></minInclusive>
                            <maxInclusive value="4"></maxInclusive>
                        </restriction>
                    </simpleType>
                </attribute>
                <attribute name="field" use="required">
                    <simpleType>
                        <restriction base="int">
                            <minInclusive value="1"></minInclusive>
                            <maxInclusive value="72"></maxInclusive>
                        </restriction>
                    </simpleType>
                </attribute>
            </complexType>
        </element>
    </choice>
</complexType>

<simpleType name="simpleIntType">
    <restriction base="int">
        <maxInclusive value="6"></maxInclusive>
        <minInclusive value="1"></minInclusive>
    </restriction>
</simpleType>


<simpleType name="playerType">
    <restriction base="int">
        <minInclusive value="1"></minInclusive>
        <maxInclusive value="4"></maxInclusive>
    </restriction>
</simpleType>

 我需要在一小时内解决这个问题因为我必须上传大学项目

2 个答案:

答案 0 :(得分:3)

我对在德国的童年假期玩“Menschärgeredichnicht”有着美好的回忆,事实上,我们带来了一个家庭住宅,有时还会出现在父母家中。它类似于英国的Ludo游戏,但规则中的细微差别意味着它的效果要好得多。

  

我需要在一小时内解决这个问题

然后希望您已经学到了有关时间管理的有用课程。

显然,根元素(游戏)有一个元素声明。您没有向我们展示架构文档的xs:schema元素,因此命名空间可能存在问题;但我认为更可能的解释是你错误地调用了模式验证器。

答案 1 :(得分:0)

我认为您的问题是在XSD中使用http://www.w3.org/2001/XMLSchema作为默认命名空间,因此所有类型都在该命名空间中定义,而您的XML文件不使用任何命名空间。

尝试将http://www.w3.org/2001/XMLSchema与前缀相关联(例如xmlns:xs =“http://www.w3.org/2001/XMLSchema”`)并定义没有目标命名空间的架构 - 它适用于我是这样的。

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

  <xs:element name="game">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="info" type="infoType" maxOccurs="1" minOccurs="1"></xs:element>
          <xs:element name="moves" type="movesType" maxOccurs="1" minOccurs="1"></xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>


  <xs:complexType name="infoType">
    <xs:sequence>
      <xs:element name="name" type="xs:string" maxOccurs="1"
          minOccurs="0">
      </xs:element>
      <xs:element name="description" type="descriptionType"
          maxOccurs="1" minOccurs="0">
      </xs:element>
      <xs:element name="started" type="xs:dateTime" maxOccurs="1"
          minOccurs="0">
      </xs:element>
      <xs:element name="players" minOccurs="0">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="screenname" minOccurs="0" maxOccurs="4">
              <xs:complexType>
                <xs:simpleContent>
                  <xs:extension base="xs:string">
                    <xs:attribute name="player"
                        type="playerType" use="required">
                    </xs:attribute>
                  </xs:extension>
                </xs:simpleContent>
              </xs:complexType>
            </xs:element>
          </xs:sequence>

          <xs:attribute name="number" type="playerType" use="required"></xs:attribute>
        </xs:complexType>
      </xs:element>
      <xs:element name="rounds" type="xs:int" minOccurs="0"></xs:element>
      <xs:element name="winner" minOccurs="0">
        <xs:complexType>
          <xs:attribute name="player" type="playerType" use="required"></xs:attribute>
        </xs:complexType>
      </xs:element>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="descriptionType" mixed="true">
    <xs:choice maxOccurs="unbounded" minOccurs="1">
      <xs:element name="i" type="descriptionType"></xs:element>
      <xs:element name="b" type="descriptionType"></xs:element>
    </xs:choice>
  </xs:complexType>


  <xs:complexType name="movesType">
    <xs:choice minOccurs="0" maxOccurs="unbounded">
      <xs:element name="roll" nillable="false">
        <xs:complexType mixed="false">
          <xs:simpleContent>
            <xs:extension base="simpleIntType">
              <xs:attribute name="player" use="required">
                <xs:simpleType>
                  <xs:restriction base="xs:int">
                    <xs:minInclusive value="1"></xs:minInclusive>
                      <xs:maxInclusive value="4"></xs:maxInclusive>
                  </xs:restriction>
                </xs:simpleType>
              </xs:attribute>
            </xs:extension>
          </xs:simpleContent>
        </xs:complexType>
      </xs:element>
      <xs:element name="piece">
        <xs:complexType>
          <xs:attribute name="nr" use="required">
            <xs:simpleType>
              <xs:restriction base="xs:int">
                <xs:minInclusive value="1"></xs:minInclusive>
                <xs:maxInclusive value="16"></xs:maxInclusive>
              </xs:restriction>
            </xs:simpleType>
          </xs:attribute>
          <xs:attribute name="player" use="required">
            <xs:simpleType>
              <xs:restriction base="xs:int">
                <xs:minInclusive value="1"></xs:minInclusive>
                  <xs:maxInclusive value="4"></xs:maxInclusive>
              </xs:restriction>
            </xs:simpleType>
          </xs:attribute>
          <xs:attribute name="field" use="required">
            <xs:simpleType>
              <xs:restriction base="xs:int">
                <xs:minInclusive value="1"></xs:minInclusive>
                  <xs:maxInclusive value="72"></xs:maxInclusive>
              </xs:restriction>
            </xs:simpleType>
          </xs:attribute>
        </xs:complexType>
      </xs:element>
    </xs:choice>
  </xs:complexType>

  <xs:simpleType name="simpleIntType">
    <xs:restriction base="xs:int">
      <xs:maxInclusive value="6"></xs:maxInclusive>
        <xs:minInclusive value="1"></xs:minInclusive>
    </xs:restriction>
  </xs:simpleType>


  <xs:simpleType name="playerType">
    <xs:restriction base="xs:int">
      <xs:minInclusive value="1"></xs:minInclusive>
        <xs:maxInclusive value="4"></xs:maxInclusive>
    </xs:restriction>
  </xs:simpleType>
</xs:schema>