users@jaxb.java.net

Re: Whats the easiest way to find the namespace context at the point on which a POJO is instantiated?

From: Aleksei Valikov <valikov_at_gmx.net>
Date: Thu, 11 Oct 2007 22:29:26 +0200

Hi.

> I've a simple JAXB POJO for XPath expressions I'm marshalling in Apache Camel
> like this...
>
> <xpath>/foo/bar</xpath>
>
> What I'd like to do is inject the XPath POJO with the XML namespaces
> available at the <xpath> element so that the namespace prefixes can be used
> inside the XPath expression. e.g.
>
> <foo xmlns:x="cheese">
> <xpath>/x:foo</xpath>
> </foo>
>
> I've had a little look around the JAXB API and I don't see any way to kinda
> grab the namespace context; any one got any neat ideas?
>
> Note this is only an issue for parsing.

Check out the binder API. You could maintain DOM and unmarshalled
objects in parallel and refer to DOM for things that are not mapped -
like namespace declarations, comments, processing instructions etc.

Another ide would be to put a SAX filter between XML and JAXB
unmarshaller and gather NS declarations there.

Bye.
/lexi