Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache 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.Node;

public class Main {
    public static String getValueByXpath(Node doc, String xquery) {
        try {
            XPathFactory factory = XPathFactory.newInstance();
            XPath xpath = factory.newXPath();
            XPathExpression expression = xpath.compile(xquery);
            String result = (String) expression.evaluate(doc, XPathConstants.STRING);
            return result;
        } catch (Exception e) {

        }
        return null;
    }
}