XSD any element

≡放荡痞女 提交于 2020-01-05 03:58:10

问题


I'm trying to create a list that some of the elements are defined and some are not, without priority to order. I tried it this way, with an any element:

<?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> 

And it tells me this error:

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

Can someone help me out solve the problem?


回答1:


You cannot define your schema like that, it violates the unique particle attribution rule: the parser cannot tell whether a "value" element it finds in the document should be validated against "value" or against "any".

Here is a good overview.

Consider using two namespaces and using xsd:any with a namespace, this will remove the problem.



来源:https://stackoverflow.com/questions/2591757/xsd-any-element

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!