Android Utililty Methods XPath Evaluate

List of utility methods to do XPath Evaluate

Description

The list of methods to do XPath Evaluate are organized into topic(s).

Method

BooleanasBoolean(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);
StringevaluateXPath(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,
...
StringevaluateAsString(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();
ElementgetElementByXPath(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));
NodefindXPathNode(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,
...
NodeListfindXPathNodeList(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,
...
NodefindChildNodeWithName(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++) {
...
StringgetXPathItemText(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) {
...
NodeListqueryXmlByXPath(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;
...