tags:

views:

35

answers:

1
+1  Q: 

XSD any element

HI! 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"&gt;

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

Ofer

A: 

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.

xcut
Thankx, but I didn't understand how to implement your idea.Can you explain more about your idea?
ofer shwartz
I saw you already answered someone about this topic, in this page : http://stackoverflow.com/questions/2592205/creating-a-flexible-xml-schema/2592271#2592271I tried what you suggested and added those lines to the XML file:<include schemaLocation="schema.xsd"/><include schemaLocation="schema2.xsd"/>But it doesn't check the validation ov values yet. Do you have an idea why?
ofer shwartz
I understand my mistake. I should have put the include in the xsd file, not in the xml file.Now it's working fine.Thank you very much.
ofer shwartz