convenience method to evaluate an xpath expression against a DOM document - Android XML

Android examples for XML:XPath

Description

convenience method to evaluate an xpath expression against a DOM document

Demo Code


//package com.java2s;

import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathExpressionException;

import org.w3c.dom.Document;

import org.w3c.dom.NodeList;

public class Main {
    /**//from   w ww  .j a v a2  s.  c o  m
     *  convenience method to evaluate an xpath expression against a DOM document
     * @param DOM the document
     * @param xpath the xpath
     * @return NodeList of retrieved nodes
     * @throws XPathExpressionException
     */
    public static NodeList evaluateXPath(Document DOM, XPathExpression xpath)
            throws XPathExpressionException {

        NodeList result = (NodeList) xpath.evaluate(DOM,
                XPathConstants.NODESET);

        return result;
    }
}

Related Tutorials