I'm trying to extract values from <to>
multiple nodes using XPath but what I have got is only first value
SOAP looks like:
<addressBlock xmlns:i="http://www.w3.org/2001/XMLSchema-instance" s:relay="1">
<from>mailto:user1@test.local</from>
<to>mailto:user2@test.local</to>
<to>mailto:user3@test2.local</to>
</addressBlock>
My code looks like:
private String extractFieldFromXml(Document doc, XPath xPath, String expression)
{
try
{
Node node = (Node) xPath.compile(expression).evaluate(doc, XPathConstants.NODE);
return node == null ? null : node.getTextContent();
} catch (XPathExpressionException e)
{
log.info(e.getMessage());
return null;
}
}
Then I have tried to do that:
String to = extractFieldFromXml(doc, xpath, msgExpression);
for (Iterator<String> to = to.iterator(); to.hasNext();) {
String value = to.next();
System.out.println(value);
}