try the following code:
Document doc = db.parse (new File("c:\\exp\\item.xml"));
NodeList nl =doc.getElementsByTagName("category");
System.out.println(" no of nodes for root = "+ nl.getLength());
for(int i =0 ;i<nl.getLength();i++){
Node n = nl.item(i);
System.out.print(n.getNodeName());
NodeList nll=n.getChildNodes();
for(int ii =0 ;ii<nll.getLength();ii++){
Node nn = nll.item(ii);
System.out.println("==>"+nn.getNodeValue());
}
}
others please optimise the code.