/** * Search for a child with the given nodeName. If recursive, search in all * the child of first level, then if not found, search in the 2nd level of * the first child, ... * * @param node * parent node * @param nodeName * node name * @param recursive * boolean to know if we got through the xml tree * @return a node */ public static Node findChild(final Node node, final String nodeName, final boolean recursive) { Node result = null; if ((node != null) && (nodeName != null)) { node.normalize(); NodeList nl = node.getChildNodes(); result = lookupNodeInNodeList(nodeName, nl); // now, search recursively if required if ((result == null) && recursive) { for (int i = 0; (i < nl.getLength()) && (result == null); i++) { result = findChild(nl.item(i), nodeName, true); } } } return result; }
/** * Search for a child with the given nodeName. If recursive, search in all * the child of firdt level, then if not found, search in the 2nd level of * the first child, ... * * @param node * parent node * @param namespaceURI * The namespaceURI of the node * @param nodeName * node name * @param recursive * boolean to know if we got through the xml tree * @return a node */ public static Node findChild(final Node node, final String namespaceURI, final String nodeName, final boolean recursive) { node.normalize(); String prefix = node.lookupPrefix(namespaceURI); return findChild(node, prefix + nodeName, recursive); }