views:

265

answers:

2

Hello All, this is a very common problem but I still need a specific solution if someone can please provide me with a solution.

JAXB.unmarshal('file', class);

However because of the namespaces present in the xml file the class object is not getting populated with the inner elements.

The turnaround I found was to create a JAXBContext object create and unmarshaller and then make it namespace aware.

I am inquisitive if there are any other solutions to the same.

+1  A: 

If the XML is using namespaces, those are part of the element name and they should not be parsed as if they were unnamespaced elements. Therefore that is not an option in JAXB. A previous question along these lines have given the only solution as sanitizing the XML prior to unmarshalling and removing all namespaces, with the JAXB objects bound to unnamespaced names.

jdmichal
A: 

If the nodes are always qualified with namespaces URIs the you should add this namespace information you your JAXB bindings. Many JAXB annotations take a namespace parameter (I.e XmlRootElement, XmlAttribute, XmlElement, etc.). Also there is a package level annotation called @XmlSchema you can use you to specify a default namespace and the default namespace qualification rules.

Blaise Doughan