Creating
a Java program to read an XML file is very simple if you know the logic
behind it. There are appropriate classes and methods available to do
this task. But you should be clear in what you do.
_______________________________________________
_______________________________________________
The
logic goes like this. First you have to create a document object and
load the XML document you want to read into it. The next step is to
get all the nodes that you want to work with by tag name. In this step
you will get a list of nodes. You have to loop through these nodes to
print it out or whatever you want.
To create
a document object, you need to first create a DocumentBuilderFactory
and from this you can create a DocumentBuilder object. This DocumentBuilder
object can be used to create the Document object you need to load the
XML file.
Once you
have the document object loaded with the XML file you need, then you
can use the method getElementByTagName() method to get a NodeList object.
Get the length of the NodeList and then loop through the list to print
them out or work with it anyway you want.
Current Newswire: (Linux Today)
"It would not be an exaggeration to say that yesterday was a very bad day for VMWare.
posted by Will Senn on Wed 30th Nov 2005 19:03 UTC (OS News)
This latest installment in the Core series from Prentice Hall PTR is a welcome arrival to the PHP/MySQL space. It is jam packed with useful information. At a little over 850 pages, this volume contains information on nearly every topic of interest in both the PHP and MySQL subject areas.