Using Java to generate XML

With Java you can generate XML in many ways. One of the ways is to write the XML code using the out.println() statement and generate the XML file you need using the PrintWriter. However this method is very straightforward and there is no guarantee that the generated XML file would be error free.

_______________________________________________


_______________________________________________

Another way is to use the Java API for XML Processing. By using this method you can create a document object and then create the different elements of the XML file using the Element object. The document object has methods for this purpose.

Methods like appendChild() and createTextNode() are used in creating the text nodes and then adding them to the root node of the XML document.

One another way to generate XML from Java is to serialize the Java objects in to XML using the XStream class. With this method you can easily serialized the Java objects to XML. For example if you have a class 'person', you can serialize that with the statement,

String xml = xs.toXML(person);

In the above statement 'xs' is the XStream object. To work with this object you have to import com.thoughtworks.xstream.XStream.



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?

Cisco CCNA Certification Video Tutorial Guide - Learn How to Pass the Cisco CCNA 640-802 Exam... Guaranteed!

Train Signal Computer Training