• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

someone pleasssseeee help !!!

 
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is my XML file
--------------------------------------------------
<ADDRESSBOOK>
<RECORD id="1">
<NAME>
<FIRSTNAME>SAMITH</FIRSTNAME>
<LASTNAME>NAMBIAR</LASTNAME>
</NAME>
<ADDRESS>CHEMBUR,MUMBAI</ADDRESS>
<PHONE>5225129</PHONE>
</RECORD>

<RECORD id="2">
<NAME>
<FIRSTNAME>DEEPAK</FIRSTNAME>
<LASTNAME>CHANDRASHEKAR</LASTNAME>
</NAME>
<ADDRESS>DADAR,MUMBAI</ADDRESS>
<PHONE>5288840</PHONE>
</RECORD>
<ADDRESSBOOK>

--------------------------------------------------
This is a snippet from the java file :
NodeList list = rootNode.getChildNodes();
for(int i=0;i<list.getLength();i++)
{
System.out.println(list.item(i).getNodeName());
}
----------------------------------------------------
the problem is with the output :
ADDRESSBOOK
ADDRESSBOOK
----------------------------------------------------
what i dont understand is how does the rootNode have two childNodes as ADDRESSBOOK .... whereas from the xml file it seems to me that there is ony one childNode as ADDRESSBOOK which has two childNodes as RECORD ???
--------------------------------------------------
i'm new to JAXP/XML and any sort of help would be very much appreciated
Thanx in advance
Samith.P.Nambiar
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
I think problem is in your for loop condition,
just check it, u dont get it
naren.
 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I too think there is something wrong with your code( the part that is not pasted here.)
When I tried just that snippet, I get the output -
ADDRESSBOOK
which is what I expect since it is the root.
If you want to iterate through the "RECORD" elements, you should use
NodeList list = doc.getDocumentElement().getChildNodes();
Cheers!

------------------
Ajith Kallambella M.
Sun Certified Programmer for the Java�2 Platform.
IBM Certified Developer - XML and Related Technologies, V1.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!