Android XML Node Child Get firstDescendantOfType(Node x, String s)

Here you can find the source of firstDescendantOfType(Node x, String s)

Description

first Descendant Of Type

Declaration

public static Element firstDescendantOfType(Node x, String s) 

Method Source Code

//package com.java2s;

import org.w3c.dom.Element;
import org.w3c.dom.Node;

public class Main {
    public static Element firstDescendantOfType(Node x, String s) {
        Node n = firstChildOfType(x, s);
        if (n != null)
            return (Element) n;
        n = (Element) x.getFirstChild();
        Node last = x.getLastChild();
        while (n != null) {
            Element k = firstDescendantOfType((Node) n, s);
            if (k != null)
                return k;
            if (n == last)
                break;
            n = n.getNextSibling();/*from  ww  w  .j a va2 s .  c  o m*/
        }
        return null;
    }

    public static Element firstChildOfType(Node x, String s) {
        if (x != null) {
            Node n = x.getFirstChild();
            Node last = x.getLastChild();
            while (n != null) {
                if (n.getNodeName().equals(s)) {
                    return (Element) n;
                }
                if (n == last)
                    break; // DSM handle possible bug in getNextSibling()
                n = n.getNextSibling();
            }
        }
        return null;
    }
}

Related

  1. getFirstMatchingChildNode(Node node, String nodeName, String attributeName, List attributeValues)
  2. children(Node x)
  3. childrenOfType(Node x, String s)
  4. firstChildOfType(Node x, String s)
  5. getMatchingChildNodes(Node node, String nodeName, String attributeName, List attributeValues)
  6. firstValueOfType(Node x, String s)
  7. getSet(Node rootNode, Set result, Node exclude, boolean com)
  8. getSetRec(final Node rootNode, final Set result, final Node exclude, final boolean com)