将 xml 文档解组为 Java 对象 (jaxb) 时出现问题
我使用 xjc 从 XSD 创建 java 对象。
现在我试图将 xml 文档解组到 java 对象,但我得到:
javax.xml.bind.UnmarshalException:意外元素(uri:"", local:"GlobalComponentInformation
这里有吗?
编辑:
我正在传递一个 org.w3c.dom.Document 对象,它从 Web 服务调用(axis 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;
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;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您从 Web 服务类接收的根元素:
与基于 JAXB 映射所期望的根元素不匹配:
package-info 类指定所有元素都应该是命名空间限定的 (javax.xml.bind.annotation)。 XmlNsForm.QUALIFIED),默认命名空间是
“http://www.mycompany.com/GlobalInformationResponseExt”
您将需要修复 XML 文档,或者更改 JAXB 映射以匹配文档。在这种情况下,通过删除 package-info。
The root element you are receiving from the web service class:
Does not match the expected root element that is expected based on your JAXB mappings:
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"
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.