Example usage for javax.xml.xpath XPathExpression evaluate

List of usage examples for javax.xml.xpath XPathExpression evaluate

Introduction

In this page you can find the example usage for javax.xml.xpath XPathExpression evaluate.

Prototype

public Object evaluate(InputSource source, QName returnType) throws XPathExpressionException;

Source Link

Document

Evaluate the compiled XPath expression in the context of the specified InputSource and return the result as the specified type.

Usage

From source file:Main.java

public static Object getXPath(Node node, String xPathString, QName returnType) throws XPathExpressionException {
    XPathFactory xPathFactory = XPathFactory.newInstance();
    XPath xPath = xPathFactory.newXPath();
    XPathExpression expression = xPath.compile(xPathString);
    return expression.evaluate(node, returnType);
}

From source file:Main.java

public static NodeList getResultXpath(String expr, InputSource inputSource) throws XPathExpressionException {
    XPathExpression xExpr = xPath.compile(expr);
    NodeList evaluate = (NodeList) xExpr.evaluate(inputSource, XPathConstants.NODESET);
    return evaluate;
}

From source file:Main.java

public static NodeList evalXpath(InputStream xmlStream, String path) throws XPathExpressionException {
    InputSource inXML = new InputSource(xmlStream);
    XPathFactory xfactory = XPathFactory.newInstance();
    XPath xpath = xfactory.newXPath();
    XPathExpression expr = xpath.compile(path);
    Object result = expr.evaluate(inXML, XPathConstants.NODESET);
    return (NodeList) result;
}

From source file:Main.java

public static String evalXPathAsString(Object item, String xpath, XPathFactory factory)
        throws XPathExpressionException {
    XPath path = factory.newXPath();
    XPathExpression expr = path.compile(xpath);
    return (String) expr.evaluate(item, XPathConstants.STRING);
}

From source file:Main.java

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;
}

From source file:Main.java

public static NodeList getNodeList(Document doc, String xPathAsString) throws XPathExpressionException {
    XPath xpath = XPathFactory.newInstance().newXPath();
    XPathExpression expr = xpath.compile(xPathAsString);
    return (NodeList) expr.evaluate(doc, XPathConstants.NODESET);
}

From source file:Main.java

public static NodeList getNodeList(Node node, String xPathAsString) throws XPathExpressionException {
    XPath xpath = XPathFactory.newInstance().newXPath();
    XPathExpression expr = xpath.compile(xPathAsString);
    return (NodeList) expr.evaluate(node, XPathConstants.NODESET);
}

From source file:Main.java

public static NodeList evalXPathAsNodeList(Object item, String xpath, XPathFactory factory)
        throws XPathExpressionException {
    XPath path = factory.newXPath();
    XPathExpression expr = path.compile(xpath);
    return (NodeList) expr.evaluate(item, XPathConstants.NODESET);
}

From source file:Main.java

public static Object read(Node node, String expression, QName returnType) throws XPathExpressionException {
    XPath xpath = XPathFactory.newInstance().newXPath();
    XPathExpression xPathExp = xpath.compile(expression);
    return xPathExp.evaluate(node, returnType);
}

From source file:Main.java

/**
 * @param doc//  ww w  . j a v a2s  . c  o m
 * @param expr
 * @return
 * @throws XPathExpressionException
 */
public static Element findElement(Document doc, XPathExpression expr) throws XPathExpressionException {
    Object evaluate = expr.evaluate(doc, XPathConstants.NODE);
    return (Element) evaluate;
}