users@jaxb.java.net

Re: UnMarshall time Validation and ValidationEventLocator

From: Kohsuke Kawaguchi <Kohsuke.Kawaguchi_at_Sun.COM>
Date: Thu, 03 Apr 2003 07:52:19 -0800

> Am I doing something wrong here ? How can I get the element name ?

There's no magic property you can access to get that information.

To me, it sounds like this is a generic problem. You are asking for
context information (surrounding element name, in this case) of an error,
which JAXB RI don't keep track of. There are a lot of other context
information, and I can imagine that someone might want to access the
ancestor element name or in-scope namespace bindings or things like that.
One time I receive an e-mail from a person who wants to get XPath
expression to the node that causes an error.


One way to do what you want is to intercept SAX events by yourself and
keep track of context information there. You set up:

XMLReader --> YourContextTracker --> JAXBUnmarshaller --> ErrorHandler

YourContextTracker should be written as XMLFilter, and you look for the
current element. Then once JAXB reports an error, your ErrorHandler can
ask YourContextTracker whatever information you need.

Does this make sense?


regards,
--
Kohsuke KAWAGUCHI                  408-276-7063 (x17063)
Sun Microsystems                   kohsuke.kawaguchi_at_sun.com