Java tutorial
//package com.java2s; //License from project: BSD License import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { public static int getCountOfChildNodes(Node node, String nodeName) { int count = 0; if (node.getNodeType() == Node.ELEMENT_NODE) { NodeList nodeList = node.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { Node n = nodeList.item(i); if (n.getNodeName().equals(nodeName)) { count++; } } } return count; } }