List of usage examples for javax.xml.xpath XPathConstants NODESET
QName NODESET
To view the source code for javax.xml.xpath XPathConstants NODESET.
Click Source Link
The XPath 1.0 NodeSet data type.
Maps to Java org.w3c.dom.NodeList .
From source file:Main.java
public static NodeList evalXpath(String xpath, Object item) throws XPathExpressionException { XPath xp = XPathFactory.newInstance().newXPath(); XPathExpression expr = xp.compile(xpath); return (NodeList) expr.evaluate(item, XPathConstants.NODESET); }
From source file:Main.java
public static Element querySingle(Element element, String query) { try {/* w ww.ja v a 2 s. c o m*/ XPathExpression expr = xpath.newXPath().compile(query); NodeList list = (NodeList) expr.evaluate(element, XPathConstants.NODESET); if (list.getLength() > 0) return (Element) list.item(0); } catch (XPathExpressionException e) { e.printStackTrace(); } return null; }
From source file:Main.java
public static Long extractValueId(Element element, String xpath) throws XPathExpressionException { XPath xpathObj = factory.newXPath(); NodeList nodeList = (NodeList) xpathObj.compile(xpath).evaluate(element, XPathConstants.NODESET); for (int i = 0; i < nodeList.getLength(); i++) { String val = nodeList.item(i).getFirstChild().getNodeValue(); return Long.parseLong(val); }/*from w w w .j a v a 2 s . c om*/ return null; }
From source file:Main.java
public static NodeList getNodesByXPath(Node node, String xpathStr) { XPath xpath = XPathFactory.newInstance().newXPath(); XPathExpression expr;/*from w w w. j a v a2 s . c o m*/ try { expr = xpath.compile(xpathStr); NodeList favoris = (NodeList) expr.evaluate(node, XPathConstants.NODESET); return favoris; } catch (XPathExpressionException e) { e.printStackTrace(); } return null; }
From source file:Main.java
/** * Evaluate xpath.//from w ww . j av a2 s .c om * * @param doc * the doc * @param expr * the expr * @return the object */ public static NodeList evaluateXpath(Document doc, XPathExpression expr) { NodeList XmlResult = null; try { XmlResult = (NodeList) expr.evaluate(doc, XPathConstants.NODESET); } catch (XPathExpressionException e) { e.printStackTrace(); } return XmlResult; }
From source file:Main.java
public static void forEachByXPath(Node n, String expression, Consumer<Node> action) { XPath path = xPathFactory.newXPath(); try {// w w w . j a v a2 s . c o m NodeList nl = (NodeList) path.evaluate(expression, n, XPathConstants.NODESET); forEach(nl, action); } catch (XPathExpressionException e) { throw new RuntimeException(e); } }
From source file:Main.java
public static NodeList getNodesListXpathNode(final String xPath, final Node node) throws Exception { return (NodeList) getNodesListXpath(xPath, node, "", "", XPathConstants.NODESET); }
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 Vector<Node> findNodes(String xpath, Node scope) throws XPathExpressionException { XPathFactory xpf = XPathFactory.newInstance(); XPath xp = xpf.newXPath();/*from www . java 2 s .c om*/ NodeList nl; Vector<Node> elements = new Vector<Node>(); nl = (NodeList) xp.evaluate(xpath, scope, XPathConstants.NODESET); for (int i = 0; i < nl.getLength(); i++) elements.add(nl.item(i)); return elements; }
From source file:Main.java
public static NodeList getXmlNodeSetForExpression(String expression, String is) throws XPathExpressionException { XPath xpath = XPathFactory.newInstance().newXPath(); InputSource inputSource = new InputSource(new StringReader(is)); return (NodeList) xpath.evaluate(expression, inputSource, XPathConstants.NODESET); }