Android XPath Evaluate getXPathItemText(Document doc, XPath xpath, String query)

Here you can find the source of getXPathItemText(Document doc, XPath xpath, String query)

Description

get X Path Item Text

License

Apache License

Declaration

public static String getXPathItemText(Document doc, XPath xpath,
            String query) throws XPathExpressionException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
import org.w3c.dom.Document;
import org.w3c.dom.Node;

public class Main {
    public static String getXPathItemText(Document doc, XPath xpath,
            String query) throws XPathExpressionException {
        if (doc == null || xpath == null || query == null) {
            return null;
        }//w  w  w .j a v a 2  s  .co  m

        Node node = (Node) xpath.evaluate(query, doc, XPathConstants.NODE);
        String text = null;

        if (node != null) {
            text = node.getNodeValue();
            if (text != null) {
                text = text.trim();
            }
        }

        return text;
    }
}

Related

  1. evaluateAsString(String expression, Node node)
  2. getElementByXPath(Element e, String xPathExpression)
  3. findXPathNode(Node node, String xPath)
  4. findXPathNodeList(Node node, String xPath)
  5. findChildNodeWithName(Node node, String childName)
  6. queryXmlByXPath(Document xmlDocument, String xpathExpressionString)