Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import org.w3c.dom.Document;

import org.w3c.dom.NodeList;
import javax.xml.namespace.QName;

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

public class Main {
    public static NodeList selectNodeList(Document xmlDocument, String expression) throws XPathExpressionException {
        return (NodeList) selectObject(xmlDocument, expression, XPathConstants.NODESET);
    }

    public static Object selectObject(Document xmlDocument, String expression, QName returnType)
            throws XPathExpressionException {
        XPath xPath = XPathFactory.newInstance().newXPath();

        return xPath.compile(expression).evaluate(xmlDocument, returnType);
    }
}