我使用xjc从XSD创建java对象 .
现在我试图将xml doc解组为java对象,但我得到:
javax.xml.bind.UnmarshalException: unexpected element (uri:"", local:"GlobalComponentInformation
在这里吗?
编辑:
我正在传递一个org.w3c.dom.Document对象,它从Web服务调用(轴Web服务)返回...
注意,从这里要解析的ws返回的Document对象包含以下根元素:
<GlobalInformationResponseDocument xmlns="" />
@XmlRootElement类看起来像:
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;
}
}
包信息:
@javax.xml.bind.annotation.XmlSchema(namespace = "http://www.mycompany.com/GlobalInformationResponseExt",
elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
package com.company.jaxb.client;
1 回答
您从Web服务类接收的根元素:
与基于JAXB映射的预期根元素不匹配:
package-info类指定所有元素都应该是名称空间限定的(javax.xml.bind.annotation.XmlNsForm.QUALIFIED),并且默认名称空间是"http://www.mycompany.com/GlobalInformationResponseExt"
您将需要修复XML文档,或更改JAXB映射以匹配documnent . 在这种情况下,删除package-info .