[xsd-users] Ignoring unknown elements

Boris Kolpackov boris at codesynthesis.com
Tue Oct 14 01:38:08 EDT 2014


Hi Vladimir,

Vladimir Zykov <vladimir.zykov at ncloudtech.ru> writes:

> In our problem domain we cannot be sure about validity (in XML sense) of
> input XML documents.
>
> [...]
> 
> Shallow inspection of generated code shows that the problem can be fixed
> by mere removal of 'break' statement at the end of a for-loop that
> processes child elements in generated parse() function. Certainly this
> should be managed by command line option.

I am not certain about this. You are trying to parse an invalid XML
instance and this is quite unusual.

While the "fix" seems simple, the problem is that it will break (at
runtime) if someone derives from such a type. So the XSD compiler
would probably need to check that this doesn't happen. But that is
not always possible (e.g., if the derived type is in another schema).
So the "fix" becomes a lot less trivial and robust.

So before we go deeper into this, isn't there a cleaner way to
achieve the same end result. The two options that I see:

1. Add wildcards to your XML Schema types. I remember you told me that
   you auto-generate the schema so maybe this can be done fairly easily?

2. If the "extra" elements have a regular form (e.g., they are in a
   different namespace), then what you could do is pre-process the
   DOM representation of your document before handing it off to the
   XSD-generated code. The idea is to remove all the extra elements
   during this step.

Boris



More information about the xsd-users mailing list