Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

reading values from xml

Posted on 2013-01-24
3
Medium Priority
?
283 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 36

Assisted Solution

by:mccarl
mccarl earned 400 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 1200 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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

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…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Suggested Courses

715 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