List of utility methods to do XPath Get
String | getValue(final String expression, final String xml) Evaluates the XPath expression against the xml and returns the selected value.
final InputSource source = new InputSource(new StringReader(xml)); final XPathFactory factory = XPathFactory.newInstance(); final XPath xpath = factory.newXPath(); return xpath.evaluate(expression, source); |
String | getValueByPath(Node node, String path) get Value By Path XPathExpression expr = compile(path); try { return expr.evaluate(node); } catch (Exception e) { throw new RuntimeException(e); |
String | getValueByXpath(Node doc, String xquery) get Value By Xpath try { XPathFactory factory = XPathFactory.newInstance(); XPath xpath = factory.newXPath(); XPathExpression expression = xpath.compile(xquery); String result = (String) expression.evaluate(doc, XPathConstants.STRING); return result; } catch (Exception e) { return null; |
String | getValueFromXML(final String inputXML, final String xPathQuery, final int index) get Value From XML return getValueFromXML(inputXML, xPathQuery, index, null);
|
List | getValues(final String expression, final String xml) Evaluates the XPath expression against the xml and returns the selected values.
final NodeList xpathResults = getNodes(expression, xml); final List<String> results = new ArrayList<String>(xpathResults.getLength()); for (int i = 0; i < xpathResults.getLength(); i++) { results.add(xpathResults.item(i).getNodeValue()); return results; |
XPath | getX_PATH() get PATH if (X_PATH == null) { X_PATH = XPathFactory.newInstance().newXPath(); return X_PATH; |
Node | xGetNode(Node targetNode, String expression) Uses the passed XPath expression to locate a single node in the passed element. Node node = null; XPath xpath = null; try { xpath = XPathFactory.newInstance().newXPath(); XPathExpression xpathExpression = xpath.compile(expression); node = (Node) xpathExpression.evaluate(targetNode, NODE); return node; } catch (Exception e) { ... |