Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import javax.xml.namespace.QName;

import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
import org.w3c.dom.Document;

import org.w3c.dom.Node;

public class Main {
    public static Node evaluateToNode(Document document, String expression) throws XPathExpressionException {
        return (Node) evaluate(document, expression, XPathConstants.NODE);
    }

    public static Object evaluate(Document document, String expression, QName returnType)
            throws XPathExpressionException {
        XPathExpression xpathexp = getXPathExpression(expression);
        return xpathexp.evaluate(document, returnType);
    }

    public static XPathExpression getXPathExpression(String expression) throws XPathExpressionException {
        return getXPathInstance().compile(expression);
    }

    public static XPath getXPathInstance() {
        XPath xPath = XPathFactory.newInstance().newXPath();
        return xPath;
    }
}