通过标签名获得节点getNodesByTagName,,/** * Get N
分享于 点击 19888 次 点评:207
通过标签名获得节点getNodesByTagName,,/** * Get N
/** * 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) { throw new IllegalArgumentException("The input node can not be 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) { nodeList.add((Element) node); } if (node.hasChildNodes()) { getNodesByTagName((Element) node, name, nodesList); }}
用户点评