1

解组响应字符串(xml 格式)时出现以下错误。最初它抱怨 and ,所以我从响应中删除了肥皂部分。现在它出现了这个错误。

类是使用 JAXB 2 从提供的 WSDL 创建的

**javax.xml.bind.UnmarshalException: unexpected element (uri:"http://ws.taxwareenterprise.com", local:"calculateDocumentResponse"). Expected elements are (none)
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent(UnmarshallingContext.java:662)
    at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:258)
    at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:253)**

这是我的响应字符串(其中一部分)

**<calculateDocumentResponse xmlns="http://ws.taxwareenterprise.com">
            <txDocRslt>
                <jurSumRslts>
                    <jurSumRslt>
                        <xmptAmt>5.0</xmptAmt>
                        <txableAmt>15.0</txableAmt>
                        <txAmt>0.04</txAmt>
                        <txJurUID>...**

这是我的 xsd 的“CalculationResponse”(其中一部分)

<xs:complexType name="CalculationResponse">
        <xs:sequence>
            <xs:element name="txDocRslt" type="tns:TxDocRslt"/>
        </xs:sequence>
    </xs:complexType>

这是我的解组代码:

**final JAXBContext context = JAXBContext.newInstance(CalculationResponse.class);
            final Unmarshaller unmarshaller = context.createUnmarshaller();
            response = processResponse(response);//for removing soap headers
            responseObj = (CalculationResponse) unmarshaller.unmarshal(new StringReader(response));//Fails here...
            final TxDocRslt txDocRslt = responseObj.getTxDocRslt();**
4

0 回答 0