The list of methods to do XPath Select are organized into topic(s).
String
getValueFromXPath(Document document, String xpathString) Returns the string value of evaluated xpath
try {
return (String) XPathFactory.newInstance().newXPath().evaluate(xpathString, document,
XPathConstants.STRING);
} catch (XPathExpressionException e) {
throw new RuntimeException("Error evaluating xpath [" + xpathString + "] -- " + e.getMessage());
List
getXmlElements(Document inXml, String xpath)
get Xml Elements
try {
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) {
...
ArrayList
selectElements(Element element, String xpathExpression)
select Elements
ArrayList<Element> resultVector = new ArrayList<Element>();
if (element == null) {
return resultVector;
if (xpathExpression.indexOf("/") == -1) {
NodeList nodeList = element.getChildNodes();
for (int i = 0; i < nodeList.getLength(); i++) {
Node node = nodeList.item(i);
...
NodeIterator
selectNodeIterator(Node nContextNode, String sXPath) Use an XPath string to select a nodelist.
try {
return (NodeIterator) s_mSelectNodeIterator.invoke(null, new Object[] { nContextNode, sXPath });
} catch (Exception e) {
throw new TransformerException(e);
NodeList
selectNodeList(Node node, String expression) select Node List
XPathFactory factory = XPathFactory.newInstance();
XPath path = factory.newXPath();
Object result = path.evaluate(expression, node, XPathConstants.NODESET);
return (NodeList) result;
NodeList
selectNodes(Node nodeParent, String name) select Nodes
try {
XPath xpath = XPathFactory.newInstance().newXPath();
return (NodeList) xpath.evaluate(name, nodeParent, XPathConstants.NODESET);
} catch (Exception e) {
return null;