users@jaxb.java.net

Re: Adding default namespace during unmarshal

From: Kenny MacLeod <kennym_at_kizoom.com>
Date: Wed, 24 Oct 2007 07:09:09 +0100

My suggestion would be to read the old documents into a JDOM (see
jdom.org), do a deep iteration over each element, calling the
setNamespace() method.

 From there, wrap the JDOM in a JDOMSource and pass that directly to
your JAXB Unmarshaller using unmarshal(Source).

Just avoid org.w3c.dom, that's a ghastly piece of work :)


vr.sundar wrote:
> Hi,
>
> I'm using the jaxb annotations to generate our schema from annotated
> java classes. Currently, there is no namespace specified. Going
> forward, we would like to add a namespace at the package level or via
> namespace attribute to an appropriate jaxb annotation. (All the
> objects are in one namespace)
>
> Question is, if that were done, how to unmarshal earlier xml content
> which wouldn't have the namespace. My tests show that those fail as
> the namespace is not specified. I didn't find a way to specify
> something like a default namespace in the unmarshaller. Is there
> anyway to do this?.
>
> If not, is there a way to do this by first converting the xml to a dom
> tree and then changing the dom? My brief attempts at this failed as
> the namespace seems to be much more then just adding an xmlns
> attribute to an element. Maybe I have to somehow transform each
> element in the tree. I don't have a clear idea yet and any
> help/suggestions would be greatly appreciated.
>
> thanks
> sundar
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>