users@jaxb.java.net

Re: Unmarshaller.setSchema vs Unmarshaller.setEventHandler

From: Kohsuke Kawaguchi <Kohsuke.Kawaguchi_at_Sun.COM>
Date: Mon, 13 Jun 2005 19:34:52 -0400

Dmitri Colebatch wrote:
> Hi again,
>
> I'm in a situation where I want to be able to parse old versions of
> schemas, including incompatible changes. When unmarshalling these
> schemas I'd like to just ignore any elements or attributes that are
> not in the current schema and fit the response into the current schema
> structure as best as I can.

That is one of the use cases for JAXB.

> The javadoc for Unmarshaller.setSchema indicates that if i call
> setSchema(null) there will be no validation. I tried this approach,
> but still got failures (unexpected element). I'm now setting my own
> ValidationEventHandler that simply returns true (ie ignore all
> errors).

setSchema(null) is the default, so you don't have to explicitly call it.
I'll update the javadoc so that it explicitly says that's the default.

We recently changed the default ValidationEventHandler so that it
ignores unexpected elements by default.

> Two questions - firstly is the javadoc correct (btw this is using
> jaxb-ri-20050407), and secondly is what I'm doing the best approach
> for my scenario?

Yes, except that you don't have to set your own ValidationEventHandler
if you are using more recent version of the JAXB RI.


-- 
Kohsuke Kawaguchi
Sun Microsystems                   kohsuke.kawaguchi_at_sun.com