This week's book giveaway is in the Agile forum.
We're giving away four copies of Head First Agile and have Andrew Stellman & Jennifer Greene on-line!
See this thread for details.
Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

problem in getting child node  RSS feed

 
sandy comp
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using jdk1.4 and inbuild xml parser. Folowing is code snippet for reference.

InputStream is = new FileInputStream(new File("conf/property.xml"));
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document xmldoc = db.parse(is);
Element elem = xmldoc.getDocumentElement();
NodeList nodeList = elem.getChildNodes(); // root node
for(int i=0; i<nodeList.getLength(); i++) {
if(nodeList.item(i).getNodeType() == 1) {
// problem statement, here I'm not able to get all the child nodes
Element childelem = (Element)nodeList.item(i);
}
}

do you ahve any idea why I am missing the child nodes?
 
Amit Jaipaul
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sandy,

Please use the following for gettting the child nodes

instead of

as Element is used only for getting the Root.
 
sandy comp
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Amint,thank you very much..
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!