我正在使用此方法将SOAPMessage响应转换为XML String。转换后,我需要获取特定的节点值。
/**
* Method used to convert the response to XML string
*/
private String getSOAPResponseString(SOAPMessage soapResponse) throws Exception {
StringWriter sw = new StringWriter();
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
Source sourceContent = soapResponse.getSOAPPart().getContent();
StreamResult result = new StreamResult(sw);
transformer.transform(sourceContent, result);
//System.out.println(sw.toString());
//System.out.println(soapResponse.getMimeHeaders());
return sw.toString();
}
我从XML String中检查这个节点。但它并不总是以
的形式出现
String responseMsg = response.substring(response.indexOf("<providerReturnMessage>") + "<providerReturnMessage>".length() , response.indexOf("</providerReturnMessage>"));
有时它前面有一个前缀,就像这样
<axis2ns7:providerReturnMessage>, <axis2ns8:providerReturnMessage>
,如何在此节点中读取消息文本,忽略前面的前缀。