private static List<Element> find(Node root, String nsUri, String localName, boolean recursive) {
        List<Element> result = new ArrayList<Element>();
        NodeList nl = root.getChildNodes();
        if (nl != null) {
            int len = nl.getLength();
            for (int i = 0; i < len; i++) {
                Node child = nl.item(i);
                if (child instanceof Element) {
                    String childUri = child.getNamespaceURI();
                    String childLocalName = child.getLocalName();
                    if (("*".equals(nsUri) || nsUri == null && childUri == null || nsUri.equals(childUri)) 
                            && localName.equals(childLocalName)) {
                        result.add((Element) child);
                    } else if (recursive) {
                        result.addAll(find(child, nsUri, localName, recursive));
                    }
                }
            }
        }
        return result;
    }