Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java如何解析SOAPMessage_Java_Xml_Parsing_Soap - Fatal编程技术网

Java如何解析SOAPMessage

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调用方法

我使用的是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调用方法,它是一个有效的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解析或获取值