Получить значение из String - Java - PullRequest
0 голосов
/ 13 декабря 2018

Я получаю ответ от сервера.

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

Как получить значение 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>

1 Ответ

0 голосов
/ 13 декабря 2018

Это должно решить вашу проблему:

...
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
...
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...