1

我已经检查了相关问题,并且一直在寻找解决这个问题的方法,但我想我找不到补救措施。这是我的 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>

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

4

2 回答 2

3

我对在德国童年假期玩“Mensch ärgere dich nicht”有着美好的回忆,事实上,我们带了一套回家,有时在拜访父母家时仍然会出现。它类似于在英格兰被称为 Ludo 的游戏,但规则的细微差别意味着它的效果要好得多。

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

那么希望你已经学到了关于时间管理的有用课程。

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

于 2012-04-23T08:59:00.680 回答
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>
于 2012-04-23T12:22:33.420 回答