List of utility methods to do XPath Get
Node | getNodeByXPath(Document document, String xPath) Inverse function for #getXPath(Node) . Node currentNode = document; String[] nodeNames = xPath.split("/"); for (int i = 1; i < nodeNames.length; i++) { String nodeName = nodeNames[i]; if (nodeName.charAt(0) != '@') { currentNode = currentNode.getFirstChild(); if (nodeName.charAt(nodeName.length() - 1) != ']') { while (currentNode.getNodeType() != Node.ELEMENT_NODE ... |
Node | getNodeByXPath(Object context, String expression) Evaluates an XPath expression and returns a single matching node. return (Node) XPathFactory.newInstance().newXPath().evaluate(expression, context, XPathConstants.NODE);
|
Iterable | getNodeList(Element root, String xpath) get Node List try { NodeList nodeList = XPathAPI.selectNodeList(root, xpath); List<Node> results = new ArrayList<Node>(); for (int i = 0; i < nodeList.getLength(); i++) { results.add(nodeList.item(i)); return results; } catch (TransformerException e) { ... |
NodeList | getNodeList(File xml, String xpathExpression) Gets the node list from the given xml file and the given xpath expression. DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance(); domFactory.setNamespaceAware(true); DocumentBuilder builder = domFactory.newDocumentBuilder(); Document doc = builder.parse(xml); XPath xpath = XPathFactory.newInstance().newXPath(); XPathExpression expr = xpath.compile(xpathExpression); Object result = expr.evaluate(doc, XPathConstants.NODESET); NodeList nodes = (NodeList) result; ... |
NodeList | getNodeList(final String expr, final File xmlFile) Evaluates given XPath expression and returns node list. XPath xPath = XPathFactory.newInstance().newXPath();
NodeList nodeList = (NodeList) xPath.evaluate(expr, parseXMLFile(xmlFile), XPathConstants.NODESET);
return nodeList;
|
NodeList | getNodeList(InputStream stream, String pattern) get Node List return getNodeList(getDocument(stream), pattern);
|
NodeList | getNodeList(Node node, String path) get Node List try { slowGetValue++; XPathFactory xPathFactory = XPathFactory.newInstance(); XPath xpath = xPathFactory.newXPath(); XPathExpression expr; expr = xpath.compile(path); NodeList list = (NodeList) expr.evaluate(node, XPathConstants.NODESET); return list; ... |
NodeList | getNodeList(Node node, String xpath) Get the W3C NodeList instance associated with the XPath selection supplied. if (node == null) { throw new IllegalArgumentException("null 'document' arg in method call."); } else if (xpath == null) { throw new IllegalArgumentException("null 'xpath' arg in method call."); try { XPath xpathEvaluater = xPathFactory.newXPath(); if (xpath.endsWith(ELEMENT_NAME_FUNC)) { ... |
NodeList | getNodeList(Node xmlNode, String xpathString) Return the Element corresponding the the XPath try { XPathExpression expr = createXPathExpression(xpathString); return (NodeList) expr.evaluate(xmlNode, XPathConstants.NODESET); } catch (XPathExpressionException e) { throw new RuntimeException(e); |
NodeList | getNodeList(Reader reader, String expression) get Node List InputSource src = new InputSource(reader); XPathFactory xPathFactory = XPathFactory.newInstance(); xPathFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, false); XPath xPath = xPathFactory.newXPath(); return (NodeList) xPath.evaluate(expression, src, XPathConstants.NODESET); |