List of utility methods to do XPath Evaluate
Boolean | asBoolean(String expression, Node node) Evaluates the specified XPath expression and returns the result as a Boolean. String booleanString = evaluateAsString(expression, node);
return (isEmptyString(booleanString)) ? null : Boolean
.valueOf(booleanString);
|
String | evaluateXPath(Node node, String xPath) evaluate X Path int currentSearchIndex = 0; while (currentSearchIndex < xPath.length()) { int endingIndex = xPath.indexOf("/", currentSearchIndex); String noderNameFromXPath = null; if (endingIndex == -1) { noderNameFromXPath = xPath.substring(currentSearchIndex); } else { noderNameFromXPath = xPath.substring(currentSearchIndex, ... |
String | evaluateAsString(String expression, Node node) Evaluates the specified expression on the specified node and returns the result as a String. if (isEmpty(node)) return null; String s = evaluateXPath(node, expression); if (s == null) { return null; } else { return s.trim(); |
Element | getElementByXPath(Element e, String xPathExpression) get Element By X Path XPathFactory factory = XPathFactory.newInstance();
XPath xPath = factory.newXPath();
return (Element) (xPath.evaluate(xPathExpression, e,
XPathConstants.NODE));
|
Node | findXPathNode(Node node, String xPath) find X Path Node int currentSearchIndex = 0; while (currentSearchIndex < xPath.length()) { int endingIndex = xPath.indexOf("/", currentSearchIndex); String noderNameFromXPath = null; if (endingIndex == -1) { noderNameFromXPath = xPath.substring(currentSearchIndex); } else { noderNameFromXPath = xPath.substring(currentSearchIndex, ... |
NodeList | findXPathNodeList(Node node, String xPath) find X Path Node List int currentSearchIndex = 0; while (currentSearchIndex < xPath.length()) { int endingIndex = xPath.indexOf("/", currentSearchIndex); String noderNameFromXPath = null; if (endingIndex == -1) { noderNameFromXPath = xPath.substring(currentSearchIndex); } else { noderNameFromXPath = xPath.substring(currentSearchIndex, ... |
Node | findChildNodeWithName(Node node, String childName) find Child Node With Name if (node == null) { return null; } else { if (node.getNodeName().equals(childName)) { return node; } else { NodeList nodeList = node.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { ... |
String | getXPathItemText(Document doc, XPath xpath, String query) get X Path Item Text if (doc == null || xpath == null || query == null) { return null; Node node = (Node) xpath.evaluate(query, doc, XPathConstants.NODE); String text = null; if (node != null) { text = node.getNodeValue(); if (text != null) { ... |
NodeList | queryXmlByXPath(Document xmlDocument, String xpathExpressionString) query Xml By X Path try { XPathFactory xpathFactory = XPathFactory.newInstance(); XPath xpath = xpathFactory.newXPath(); XPathExpression xpathExpression = xpath .compile(xpathExpressionString); Object result = xpathExpression.evaluate(xmlDocument, XPathConstants.NODESET); return (NodeList) result; ... |