Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//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;
import org.w3c.dom.NodeList;
import java.util.Vector;

public class Main {
    public static Vector<Node> findNodes(String xpath, Node scope) throws XPathExpressionException {
        XPathFactory xpf = XPathFactory.newInstance();
        XPath xp = xpf.newXPath();
        NodeList nl;
        Vector<Node> elements = new Vector<Node>();

        nl = (NodeList) xp.evaluate(xpath, scope, XPathConstants.NODESET);

        for (int i = 0; i < nl.getLength(); i++)
            elements.add(nl.item(i));

        return elements;
    }
}