Solved

reading values from xml

Posted on 2013-01-24
3
281 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 27

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
iterator/ListIterator approach 17 68
throw exception 21 78
Why doesn't this text field show up on my Applet frame? 2 43
Java program running SQL query 5 63
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
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…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

734 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