Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*-****************************************************************************** 
 * Copyright (c) 2014 Iwao AVE!.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Iwao AVE! - initial API and implementation and/or initial documentation
 *******************************************************************************/

import javax.xml.namespace.NamespaceContext;
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;
import org.w3c.dom.Node;

public class Main {
    public static boolean xpathBool(Node node, String expression) throws XPathExpressionException {
        return ((Boolean) evaluateXpath(expression, node, XPathConstants.BOOLEAN, null)).booleanValue();
    }

    public static Object evaluateXpath(String expression, Object node, QName returnType, NamespaceContext nsContext)
            throws XPathExpressionException {
        XPathFactory xpathFactory = XPathFactory.newInstance();
        XPath xpath = xpathFactory.newXPath();
        if (nsContext != null) {
            xpath.setNamespaceContext(nsContext);
        }
        return xpath.evaluate(expression, node, returnType);
        // XPathExpression xpathExpr = xpath.compile(expression);
        // return xpathExpr.evaluate(node, returnType);
    }
}