Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import org.w3c.dom.Node;

import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathExpressionException;

public class Main {
    public static String getNodeText(Node node, XPathExpression xpath) {
        try {
            Object result = xpath.evaluate(node, XPathConstants.NODE);
            if (result == null) {
                return null;
            }

            return ((Node) result).getTextContent();
        } catch (XPathExpressionException e) {
            throw new RuntimeException("Invalid XPath", e);
        }
    }
}