Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import javax.xml.namespace.QName;

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 Node selectSingleNode(String Xpath, Node InNode, String nsuri, String pre) throws Exception {
        return (Node) getNodesListXpath(Xpath, InNode, nsuri, pre, XPathConstants.NODE);
    }

    public static Node selectSingleNode(String Xpath, Node InNode) throws Exception {
        // TODO put a node type checker so it can be used for documents or nodes
        return selectSingleNode(Xpath, InNode, "", "");
    }

    public static Object getNodesListXpath(String XpathS, Node node, String nsuri, String pre, QName returnType)
            throws Exception {
        Object matches = null;
        // TODO move this to a generic start up method
        //System.setProperty("javax.xml.xpath.XPathFactory:"+ XPathConstants.DOM_OBJECT_MODEL, XpathFactory);

        XPathFactory xpathFactory = XPathFactory.newInstance(XPathConstants.DOM_OBJECT_MODEL);
        XPath xpath = xpathFactory.newXPath();
        XPathExpression xpe = xpath.compile(XpathS);
        matches = xpe.evaluate(node, returnType);

        return matches;
    }
}