【问题标题】:error on validation of xsd to #AnonType将 xsd 验证为 #AnonType 时出错
【发布时间】:2014-04-10 02:58:04
【问题描述】:

我是 XML 和 XSD 的新手,我一直在尝试将此 xsd 代码验证为 xml 文件,但没有任何成功。我在下面收到一个错误,我看不出有什么问题。任何帮助将不胜感激。

s4s-elt-invalid-content.1:内容 '#AnonType_endangered_species' 无效。元素“元素”是 无效、放错位置或过于频繁。

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<xsd:element name="endangered_species">
  <xsd:complexType>

<xsd:element name="animal" type="xsd:string" minOccurs="1" maxOccurs="unbounded">
<xsd:complexType>
    <xsd:sequence>
<xsd:element name="name" minOccurs="2" maxOccurs="2" type="xs:string">
    <xsd:complexType>
        <xsd:all>
        </xsd:all>
             <xsd:attribute ref="language"> 
            <xsd:simpleType>
               <xsd:restriction base="xsd:string">
                  <xsd:enumeration value="English"/>
                  <xsd:enumeration value="Latin"/>
               </xsd:restriction>
            </xsd:simpleType>
             </xsd:attribute>
    </xsd:complexType>
</xsd:element>

    </xsd:sequence>
</xsd:complexType>
</xsd:element>  

</xsd:complexType>
</xsd:element>

</xsd:schema>

【问题讨论】:

    标签: xml xsd


    【解决方案1】:

    您的xsd:element 标签放错了位置。您不能将 xsd:element 作为 xsd:contentType 的子级。

    您可能希望将它放在一个组中,例如序列

    <xsd:complexType>
        <xsd:sequence>
             <xsd:element ...>
        ...
    ...
    

    您在该 XSD 中还有其他问题。您必须选择是嵌套complexType 元素还是要声明一个简单类型。您可以修复它,从嵌套的 xs:element 元素中删除 type="xsd:string" 属性。

    最后,您要么引用一个属性(XSD 中不存在该属性),要么命名它。由于您有一个嵌套类型,您可能不想引用它。所以把&lt;xsd:attribute ref="language"&gt;改成&lt;xsd:attribute name="language"&gt;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-05-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-30
      • 2014-05-29
      • 1970-01-01
      相关资源
      最近更新 更多