/** * get Elements with the same localName as the input localName under the rootNode,it is a * recursive computation. * * @param rootNode * @param localName * @param caseSensitive * @param list The input list to hold the matched elements. */ public static void getElementByLocalName( Node rootNode, String localName, boolean caseSensitive, List list) { if (list == null) { return; } NodeList nodeList = rootNode.getChildNodes(); if (nodeList != null && nodeList.getLength() > 0) { for (int i = 0, size = nodeList.getLength(); i < size; i++) { Node node = nodeList.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { String nodeLocalName = node.getLocalName(); if (caseSensitive && localName.equals(nodeLocalName)) { list.add(node); } else if (!caseSensitive && localName.equalsIgnoreCase(nodeLocalName)) { list.add(node); } getElementByLocalName(node, localName, true, list); } } } }