Example usage for javax.xml.xpath XPathConstants NODE

List of usage examples for javax.xml.xpath XPathConstants NODE

Introduction

In this page you can find the example usage for javax.xml.xpath XPathConstants NODE.

Prototype

QName NODE

To view the source code for javax.xml.xpath XPathConstants NODE.

Click Source Link

Document

The XPath 1.0 NodeSet data type.

Usage

From source file:Main.java

public static String getNodeText(Node node, XPathExpression xpath) {
    try {//from  ww  w. j a  v a2  s.c o m
        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);
    }
}

From source file:Main.java

public static Node findNode(Document doc, String xpath) {
    return (Node) xpathFind(doc, xpath, XPathConstants.NODE);
}

From source file:Main.java

public static Node oneOf(Node parent, XPathExpression... exprs) throws XPathExpressionException {
    for (XPathExpression expr : exprs) {
        Node child = (Node) expr.evaluate(parent, XPathConstants.NODE);
        if (child != null) {
            return child;
        }/*from  ww  w  .j a  va  2  s . c  o m*/
    }
    return null;
}

From source file:Main.java

public static Node evalXPathNode(String xpath, InputSource source) throws XPathExpressionException {
    return (Node) newXPath(xpath).evaluate(source, XPathConstants.NODE);
}

From source file:Main.java

public static Node nodeForXPath(Node node, String xPathString) throws XPathExpressionException {
    QName returnType = XPathConstants.NODE;
    return (Node) getXPath(node, xPathString, returnType);
}

From source file:Main.java

public static Element evalXPathElement(String xpath, InputSource source) throws XPathExpressionException {
    return (Element) newXPath(xpath).evaluate(source, XPathConstants.NODE);
}

From source file:Main.java

static public Element element(Node context, String expression) {
    try {/*from  www  .jav  a  2 s.  co m*/
        return (Element) xpath.evaluate(expression, context, XPathConstants.NODE);
    } catch (XPathExpressionException ex) {
        ex.printStackTrace();
        throw new RuntimeException("invalid xpath expresion used");
    }
}

From source file:Main.java

public static Node selectSingleNode(String Xpath, Node InNode, String nsuri, String pre) throws Exception {
    return (Node) getNodesListXpath(Xpath, InNode, nsuri, pre, XPathConstants.NODE);
}

From source file:Main.java

public static Node findNode(String xpath, Node scope) throws XPathExpressionException {
    XPathFactory xpf = XPathFactory.newInstance();
    XPath xp = xpf.newXPath();/* ww  w .j  a  v  a 2  s  .  c  o  m*/

    return (Node) xp.evaluate(xpath, scope, XPathConstants.NODE);
}

From source file:Main.java

public static Node getXmlNodeForExpression(String expression, Node widgetNode) throws XPathExpressionException {
    XPath xpath = XPathFactory.newInstance().newXPath();
    return (Node) xpath.evaluate(expression, widgetNode, XPathConstants.NODE);

}