简体   繁体   English

从字符串获取价值-Java

[英]Get value from String - Java

I get a response from the server. 我从服务器收到响应。

SOAPMessage soapResponse = soapConnection.call(msgRequest, targetEndpoint);

How do I get the documentId value? 如何获取documentId值?

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
   <SOAP-ENV:Body>
      <retrieveDocumentRequest>
         <documentId>Test</documentId>
      </retrieveDocumentRequest>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

This should solve your problem: 这应该可以解决您的问题:

...
SOAPBody soapBody = soapResponse.getSOAPBody(); //get body instance from your response

NodeList nodes = soapBody.getElementsByTagName("documentId"); //get documentId property from your body 
String documentId = null;
Node node = nodes.item(0); //match the first correspondence
documentId = node != null ? node.getTextContent() : ""; //check if is null otherwise return your match
...

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

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