Posted By:
krishnakanth_Rengarajan
Posted On:
Wednesday, November 26, 2003 02:05 AM
It works for me,Follows my Xml and java file.
dep.xml
classdep
c:/Documents and Settings/lad/bci/Depend/temp/classdep/com/jpl/
treewalk
c:/Documents and Settings/lad/bci/Depend/temp/classdep/com/jpl/
XMLTest.javaimport javax.xml.parsers.*;
import org.w3c.dom.*;
import java.io.*;
public class XMLTest
{
public static void main(String str[])
{
try
{
DocumentBuilderFactory dbfBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = dbfBuilderFactory.newDocumentBuilder();
Document doc = docBuilder.parse (new File("C:\eclipse\workspace\classdep\dep.xml"));
Element root = doc.createElement("root");
doc.appendChild(root);
doc.getDocumentElement().normalize();
NodeList listOfTablas = doc.getElementsByTagName("tablas");
int totalTablas = listOfTablas.getLength();
System.out.println("Total de tablas : " + totalTablas);
}catch(Exception e)
{
System.out.println("Error");
}
}
}
I works fine and gives me the following output:
Total de tablas : 2