Solved

reading values from xml

Posted on 2013-01-24
3
276 Views
Last Modified: 2013-01-25
hi guys
I am reading  values from xml using

  DocumentBuilder db = dbf.newDocumentBuilder();
 Document document = db.parse(new File("customerPlaceholder.xml"));
NodeList nodeList = document.getElementsByTagName("Item");
  for(int x=0,size= nodeList.getLength(); x<size; x++) {
       System.out.println(nodeList.item(x).getAttributes().getNamedItem("name").getNodeValue());
 }

customerPlaceholder.xml has some information but nodeList.getLength(); is zero
any idea where i am doing wrong?

thanks
0
Comment
Question by:royjayd
3 Comments
 
LVL 35

Assisted Solution

by:mccarl
mccarl earned 100 total points
ID: 38816771
Can you post the XML that you are trying to read? It's a bit hard to help in any way unless we have this.
0
 

Author Comment

by:royjayd
ID: 38817140
the xml is like

<?xml version="1.0"?>
<custmomer>
   <id> bk101 </id>
      <name>James, Matthew</name>
      <title>Production</title>
      <genre>Computer</genre>
      <price>44.95</price>
 </custmomer>

I want to read the values of id and name , genre and price.

thanks
0
 
LVL 26

Accepted Solution

by:
mrcoffee365 earned 300 total points
ID: 38817461
You see where your code is getting all the tags named "Item":
document.getElementsByTagName("Item");

Your xml file does not have any tags named "Item".  Presumably you mean to put "custmomer" as the name of the tag.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now