An example for reading XML with Java

Reading XML with java can be done easily if you are using the Java API for XML Processing. You can download this API and if you want the specifications too from the Sun Microsystems website.

_______________________________________________


_______________________________________________

Once you have the Java API in place, it is needed to have the proper imports in your program. Typical imports statements might have,

import org.w3c.dom.Document;
import org.w3c.dom.DOMException;
import org.w3c.dom.Element;

The next step is to create a document object to load the XML file that should be read. If you have loaded the XML object then it is easy to traverse the nodes of the XML document and access all the nodes of the XML document. Creating a document object involves three steps as given in the code below.

DocumentBuilderFactory fact = DocumentBuilderFactory.newInstance();
DocumentBuilder db = fact.newDocumentBuilder();
doc = db.newDocument();

once the document object is loaded with the XML document you can use the methods like getDocumentElement().getNodeName() to get the root node of the XML document and use getElementsByTagName() to get all the elements of a particular name and then loop through them to display them.

Methods to change the attributes, create attributes, change nodes, and to remove nodes are also available.

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.

Linked by Thom Holwerda on Thu 6th Oct 2005 11:05 UTC (New Mobile Computing)
The Servlet-Based Content Creation Framework is an easy-used and easily-understood compact, content creation framework utilizing hamlets; a servlet extension that reads XHTML and uses the simple API for XML. Read this article on introducing Hamlets and learn how they can be used to separate Java and HTML in the same source file.

Linked by Thom Holwerda on Wed 21st Jun 2006 22:08 UTC, submitted by anonymous (OS News)
"This list is compiled from a variety of sources and is intended for anyone who wishes to find centralized reading material about Eclipse . One of the biggest challenges new Eclipse users face is where to find the right information for a task.




FREE Subscription

Subscribe to our mailing list and receive new articles
through email. Keep yourself updated with latest
developments in the industry.

Name:
Email:

Note : We never rent, trade, or sell my email lists to
anyone. We assure that your privacy is respected
and protected.

_______________________________________

Recommended XML Books

cover
cover
cover
cover
cover
cover







 

 

FREE Subscription

Stay Current With the Latest Technology Developments Realted to XML. Signup for Our Newsletter and Receive New Articles Through Email.

Name:

Email:

Note : We never rent, trade, or sell our email lists to anyone. We assure that your privacy is respected and protected.

 

 

Add to My Yahoo!


New XML Books Titles - Best Seller's @ Amazon.com

Visit XML Training Material Guide Homepage

Technology helps engage students - how do classroom instruction and social dynamics change when the classroom is completely dependant on modern technology?

Dallas Web Design- local Dallas web design firm offers site design and backend system development