Here you can find the source of firstDescendantOfType(Node x, String s)
public static Element firstDescendantOfType(Node x, String s)
//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; } }