I have an XML like:
<message xmlns:gtm="http:// www.example.com/working/gtm">
<gtm:header>
<someid></someid>
<sometext></sometext>
</gtm:header>
<gtm:customer>0123456789</gtm:customer>
</message>
I am using @XmlPath mappings. but when I run the code I get this error:
Exception [EclipseLink-25016] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.XMLMarshalException
Exception Description: A namespace for the prefix gtm:header was not found in the namespace resolver.
I wonder what am I missing?
Below is an example of how you can map your use case with EclipseLink JAXB (MOXy).
package-info
First you need to set up the namespace information using the package level
@XmlSchemaannotation. We will leverage the namespace prefixes specified with the@XmlNsannotation later with the@XmlPathannotation.Message
The
@XmlPathannotation is used to specify an XPath based mapping with MOXy. Since in the@XmlSchemaannotation we specifiedelementFormDefault=XmlNsForm.UNQUALIFIED, the portions of the XPath without a prefix will not be namespace qualified.jaxb.properties
To specify MOXy as your JAXB provider you need to add a file called
jaxb.propertiesin the same package as your domain model with the following entry (see http://blog.bdoughan.com/2011/05/specifying-eclipselink-moxy-as-your.html):Demo
input.xml/Output
For More Information