Code samples on parsing XML files in Java

Parsing XML file using Java is easy if you are using the Java API for XML (JAXP) processing. You can download the JAXP from the Sun Microsystems website. You can also find the specifications of JAXP in the same website.


_______________________________________________


A sample line of code that would parse the XML fine into a document object is given below.

Document doc = dbuild.parse(new File("xmlfile.xml"));

In the above line 'doc' is the document object that is used to load the XML document that you want to work with. 'dbuild' is the DocumentBuilder object. Before you create a 'doc' object you need to create a DocumentBuilderFactory and then a DocumentBuilder.

Once the XML document is loaded into the document object, you can use the methods available to manipulate the elements of the XML document. For example to get all the elements of a particular tag name you would using the method getElementsByTagName() method of the document object.

Similarly methods to change and remove elements and to create attributes are also available. You can find lots of code samples for XML processing the Sun Microsystems website.




_______________________________________________

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.

_______________________________________







 

 

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!

Visit XML Training Material Guide Homepage

 

 

Copyright - © 2004 - 2017 - All Rights Reserved.