将 xml 文档解组为 Java 对象 (jaxb) 时出现问题

发布于 2024-09-30 20:41:49 字数 1616 浏览 1 评论 0原文

我使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

过期情话 2024-10-07 20:41:49

您从 Web 服务类接收的根元素:

<GlobalInformationResponseDocument xmlns="" />

与基于 JAXB 映射所期望的根元素不匹配:

<GlobalInformationResponseDocument xmlns="http://www.mycompany.com/GlobalInformationResponseExt" />

package-info 类指定所有元素都应该是命名空间限定的 (javax.xml.bind.annotation)。 XmlNsForm.QUALIFIED),默认命名空间是
“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;

您将需要修复 XML 文档,或者更改 JAXB 映射以匹配文档。在这种情况下,通过删除 package-info。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文