gpt4 book ai didi

java - 如何将 SOAP XML 解码为 Java 对象

转载 作者:搜寻专家 更新时间:2023-10-30 21:02:20 25 4
gpt4 key购买 nike

<分区>

在尝试将我的 soap XML 解码为 JAXB 对象时出现以下错误。

我们收到预期元素为空的错误。在解码 SOAP XML 时是否应该做任何特定的事情。

javax.xml.bind.JAXBContext jaxbContext = (javax.xml.bind.JAXBContext) JAXBContext.newInstance(Class.forName(requestName));
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
StringReader reader = new StringReader(SoapXmlString);
reqInfo = unmarshaller.unmarshal(reader);

出现以下错误:

 javax.xml.bind.UnmarshalException: unexpected element (uri:"http://schemas.xmlsoap.org/soap/envelope/", local:"Envelope"). Expected elements are (none)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent(UnmarshallingContext.java:642)
at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:254)
at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:249)
at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportUnexpectedChildElement(Loader.java:116)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext$DefaultRootLoader.childElement

这是示例 XML

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v2="http://example.com/v2">
<soapenv:Header/>
<soapenv:Body>
<v2:createSession>
<v2:client>
<!--Optional:-->
<v2:name>?</v2:name>
<!--Optional:-->
<v2:clientId>?</v2:clientId>
<!--Optional:-->
<v2:requestId>?</v2:requestId>
</v2:client>
<!--Optional:-->
<v2:oldSessionId>?</v2:oldSessionId>
<!--Optional:-->
<v2:clientIp>?</v2:clientIp>
<!--Optional:-->
<v2:clientIpStatus>?</v2:clientIpStatus>
<!--Optional:-->
<v2:superBYOBFlow>?</v2:superBYOBFlow>
<!--Optional:-->
<v2:FlowParams>?</v2:FlowParams>
<!--Optional:-->
<v2:deviceInfo>?</v2:deviceInfo>
</v2:createSession>
</soapenv:Body>
</soapenv:Envelope>

请帮忙。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com