Using java to write XML documents

The basis to work with an XML document or to create an XML document from the scratch is to have a document object in place. So, your first task should be to create a document object using the classes and methods available for that purpose in Java.


_______________________________________________

Creating a document object involves three steps. The first is to create a DocumentBuilderFactory object. The second is to create a DocumentBuilder object with that DocumentBuilderFactory object. Now in the third step you can create the Document object using the Document Builder object. A typical code should be,

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

You can use the getDocumentElement() method to get the root node and then you can use the appendChild() method to append the elements created, to the root node. To create the text nodes, you can use the method createTextNode() of the document object.

Manipulating the existing XML document is also possible and there are methods to traverse the nodes and to change them or to remove them. You can also traverse the nodes and then create attributes.




_______________________________________________

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.