2014-04-10 113 views
0

我是新來的XML和XSD,我一直在試圖驗證這個xsd代碼到一個xml文件,但沒有任何成功。我在下面看到一個錯誤,我看不出有什麼問題。任何幫助將不勝感激。錯誤驗證xsd到#AnonType

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> 

回答

2

xsd:element標籤是錯誤的。作爲xsd:contentType的子女,您不能有xsd:element

你可能想將它放在一個組內,如序列

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

您還可以在XSD其他問題。您必須選擇是否要嵌套complexType元素,或者您要聲明簡單類型。您可以修復它,從嵌套的xs:element元素中刪除type="xsd:string"屬性。

最後,您要麼引用一個屬性(不存在於您的XSD中),要麼命名它。既然你有一個嵌套類型,你可能不想引用它。因此請將<xsd:attribute ref="language">更改爲<xsd:attribute name="language">

+0

非常感謝!這解決了我的問題! – user3517759