[xsd-users] I want to ignore Unknown element
Boris Kolpackov
boris at codesynthesis.com
Mon Apr 27 04:43:34 EDT 2009
Hi,
Tore Martin Hagen <thagen at slb.com> writes:
> Is there a way I can tell the parser to just ignore all unknown tags as
> if they where not there?
>
> I have tried to add my own xml_schema::error_handler and returning true.
> When logging in my own error handler I see this
> id= line=9 column=34 sev=ERROR msg=Unknown element 'softwareImageConfigFile'
> id= line=10 column=26 sev=ERROR msg=Element 'softwareImageConfigFile' is
> not valid for content model: '(network,dsnSubnet)'
>
> And then it thows an exception which I assume comes from the
> DOMErrorHandler.
>
> I have tried to add the flag xml_schema::flags::dont_validate and in
> this case the unknown element is ignored, but if I have an other error
> like unknown enum value my application crashes which is not so good.
There is no way to selectively disable certain aspects of XML Schema
validation (which is more or less what you are asking for). You best
bet is to "relax" the schema to allow unknown elements (via the xs:any
wildcard) in some places where you expect them to appear. For example,
if you have:
<complexType name="Type">
<sequence>
<element name="network" type="..."/>
<element name="dnsSubnet" type="..."/>
</sequence>
</complexType>
Then you can change it to:
<complexType name="Type">
<sequence>
<element name="network" type="..."/>
<element name="dnsSubnet" type="..."/>
<any namespace="##any" processContents="skip"
minOccurs="0" maxOccurs="unbounded"/>
</sequence>
</complexType>
Which will allow any elements after network and dnsSubnet.
Boris
More information about the xsd-users
mailing list