Java如何解析SOAPMessage

时间:2017-09-15 07:45:48

标签: java xml parsing soap

我正在使用w3schools CelciusToFahrenheit的例子。

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);
        }

w3schools xml回复

<?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解析器无法解析并认为文档为空。

长话短说;我怎样才能从SOAPesponse中获取或获取价值

0 个答案:

没有答案
相关问题