Reputation: 30058
I've used xjc to create java objects from XSD.
and now I am trying to unmarshal the xml doc to the java objects but I get:
javax.xml.bind.UnmarshalException: unexpected element (uri:"", local:"GlobalComponentInformation
Any here here?
EDIT:
I am passing a org.w3c.dom.Document object, it returned from a web service call (axis web service)...
Note, the Document object returned from ws to be parsed here contains the following root element:
<GlobalInformationResponseDocument xmlns="" />
@XmlRootElement class looks like:
XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"wsExternalResponse"
})
@XmlRootElement(name = "GlobalInformationResponseDocument")
public class GlobalInformationResponseDocument {
@XmlElement(name = "WS_ExternalResponse", required = true)
protected WSExternalResponseType wsExternalResponse;
/**
* Gets the value of the wsExternalResponse property.
*
* @return
* possible object is
* {@link WSExternalResponseType }
*
*/
public WSExternalResponseType getWSExternalResponse() {
return wsExternalResponse;
}
/**
* Sets the value of the wsExternalResponse property.
*
* @param value
* allowed object is
* {@link WSExternalResponseType }
*
*/
public void setWSExternalResponse(WSExternalResponseType value) {
this.wsExternalResponse = value;
}
}
package-info:
@javax.xml.bind.annotation.XmlSchema(namespace = "http://www.mycompany.com/GlobalInformationResponseExt",
elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
package com.company.jaxb.client;
Upvotes: 1
Views: 2362
Reputation: 148977
The root element you are receiving from the web service class:
<GlobalInformationResponseDocument xmlns="" />
Does not match the expected root element that is expected based on your JAXB mappings:
<GlobalInformationResponseDocument xmlns="http://www.mycompany.com/GlobalInformationResponseExt" />
The package-info class specifies that all elements should be namespace qualified (javax.xml.bind.annotation.XmlNsForm.QUALIFIED), and that the default namespace is "http://www.mycompany.com/GlobalInformationResponseExt"
@javax.xml.bind.annotation.XmlSchema(namespace = "http://www.mycompany.com/GlobalInformationResponseExt",
elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
package com.company.jaxb.client;
You will either need to fix the XML document, or change the JAXB mappings to match the documnent. In this case by removing package-info.
Upvotes: 1