I'm currently working on marshalling/unmarshalling XML messages. Here are my two XML elements :
@XmlRootElement(namespace = "http://namespaceA")
public class RootElementA {
@XmlElement
private ElementXX elementXX;
}
@XmlRootElement(namespace = "http://namespaceB")
public class RootElementB {
@XmlElement
private ElementXX elementXX;
}
When unmarshalling a RootElementB I have the following error :
javax.xml.bind.UnmarshalException: unexpected element (uri:"http://namespaceB", local:"ElementXX"). Expected elements are <{}ElementXX>
If I add the namespace to the ElementXX declaration, I have the same error except that it occurs for properties of ElementXX.
The problem is that I can't set the namespace on properties of ElementXX because it is specified in both namespaces and I don't want to duplicate my class just to change the namespace...
Do you have an idea ? Thanks.
EDIT
Here is a XML sample :
<RootElementA xmlns="http://namespaceA">
<ElementXX>
<name>blabla</name>
<desc>blabla</desc>
</ElementXX>
</RootElementA>
If I don't set a namespace to ElementXX in XmlRootElementA class I have the error above. If I set it, I have the same error but for the name property.