Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

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

public class Main {
    /***
     * Returns the string value of evaluated xpath
     *
     * @param  document    - XML Document to check
     * @param  xpathString - xpath to evaluate
     * @return String evaluation of the xpath
     */
    public static String getValueFromXPath(Document document, String xpathString) {
        try {
            return (String) XPathFactory.newInstance().newXPath().evaluate(xpathString, document,
                    XPathConstants.STRING);
        } catch (XPathExpressionException e) {
            throw new RuntimeException("Error evaluating xpath [" + xpathString + "] -- " + e.getMessage());
        }
    }
}