1

xjc を使用して、XSD から Java オブジェクトを作成しました。

そして今、xmlドキュメントを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;
4

1 に答える 1

1

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 を削除します。

于 2010-11-08T16:34:59.500 に答える