Java Soap 请求 - 读取 soap 响应
2022-09-04 20:09:46
我正在尝试从从 Web 服务获得的响应中获取特定值。不幸的是,我不知道该怎么做。我使用在 stackoverflow 上找到的代码来创建 soap 请求并将响应内容写出到 stdout 中:
private static void printSOAPResponse(SOAPMessage soapResponse) throws Exception {
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
Source sourceContent = soapResponse.getSOAPPart().getContent();
System.out.print("\nResponse SOAP Message = ");
StreamResult result = new StreamResult(System.out);
transformer.transform(sourceContent, result);
}
一切都很好,但我不需要完整的响应内容:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:bin="http://localhost/WebService/bindings" xmlns:typ="http://localhost/WebService/types">
<soapenv:Header/>
<soapenv:Body>
<bin:doActionResponse>
<bin:out>
<typ:result>
<typ:code>?</typ:code>
<typ:description>?</typ:description>
</typ:result>
</bin:out>
</bin:doActionResponse>
</soapenv:Body>
</soapenv:Envelope>
我只需要此响应中的代码和描述值。我该怎么做?