Java tutorial
//package com.java2s; import java.util.ArrayList; import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathExpression; import javax.xml.xpath.XPathExpressionException; import org.w3c.dom.Node; public class Main { public static String evalConcat(Node n, String delimiter, XPathExpression... exprs) throws XPathExpressionException { ArrayList<String> results = new ArrayList<String>(); for (XPathExpression expr : exprs) { results.add(orEmptyStr(expr, n)); } while (results.remove("")) ; String retn = ""; for (String s : results) { retn += s; if (results.indexOf(s) != results.size() - 1) { retn += delimiter; } } return retn; } public static String orEmptyStr(XPathExpression xpe, Node n) throws XPathExpressionException { Node inner = (Node) xpe.evaluate(n, XPathConstants.NODE); return inner == null ? "" : inner.getTextContent(); } }