GeeCON Prague 2014*
The moose likes XML and Related Technologies and the fly likes Printing the results to console (xml elements, attributes, nodes..) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Printing the results to console (xml elements, attributes, nodes..)" Watch "Printing the results to console (xml elements, attributes, nodes..)" New topic
Author

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

Edward Bloom
Greenhorn

Joined: Apr 10, 2012
Posts: 29

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
Bartender

Joined: May 31, 2011
Posts: 1776
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
Greenhorn

Joined: Apr 10, 2012
Posts: 29

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.
 
GeeCON Prague 2014
 
subject: Printing the results to console (xml elements, attributes, nodes..)