List of utility methods to do XPath Evaluate
Node | evaluateXPathExpressionAndReturnNode(String expression, Node node) Evaluates a XPath expression from a XML node, returning a Node object try { return (Node) xPath.get().evaluate(expression, node, XPathConstants.NODE); } catch (XPathExpressionException e) { return null; |
NodeList | evaluateXPathExpressionAndReturnNodeList(String expression, Node node) Evaluates a XPath expression from a XML node, returning a NodeList. try { return (NodeList) getXPath().get().evaluate(expression, node, XPathConstants.NODESET); } catch (XPathExpressionException e) { return null; |
NodeList | evaluateXPathQuery(Document doc, NamespaceContext context, String xPathQuery) evaluate X Path Query XPathExpression expr = createXPathExpression(context, xPathQuery);
return (NodeList) expr.evaluate(doc, XPathConstants.NODESET);
|
Object | evalXPath(Node d, String expr, QName returnType) Gets the object at the given XPath in the given XML node. return XPathFactory.newInstance().newXPath().compile(expr).evaluate(d, returnType);
|
List | evalXPath(Node node, String xPath) eval X Path synchronized (xpath) { try { NodeList nodes = (NodeList) xpath.evaluate(xPath, node, XPathConstants.NODESET); int size = nodes.getLength(); ArrayList<Node> list = new ArrayList<Node>(size); for (int i = 0; i < size; i++) list.add(nodes.item(i)); return list; ... |
T | evalXPath(String expression, Object item, Class Evaluates an XPath returning null if not found. Object val; if (type == String.class) val = evalXPath(expression, item, XPathConstants.STRING); else if (type == CharSequence.class) val = evalXPath(expression, item, XPathConstants.STRING); else if (type == Boolean.class) val = evalXPath(expression, item, XPathConstants.BOOLEAN); else if (type == Boolean.TYPE) ... |
String | evalXPath(String path, Document doc) eval X Path XPath xpath = newXPath(); try { return xpath.evaluate(path, doc); } catch (XPathExpressionException e) { throw new RuntimeException(e); |
NodeList | evalXpath(String xpath, Object item) eval Xpath XPath xp = XPathFactory.newInstance().newXPath();
XPathExpression expr = xp.compile(xpath);
return (NodeList) expr.evaluate(item, XPathConstants.NODESET);
|
String | evalXPathAsString(Object item, String xpath, XPathFactory factory) eval X Path As String XPath path = factory.newXPath();
XPathExpression expr = path.compile(xpath);
return (String) expr.evaluate(item, XPathConstants.STRING);
|
List | evalXPathAsStringList(Object item, String xpath, XPathFactory factory, boolean includeDuplicates) eval X Path As String List NodeList nl = evalXPathAsNodeList(item, xpath, factory); List<String> result = new ArrayList<String>(nl.getLength()); for (int i = 0; i < nl.getLength(); i++) { String text = nl.item(i).getTextContent(); if (includeDuplicates || !result.contains(text)) { result.add(text); return result; |