Android Utililty Methods XML Node Search

List of utility methods to do XML Node Search

Description

The list of methods to do XML Node Search are organized into topic(s).

Method

NodefindNamedElementNode(Node doc, String name)
find Named Element Node
Node[] elnodes = getChildNodes(doc, Node.ELEMENT_NODE);
int i;
for (i = 0; i < elnodes.length; ++i) {
    if (elnodes[i].getNodeName().equals(name))
        return elnodes[i];
return null;
ListfindNamedElementNodes(Node doc, String name)
find Named Element Nodes
Node[] elnodes = getChildNodes(doc, Node.ELEMENT_NODE);
List<Node> nodes = new ArrayList<Node>();
int i;
for (i = 0; i < elnodes.length; ++i) {
    if (elnodes[i].getNodeName().equals(name)) {
        nodes.add(elnodes[i]);
return nodes;
ElementfindNextElement(Node ret, String name)
find Next Element
ret = ret.getNextSibling();
while (ret != null
        && (!(ret instanceof Element) || !ret.getNodeName().equals(
                name))) {
    ret = ret.getNextSibling();
return (Element) ret;
StringgetOptionalXmlString(Node node, String xmlLocalName)
Retrieves the value of that XML element as a string.
Node child = getFirstChild(node, xmlLocalName);
return child == null ? null : child.getTextContent(); 
StringreturnNodeValue(Node node)
Returns the value of an XML node.
String text = node.getFirstChild().getTextContent();
text = text.replaceAll("\\\\n", "\n");
return text;
ElementselectNode(Node sibling, String uri, String nodeName, int number)
select Node
while (sibling != null) {
    if (sibling.getNamespaceURI() != null
            && sibling.getNamespaceURI().equals(uri)
            && sibling.getLocalName().equals(nodeName)) {
        if (number == 0) {
            return (Element) sibling;
        number--;
...
TextselectNodeText(Node sibling, String uri, String nodeName, int number)
select Node Text
Node n = selectNode(sibling, uri, nodeName, number);
if (n == null) {
    return null;
n = n.getFirstChild();
while (n != null && n.getNodeType() != Node.TEXT_NODE) {
    n = n.getNextSibling();
return (Text) n;
Element[]selectNodes(Node sibling, String uri, String nodeName)
select Nodes
List<Element> list = new ArrayList<Element>();
while (sibling != null) {
    if (sibling.getNamespaceURI() != null
            && sibling.getNamespaceURI().equals(uri)
            && sibling.getLocalName().equals(nodeName)) {
        list.add((Element) sibling);
    sibling = sibling.getNextSibling();
...