简体   繁体   English

Java从SOAP响应中获得价值

[英]Java get Value from SOAP Response

I am getting the below SOAP Response 我收到以下SOAP响应

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soapenv:Body>
      <ns0:Get_Response xmlns:ns0="urn:DAL:OrderShim_WS">
         <ns0:Order_Number>Order001165</ns0:Order_Number>
      </ns0:Get_Response>
   </soapenv:Body>
</soapenv:Envelope>

I need to get Order_Number from above Response. 我需要从上面的响应中获取Order_Number For this I write the below Code 为此,我编写以下代码

import javax.xml.soap.MessageFactory;
import javax.xml.soap.MimeHeaders;
import javax.xml.soap.SOAPBody;
import javax.xml.soap.SOAPConnection;
import javax.xml.soap.SOAPConnectionFactory;
import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPHeader;
import javax.xml.soap.SOAPMessage;
import javax.xml.soap.SOAPPart;

public class Test {
    public static void main(String[] args) {
        try {
            SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
            SOAPConnection soapConnection = soapConnectionFactory.createConnection();
            String url = "http://devlocal:8080/arsys/services/";
            SOAPMessage soapResponse = soapConnection.call(createSOAPRequest(), url);
            soapResponse.writeTo(System.out);

            soapConnection.close();
        } catch (Exception e) {
            System.out.println("Exception : " + e);
        }
    }
}

I can able to get Response. 我可以得到回应。 But How can I get the value of Order_Number . 但是,如何获取Order_Number的值。

I am using Java. 我正在使用Java。

You should retrieve SOAPBody object and iterate its nodes like this: 您应该检索SOAPBody对象并像这样迭代其节点:

SOAPBody body = soapResponse .getSOAPBody();

NodeList returnList = body.getElementsByTagName("YOUR_TAG");
for (int k = 0; k < returnList.getLength(); k++) {
    NodeList innerResultList = returnList.item(k).getChildNodes();
    // processing nodes
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM