2010-04-07 99 views
1

我想創建一個列表,其中一些元素是定義的,有些不是,沒有優先順序。 我嘗試了這種方式,與任何元素:XSD任何元素

<?xml version="1.0"?> 
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> 

<xs:complexType name="object" mixed="true"> 
    <xs:choice> 
    <xs:element name="value" minOccurs="1" maxOccurs="1"> 
    <xs:simpleType> 
    <xs:restriction base="xs:integer"> 
     <xs:enumeration value="1"/> 
    </xs:restriction> 
    </xs:simpleType> 
</xs:element>  
<xs:any namespace="##any" processContents="skip"/> 
    </xs:choice> 
</xs:complexType> 

<xs:element name="object" type="object"/> 

</xs:schema> 

,它告訴我這個錯誤:

:0:0: error: complex type 'object' violates the unique particle attribution rule in its components 'value' and '##any'

有人可以幫我解決這個問題?

回答

2

您不能像這樣定義您的模式,它違反了唯一的粒子歸因規則:分析器無法判斷它在文檔中找到的「value」元素是應該針對「value」還是針對「any」進行驗證。

這是good overview

考慮使用兩個命名空間並使用xsd:any命名空間,這將消除該問題。

+0

Thankx,但我不明白如何實現你的想法。 你能解釋一下你的想法嗎? – 2010-04-11 08:28:43

+0

我看到你已經在這個頁面回答了關於這個話題的人:http://stackoverflow.com/questions/2592205/creating-a-flexible-xml-schema/2592271#2592271 我試着你的建議,並添加了那些行到XML文件: 但它不會檢查驗證ov值。你知道爲什麼嗎? – 2010-04-11 09:19:26

+0

我明白我的錯誤。我應該把包含在xsd文件中,而不是在xml文件中。 現在它工作正常。 非常感謝。 – 2010-04-11 10:23:14