/ Published in: Java
Get the all nodes list which's element tag name specified from a document.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/** * Get Nodes by element tag name from a Document * * @param parent - the document root element * @param tagname - the tag name * @param - list store the Elements * @throws IllegalArgumentException */ public void getNodesByTagName(Element parent, String name, List<Element> nodesList) throws IllegalArgumentException { if (parent == null) { } NodeList children = parent.getChildNodes(); Node node = null; for (int i = 0; i < children.getLength(); i++) { node = children.item(i); if (node.getNodeType() == Node.ELEMENT_NODE && node.getNodeName().equals(name) { } if (node.hasChildNodes()) { } }