Java XPath Evaluate evalXPath(String path, Document doc)

Here you can find the source of evalXPath(String path, Document doc)

Description

eval X Path

License

Open Source License

Declaration

public static String evalXPath(String path, Document doc) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import org.w3c.dom.Document;

import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;

public class Main {
    public static String evalXPath(String path, Document doc) {
        XPath xpath = newXPath();
        try {/*from   w  ww. j  av  a2s  .c om*/
            return xpath.evaluate(path, doc);
        } catch (XPathExpressionException e) {
            throw new RuntimeException(e);
        }
    }

    public static XPath newXPath() {
        XPathFactory factory = XPathFactory.newInstance();
        XPath xpath = factory.newXPath();
        return xpath;
    }
}

Related

  1. evaluateXPathExpressionAndReturnNodeList(String expression, Node node)
  2. evaluateXPathQuery(Document doc, NamespaceContext context, String xPathQuery)
  3. evalXPath(Node d, String expr, QName returnType)
  4. evalXPath(Node node, String xPath)
  5. evalXPath(String expression, Object item, Class type)
  6. evalXpath(String xpath, Object item)
  7. evalXPathAsString(Object item, String xpath, XPathFactory factory)
  8. evalXPathAsStringList(Object item, String xpath, XPathFactory factory, boolean includeDuplicates)
  9. executeXPath(Document dom, String xpath, QName returnType)