I have a problem with JAXB marshalling. I have a set of classes generated from some XSD. I need to be able to change the namespace URI dynamically - when marshalling an object.
I simply used my own QName, like
new JAXBElement<MyType>(new QName(uri, "Doc") ....
and it works. However the problem is that MyType
composes of few other classes, and I would like to change namespace for them as well (in fact all of those elements use one and the same namespace, and I only want to change the URI of this namespace).
Resulting XML changes namespace only for my "root" element, the one I specified QName for, it looks like this
<ns2:Dok>
<ns1:Elem>a</ns1:Elem>
</ns2:Dok>
Where ns2 is new namespace I supplied with QName, but ns1 is still the "old one", if written in package info for generated classes). My question is - how to change the namespace for good? How to change a namespace URI for all the elements, how to make my new QName to apply down to all child elements as well?