Evaluate xPath and return Node - Java XML

Java examples for XML:XPath

Description

Evaluate xPath and return Node

Demo Code


//package com.java2s;

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

import org.w3c.dom.Node;

public class Main {
    public static Node xPathNodeList(Node node, String path)
            throws XPathExpressionException {
        XPath xpath = XPathFactory.newInstance().newXPath();
        return (Node) xpath.evaluate(path, node, XPathConstants.NODE);
    }//from   w ww.  jav  a 2 s .  c om
}

Related Tutorials