Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import javax.xml.transform.TransformerException;

import javax.xml.xpath.*;

import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class Main {
    public static NodeList executeXpathQuery(Node root, String query) throws TransformerException {

        try {
            XPathFactory factory = XPathFactory.newInstance();
            XPath xpath = factory.newXPath();
            XPathExpression expr = xpath.compile(query);

            Object result = expr.evaluate(root, XPathConstants.NODESET);
            NodeList nodes = (NodeList) result;
            return nodes;
        } catch (XPathExpressionException e) {
            throw new RuntimeException(e);
        }
    }
}