List of usage examples for javax.xml.xpath XPathExpression evaluate
public Object evaluate(InputSource source, QName returnType) throws XPathExpressionException;
From source file:Main.java
public static Object getNodesListXpath(String XpathS, Node node, String nsuri, String pre, QName returnType) throws Exception { Object matches = null;/* w w w . j av a 2 s. co m*/ // 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; }
From source file:Main.java
public static Object evaluate(Document document, String expression, QName returnType) throws XPathExpressionException { XPathExpression xpathexp = getXPathExpression(expression); return xpathexp.evaluate(document, returnType); }
From source file:Main.java
public static Object getNodesListXpath(String XpathS, Node node, String nsuri, String pre, QName returnType) throws Exception { Object matches = null;/* w ww . j a v a 2 s . c o m*/ // 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; }
From source file:Main.java
/** * @param doc/*w w w . jav a 2s .co m*/ * @param expr * @return * @throws XPathExpressionException */ public static NodeList findNodes(Document doc, XPathExpression expr) throws XPathExpressionException { Object evaluate = expr.evaluate(doc, XPathConstants.NODESET); NodeList nodes = (NodeList) evaluate; return nodes; }
From source file:Main.java
public static NodeList getElementsByXpath(Document docInput, String xPath) throws XPathExpressionException { XPathFactory factory = XPathFactory.newInstance(); XPath xpath = factory.newXPath(); XPathExpression expr = xpath.compile(xPath); return ((NodeList) expr.evaluate(docInput, XPathConstants.NODESET)); }
From source file:Main.java
public static NodeList executeXpathQuery(Node root, String query) throws TransformerException { try {// www. j a v a 2 s.c om XPathFactory factory = XPathFactory.newInstance(); XPath xpath = factory.newXPath(); XPathExpression expr = xpath.compile(query); Object result = expr.evaluate(root, XPathConstants.NODESET); NodeList nodes = (NodeList) result; return nodes; } catch (XPathExpressionException e) { throw new RuntimeException(e); } }
From source file:Main.java
public static Node getXpathExpressionNode(Object xprContext, String xpExpression) throws XPathExpressionException { XPath xpath = XPathFactory.newInstance().newXPath(); XPathExpression xpe = xpath.compile(xpExpression); Node node = (Node) xpe.evaluate(xprContext, XPathConstants.NODE); return node;//from w w w. j av a 2 s . c om }
From source file:Main.java
public static String getString(Object node, XPathExpression expression) throws XPathExpressionException { return (String) expression.evaluate(node, XPathConstants.STRING); }
From source file:Main.java
public static List<String> getValueList(Node node, String exprStr) throws XPathExpressionException { ArrayList<String> r = new ArrayList<>(); XPathExpression expr = xpath.compile(exprStr); NodeList nodes = (NodeList) expr.evaluate(node, XPathConstants.NODESET); for (int i = 0; i < nodes.getLength(); i++) { r.add(nodes.item(i).getNodeValue()); }/*from w ww .ja v a 2 s. c o m*/ return r; }
From source file:Main.java
public static double getDouble(Object node, XPathExpression expression) throws XPathExpressionException { return ((Double) expression.evaluate(node, XPathConstants.NUMBER)).doubleValue(); }