Sample code on how to read an XML file in java

Classes and methods to read an XML file and to manipulate an XML file is available in java. With these APIs you can do anything with an XML file. To work with an XML file you have to do the following imports.

_______________________________________________


_______________________________________________


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

DocumentBuilderFactory dbfact = DocumentBuilderFactory.newInstance();
DocumentBuilder dbuild = dbfact.newDocumentBuilder();
Document doc = dbuild.parse (new File("xml_file.xml"));
. . .
. . .
doc.getDocumentElement().getNodeName());
NodeList ndlist = doc.getElementsByTagName("ele_name");
. . .
. . .

The above code gives you an idea on how to create a document object to load the XML file you want and then work on it. you have to create objects like DocumentBuilderFactory, DocumentBuilder, and then Document to work on an XML file.

The XML file is loaded in the Document object. A NodeList object is created and then the elements of the XML file are loaded in it. Using a 'for' loop all the elements are displayed. Methods to change and remove the nodes are also available.

Recent Original Stories (OS News)
"One of the things my team has been working to enable has been the ability for .NET developers to download and browse the source code of the .NET Framework libraries, and to easily enable debugging support in them.

Recent Original Stories (New Mobile Computing)
At last week's Guadec meeting, Kristian Rietveld delivered the GTK+ "state of the union" report. GTK+ is the multi-platform toolkit behind a number of popular applications and, perhaps most well known, the Gnome Desktop environment for Linux.



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