Java Utililty Methods XPath Get

List of utility methods to do XPath Get

Description

The list of methods to do XPath Get are organized into topic(s).

Method

StringgetLatestVersion(String tempDir, String url, String groupId, String artifactId, String version)
get Latest Version
return getLatestVersion(tempDir, url, null, groupId, artifactId, version);
ListgetListValue(Node node, XPathExpression expression)
Evaluates the XPath expression in the specified context and returns the found items as a List.
try {
    NodeList nodeList = (NodeList) expression.evaluate(node, XPathConstants.NODESET);
    List<String> list = new ArrayList<String>(nodeList.getLength());
    for (int i = 0; i < nodeList.getLength(); i++) {
        Node item = nodeList.item(i);
        list.add(item.getFirstChild().getNodeValue());
    return list;
...
HashMapgetListValue(String targetDoc, List xpathExps, String encoding)
get List Value
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(new ByteArrayInputStream(targetDoc.getBytes(encoding)));
XPathFactory pathFactory = XPathFactory.newInstance();
XPath xpath = pathFactory.newXPath();
XPathExpression pathExpression;
String result;
HashMap<String, String> values = new HashMap<String, String>();
for (String xpathExp : xpathExps) {
...
StringgetMessage(XPathExpressionException e)
get Message
String msg;
Throwable t = e;
do {
    msg = t.getMessage();
    t = t.getCause();
} while (msg == null && t != null);
return msg;
StringGetMobivateSessionId()
Get Mobivate Session Id
try {
    String loginUri = String.format(LoginUrlModifier, URLEncoder.encode(Username, "ISO-8859-1"), Password);
    Document document = DoApiCall(loginUri, null);
    return extractData(document, "/xaresponse/session");
} catch (XPathExpressionException | UnsupportedEncodingException ex) {
    return null;
StringgetNameBasedXPath(Node n, boolean includeCurrent)
get Name Based X Path
Node parent = null;
Stack<Node> hierarchy = new Stack<Node>();
if (includeCurrent) {
    hierarchy.push(n);
parent = n.getParentNode();
while (null != parent && parent.getNodeType() != Node.DOCUMENT_NODE) {
    hierarchy.push(parent);
...
XPathgetNewXPath()
get New X Path
return XPathFactory.newInstance().newXPath();
XPathgetNewXPath()
Create and return a new XPath object from ThreadLocal .
return XPATH_FACTORY.get().newXPath();
NodegetNode(Node node, XPathExpression xpath)
get Node
try {
    Object result = xpath.evaluate(node, XPathConstants.NODE);
    return (Node) result;
} catch (XPathExpressionException e) {
    throw new RuntimeException("Invalid XPath", e);
NodegetNode(String xPathExpression, Node node)
get Node
return (Node) xPath.evaluate(xPathExpression, node, XPathConstants.NODE);