trong khi cố gắng unmarshall xà phòng XML của tôi để JAXB đối tượng đang nhận được lỗi sau.Làm thế nào để unmarshall SOAP XML đối tượng Java
Chúng tôi đang nhận được lỗi mà yếu tố mong đợi là không có. Bất cứ điều gì cụ thể được thực hiện trong khi unmarshalling XML SOAP.
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);
Am nhận được lỗi sau:
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
và đây là mẫu 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>
hãy làm giúp đỡ.
giá trị gì 'requestName' có? – Priyesh
Xem [tại đây] (http://blog.bdoughan.com/2012/08/handle-middle-of-xml-document-with-jaxb.html). –
@priyesh: tên lớp của nó. Ví dụ: createSessionRequest – srinath