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 javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathFactory;
import org.w3c.dom.*;

public class Main {

    public static String getConfigParam(Document xml, String xPath) throws Exception {
        //        NodeList nodeList = XPathAPI.selectNodeList(xml, xPath);
        NodeList nodeList = selectNodeList(xml, xPath);
        if (nodeList.getLength() == 0)
            return null;
        return nodeList.item(0).getNodeValue();
    }

    public static NodeList selectNodeList(Node xml, String xPath) throws Exception {
        XPath xpath = XPathFactory.newInstance().newXPath();
        XPathExpression expr = xpath.compile(xPath);
        NodeList nodeList = (NodeList) expr.evaluate(xml, XPathConstants.NODESET);
        return nodeList;
    }
}