Java XPath Evaluate executeXPathExpression(Document document, String expression)

Here you can find the source of executeXPathExpression(Document document, String expression)

Description

execute X Path Expression

License

Open Source License

Declaration

public static NodeList executeXPathExpression(Document document, String expression) 

Method Source Code

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

import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
import org.w3c.dom.Document;

import org.w3c.dom.NodeList;

public class Main {
    public static NodeList executeXPathExpression(Document document, String expression) {
        NodeList nodeList = null;
        XPathFactory xPathfactory = XPathFactory.newInstance();
        XPath xpath = xPathfactory.newXPath();
        XPathExpression expr;//from   w w w.  j a  va2s .co  m
        try {
            expr = xpath.compile(expression);
            nodeList = (NodeList) expr.evaluate(document, XPathConstants.NODESET);
        } catch (XPathExpressionException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return nodeList;
    }
}

Related

  1. evalXPath(String path, Document doc)
  2. evalXpath(String xpath, Object item)
  3. evalXPathAsString(Object item, String xpath, XPathFactory factory)
  4. evalXPathAsStringList(Object item, String xpath, XPathFactory factory, boolean includeDuplicates)
  5. executeXPath(Document dom, String xpath, QName returnType)
  6. execXPath(org.w3c.dom.Node node, String pattern, QName xPathConstantsType)
  7. findNodeAndGetXPath(String qName, String fileName)
  8. getNodesListXpath(final String xPathS, final Node node, final String nsuri, final String pre, final QName returnType)
  9. parseVariable(Node contextNode, String xPathString)