Java如何解析SOAPMessage
我使用的是W3Celciustofahrenheit示例Java如何解析SOAPMessage,java,xml,parsing,soap,Java,Xml,Parsing,Soap,我使用的是W3Celciustofahrenheit示例 String soapEndpointUrl = "https://www.w3schools.com/xml/tempconvert.asmx"; //https://www.w3schools.com/xml/CelsiusToFahrenheit String soapAction = "https://www.w3schools.com/xml/CelsiusToFahrenheit"; 这是我的SoapResponse调用方法
String soapEndpointUrl = "https://www.w3schools.com/xml/tempconvert.asmx";
//https://www.w3schools.com/xml/CelsiusToFahrenheit
String soapAction = "https://www.w3schools.com/xml/CelsiusToFahrenheit";
这是我的SoapResponse调用方法,它是一个有效的xml
ByteArrayOutputStream bout = new ByteArrayOutputStream();
soapResponse.writeTo(bout);
soapConnection.close();
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = null;
try {
builder = factory.newDocumentBuilder();
} catch (ParserConfigurationException e) {
e.printStackTrace();
}
String xml = bout.toString("UTF-8"); // <-- The XML SOAP response
Document xmlDocument = builder.parse(new ByteArrayInputStream(xml.getBytes()));
xmlDocument.getDocumentElement().normalize();
NodeList nList = xmlDocument.getElementsByTagName("CelsiusToFahrenheitResponse");
for (int temp = 0; temp < nList.getLength(); temp++) {
Node nNode = nList.item(temp);
}
W3XML响应
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><CelsiusToFahrenheitResponse xmlns="https://www.w3schools.com/xml/"><CelsiusToFahrenheitResult>212</CelsiusToFahrenheitResult></CelsiusToFahrenheitResponse></soap:Body></soap:Envelope>
İ不能只获取值,因为dom解析器不能解析文档,并且认为文档为空
长话短说;我如何从SOAPResponse解析或获取值