1

你好我一直在寻找这个问题大约一个小时,我什至找不到这意味着什么。

这是我的 XML shema 代码:

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

        </xsd:element>
        </xsd:sequence>
    </xsd:complexType>
</xsd:element>
<xsd:complexType name="infoType">
    <xsd:sequence>
        <xsd:element name="name" minOccurs="0" maxOccurs="1" type="xsd:string"></xsd:element>
        <xsd:element name="description" minOccurs="0" maxOccurs="1" type="descriptionType">
        </xsd:element>
        <xsd:element name="started" type="xsd:dateTime"></xsd:element>
        <xsd:element name="players" minOccurs="0" maxOccurs="1">    
            <xsd:complexType>
                <xsd:sequence>
                    <xsd:element name="screenname" minOccurs="0" maxOccurs="4" type="xsd:string">
                        <xsd:complexType>
                            <xsd:attribute name="player"  use="required">   </xsd:attribute>
                        </xsd:complexType>
                    </xsd:element>
                </xsd:sequence>
                <xsd:attribute name="number" type="xsd:integer" use="required"></xsd:attribute> 
            </xsd:complexType>
        </xsd:element>
        <xsd:element name="rounds" minOccurs="0" maxOccurs="1" type="xsd:integer"></xsd:element>
        <xsd:element name="winner" minOccurs="0" maxOccurs="1">
            <xsd:complexType>
                <xsd:attribute name="player" type="playerType" use="required"></xsd:attribute>
            </xsd:complexType>
        </xsd:element>
    </xsd:sequence>
</xsd:complexType>
<xsd:complexType name="movesType">
    <xsd:choice maxOccurs="unbounded">
        <xsd:element name="roll" >
            <xsd:complexType>
                <xsd:simpleContent>
                    <xsd:restriction base="xsd:integer">
                        <xsd:minInclusive value="1"></xsd:minInclusive>
                        <xsd:maxInclusive value="6"></xsd:maxInclusive>
                    </xsd:restriction>
                </xsd:simpleContent>
                <xsd:attribute name="player" type="playerType"></xsd:attribute>
            </xsd:complexType>
        </xsd:element>
        <xsd:element name="piece">
            <xsd:complexType>
                <xsd:attribute name="player" type="playerType" use="required"></xsd:attribute>
                <xsd:attribute name="nr" type="xsd:integer" use="required">
                    <xsd:simpleType>
                        <xsd:restriction base="xsd:integer">
                            <xsd:minInclusive value="1"></xsd:minInclusive>
                            <xsd:maxInclusive value="16"></xsd:maxInclusive>
                        </xsd:restriction>
                    </xsd:simpleType>
                </xsd:attribute>
                <xsd:attribute name="field" type="xsd:integer" use="required">
                    <xsd:simpleType>
                        <xsd:restriction base="xsd:integer">
                            <xsd:minInclusive value="1"></xsd:minInclusive>
                            <xsd:maxInclusive value="72"></xsd:maxInclusive>
                        </xsd:restriction>
                    </xsd:simpleType>
                </xsd:attribute>
            </xsd:complexType>
        </xsd:element>
    </xsd:choice>
</xsd:complexType>
<xsd:simpleType name="playerType" >
    <xsd:restriction base="xsd:integer">
        <xsd:minInclusive value="1"></xsd:minInclusive>
        <xsd:maxInclusive value="4"></xsd:maxInclusive>
    </xsd:restriction>
</xsd:simpleType>
<xsd:complexType  name="descriptionType" mixed="true">
                <xsd:choice minOccurs="0" maxOccurs="unbounded">
                    <xsd:element name="i" type="descriptionType" ></xsd:element>
                    <xsd:element name="b" type="descriptionType"></xsd:element>
                </xsd:choice>
            </xsd:complexType>

这是我得到的解析器错误。

game.xsd:25: 
  element complexType: 
  Schemas parser error : 
  Element '{http://www.w3.org/2001/XMLSchema}element': 
  The attribute 'type' and the child are mutually exclusive. 
game.xsd:51: 
  element attribute: 
  Schemas parser error : 
  Element '{http://www.w3.org/2001/XMLSchema}complexType': 
  The content is not valid. Expected is (annotation?, (simpleContent | complexContent | ((group | all | choice | sequence)?, ((attribute | attributeGroup)*, anyAttribute?)))). 
game.xsd:58: 
  element simpleType: 
  Schemas parser error : 
  Element '{http://www.w3.org/2001/XMLSchema}attribute': 
  The attribute 'type' and the child are mutually exclusive. 
game.xsd:66: 
  element simpleType: 
  Schemas parser error : 
  Element '{http://www.w3.org/2001/XMLSchema}attribute': 
  The attribute 'type' and the child are mutually exclusive. WXS schema game.xsd failed to compile

这是一个大学项目,我必须在 6 小时内上交。我希望我能在这段时间内找到解决方案。

谢谢

4

1 回答 1

4

属性“类型”和子级是互斥的。

screenname( game.xsd:25) 的元素定义中,两者都将元素类型定义为xsd:string在属性中,并将其定义为complexType使用子元素。您可能正在寻找具有特定属性和字符串内容的类型?

<xsd:element name="screenname" minOccurs="0" maxOccurs="4">
  <xsd:complexType>
    <xsd:simpleContent>
      <xsd:extension base="xsd:string">
        <xsd:attribute name="player" use="required" type="xsd:string" />
      </xsd:extension>
    </xsd:simpleContent>
  </xsd:complexType>
</xsd:element>
于 2012-04-22T15:46:18.277 回答