Java XPath Evaluate evaluateXPathQuery(Document doc, NamespaceContext context, String xPathQuery)

Here you can find the source of evaluateXPathQuery(Document doc, NamespaceContext context, String xPathQuery)

Description

evaluate X Path Query

License

Apache License

Declaration

public static NodeList evaluateXPathQuery(Document doc, NamespaceContext context, String xPathQuery)
            throws XPathExpressionException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import org.w3c.dom.Document;

import org.w3c.dom.NodeList;

import javax.xml.namespace.NamespaceContext;

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;

public class Main {
    public static NodeList evaluateXPathQuery(Document doc, NamespaceContext context, String xPathQuery)
            throws XPathExpressionException {
        XPathExpression expr = createXPathExpression(context, xPathQuery);
        return (NodeList) expr.evaluate(doc, XPathConstants.NODESET);
    }/*from w  ww  .  java2  s. c om*/

    public static XPathExpression createXPathExpression(NamespaceContext context, String xPathQuery)
            throws XPathExpressionException {
        XPath xpath = XPathFactory.newInstance().newXPath();
        xpath.setNamespaceContext(context);
        return xpath.compile(xPathQuery);
    }
}

Related

  1. evaluateXPathExpr(final File xmlFile, final XPathExpression xPathExpression, final QName returnType)
  2. evaluateXPathExpr(XPathExpression xpath, Node node)
  3. evaluateXPathExpression(final String expression, final Node node)
  4. evaluateXPathExpressionAndReturnNode(String expression, Node node)
  5. evaluateXPathExpressionAndReturnNodeList(String expression, Node node)
  6. evalXPath(Node d, String expr, QName returnType)
  7. evalXPath(Node node, String xPath)
  8. evalXPath(String expression, Object item, Class type)
  9. evalXPath(String path, Document doc)