2010-04-07 68 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