Java examples for XML:XML Node Child
get Child XML Nodes by tag name
//package com.java2s; import java.util.ArrayList; import java.util.List; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.w3c.dom.Text; public class Main { public static Node[] getChildNodes(Node parent, String tagName) { List<Node> nodeList = new ArrayList<Node>(); NodeList ndList = parent.getChildNodes(); int length = ndList.getLength(); for (int i = 0; i < length; i++) { Node n = ndList.item(i); if (n instanceof Text) continue; if (n.getNodeName().equals(tagName)) nodeList.add(n);/* ww w . j a v a 2 s .com*/ } return nodeList.toArray(new Node[0]); } }