How to ignore the validation of Unknown tags?
In case your not already done with this, you might try the following:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="root" type="root"></xs:element>
<xs:complexType name="root">
<xs:sequence>
<xs:any maxOccurs="2" minOccurs="0" processContents="skip"/>
<xs:element name="node" type="xs:string"/>
<xs:any maxOccurs="2" minOccurs="0" processContents="skip"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
Under Linux this works fine with xmllint using libxml version 20706.
You could make use of a new feature in XML 1.1 called "Open Content". In short, it allows you to specify that additional "unknown" elements can be added to a complex type in various positions, and what the parser should do if it hit any of those elements.
Using XML 1.1, your complex type would become:
<xs:element name="root" type="root" />
<xs:complexType name="root">
<xs:openContent mode="interleave">
<xs:any namespace="##any" processContents="skip"/>
</xs:openContent>
<xs:sequence>
<xs:element name="node" type="xs:string"/>
</xs:sequence>
</xs:complexType>
If you have a lot of complex types, you can also set a "default" open content mode at the top of your schema:
<xs:schema ...>
<xs:defaultOpenContent mode="interleave">
<xs:any namespace="##any" processContents="skip"/>
</xs:defaultOpenContent>
...
</xs:schema>
The W3C spec for Open Content can be found at http://www.w3.org/TR/xmlschema11-1/#oc, and there's a good writeup of this at http://www.ibm.com/developerworks/library/x-xml11pt3/#N102BA.
Unfortunately, .NET doesn't support XML 1.1 as of yet I can't find any free XML 1.1 processors - but a couple of paid-for options are:
- http://www.saxonica.com/
- http://www.altova.com/raptorxml.html
Conclusion:
This is not possible with XSD. All the approaches I was trying to achieve the requirement were named as "ambiguous" by validation-tools, accompanying bunch of errors.