_1:Entitlement _1:Entitlement _1:Entitlement

JAXB unmarshall with multi namespace

50 Views Asked by At

I have a xml from third part.

<cts:element-value-query weight="0">
   <cts:element xmlns:_1="entitlement:AAA">_1:Entitlement</cts:element>
   <cts:text xml:lang="en">TEST</cts:text>
</cts:element-value-query>

Or :

<cts:element-value-query weight="0">
   <cts:element xmlns:_1="entitlement:BBB">_1:Entitlement</cts:element>
   <cts:text xml:lang="en">CASE</cts:text>
</cts:element-value-query>

I want to unmarshall the xml to Java bean:

@XmlRootElement(name = "element-value-query", namespace= "http://marklogic.com/cts")
@XmlAccessorType(XmlAccessType.FIELD)
public class Query4ElementValue {

@XmlElement(name= "element", namespace="entitlement:AAA")
private String element;

private String text;
}

I can get the correct text value, but for the element, always null.

[element=null, text=TEST]

How can I do then ?

1

There are 1 best solutions below

0
lexicore On

This:

<cts:element xmlns:_1="entitlement:AAA">_1:Entitlement</cts:element>

Is an element with the name element in the cts namespace.

Your mapping:

@XmlElement(name= "element", namespace="entitlement:AAA")
private String element;

Expects an element with the name element in the namespace with the URI entitlement:AAA. Which is probably not the cts namespace you're providing.

If you're interested in getting _1:Entitlement with _1 bound to entitlement:AAA or entitlement:BBB, change the type of the element to QName.