Solved

reading values from xml

Posted on 2013-01-24
3
280 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 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
fibonacci ten numbers 4 54
servlet example 17 58
runtime exception 2 50
ejb stateless example 2 40
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
In this post we will learn different types of Android Layout and some basics of an Android App.
The viewer will learn how to implement Singleton Design Pattern in Java.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

679 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