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 List<Element> getXmlElements(Document inXml, String xpath) { try {//from w w w. jav a 2s .c om NodeList nodeList = (NodeList) xPath.evaluate(xpath, inXml, XPathConstants.NODESET); List<Element> results = new ArrayList<>(); for (int i = 0; i < nodeList.getLength(); i++) { results.add((Element) nodeList.item(i)); } return results; } catch (Exception ex) { throw new RuntimeException("Could not run xpath: " + xpath, ex); } }
From source file:Main.java
public static NodeList getKeyDefinitions(Element mapElem) { NodeList resultNl = null;/*from ww w. j a va 2s.c o m*/ try { resultNl = (NodeList) allKeyDefs.evaluate(mapElem, XPathConstants.NODESET); } catch (XPathExpressionException e) { throw new RuntimeException("Unexpected exception evaluating XPath expression " + allKeyDefs.toString(), e); } return resultNl; }
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 executeXpathQuery(Node root, String query) throws TransformerException { try {//from ww w .jav a 2 s . com 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 NodeList selectNodeList(Document xmlDocument, String expression) throws XPathExpressionException { return (NodeList) selectObject(xmlDocument, expression, XPathConstants.NODESET); }
From source file:Main.java
public static NodeList getNodesListXpathNode(String Xpath, Node node) throws Exception { return (NodeList) getNodesListXpath(Xpath, node, "", "", XPathConstants.NODESET); }
From source file:Main.java
public static NodeList evaluateToNodeList(Document document, String expression) throws XPathExpressionException { return (NodeList) evaluate(document, expression, XPathConstants.NODESET); }
From source file:Main.java
public static List<Element> SelectElements(Element parent, String expression) { List<Element> nodes = new ArrayList<Element>(); XPath xpath = getXPath();//from w ww . ja v a 2s .c o m try { XPathExpression xpathExpression = xpath.compile(expression); NodeList nodeList = (NodeList) xpathExpression.evaluate(parent, XPathConstants.NODESET); for (int i = 0; i < nodeList.getLength(); i++) { nodes.add((Element) (nodeList.item(i))); } } catch (Exception e) { throw new RuntimeException(e); } return nodes; }
From source file:Main.java
static public List<Element> elements(Node context, String expression) { try {/*from w w w. j a va 2s. com*/ NodeList nodeList = (NodeList) xpath.evaluate(expression, context, XPathConstants.NODESET); List<Element> result = new LinkedList<Element>(); for (int i = 0, len = nodeList.getLength(); i < len; i++) { result.add((Element) nodeList.item(i)); } return result; } catch (XPathExpressionException ex) { ex.printStackTrace(); throw new RuntimeException("invalid xpath expresion used"); } }
From source file:Main.java
public static NodeList extractNodeList(XPath xpath, String nodePath, String xmlString) { InputSource inputSource = new InputSource(new StringReader(xmlString)); try {/*from ww w . j a v a2 s . co m*/ return (NodeList) xpath.evaluate(nodePath, inputSource, XPathConstants.NODESET); } catch (XPathExpressionException e) { return null; } }