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 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 Number selectNumber(Document xmlDocument, String expression) throws XPathExpressionException {
        return (Number) selectObject(xmlDocument, expression, XPathConstants.NUMBER);
    }

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

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