Creating a simple Java XML DOM

Creating a simple Java XML Document Object Model is very easy if you use the appropriate imports and use the appropriate classes and methods. The following import statements are to be used to use the appropriate classes and methods to work with the XML document.


_______________________________________________

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

Creating a document object that can load the XML document involves three steps, and the following code will give you an idea on how to create such a document object.

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse (new File("ur_xml_file.xml"));

Once you have created the document object, there are methods available in the document object to work with the XML document. The method getDocumentElement().getNodeName() can be used to get the root element name of the XML document that is loaded in the document object.

The getElementsByTagName() method can be used to get all the names of the elements that is specified as an string argument to that method.Lots of complete code samples are available in the internet that uses these methods to work with the XML document.




_______________________________________________

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.