Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Printing the results to console (xml elements, attributes, nodes..)

 
Edward Bloom
Ranch Hand
Posts: 34
Eclipse IDE Fedora Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy!
There is an xml file.



I trying write some code with the DOM parser. I can getElementsByTagName and something.. but i am so new in Java, and i do not know how can i get the Attributes (i know the getAttributes() method, but how can i use, and where?)..
Well i would like to ask any help with somebody who has a little time, and who could show me how I could to print the results to console like this:

www.lib.org/books
BookID: 1097# Tittle: IMAGINE# Written by: Jonah Lehrer# ISBN: 1413494-413-54# Price: 37 (USD)# Publisher ID: K641#
BookID: 1010# Tittle: PRAGUE WINTER# Written by: Madeleine Albright, Bill Woodward# ISBN: 1156521-568-87# Price: 55 (EUR)# Publisher ID: K354#
BookID: 1063# Tittle: THE INNOCENT# Written by: David Baldacci# ISBN: 1052071-518-27# Price: 23 (GPB)# Publisher ID: K211#

Does someone have little time for it?
Thank you in advance for any help you can provide.
 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. Create a bean class with setters and getters to store each book information like below.


2. Get all the information under each <book> node and populate the Book bean with its values. Add all the populated Book beans in a List<Book>

3. Iterate every Book in List<Book> and print its information.

To get attribute values you can convert the Node into an Element and use its getAttribute() method.

Sample -
 
Edward Bloom
Ranch Hand
Posts: 34
Eclipse IDE Fedora Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear John!
Unfortunately i have to do another things, therefore i cannot write any row in this theme. When i'll have time for it again (i hope as soon as possible), i Will be trying write a code with your logic.
Thanks for your patience.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic