Solved

reading values from xml

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Java JRE greater than 1.6 5 62
servlet requestdispatcher include and forward differences 1 30
egit plugin on eclipse 8 63
javap not working 8 45
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
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…
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 theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

773 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