How do I write a JavaBean to an XML file using JOX?
Author: Deron Eriksson
Description: This Java tutorial describes how to write a JavaBean to an XML file using JOX (Java Objects in XML).
Tutorial created using: Windows XP || JDK 1.5.0_09 || Eclipse Web Tools Platform 1.5.1

Page: < 1 2

(Continued from page 1)

When we execute our JoxWriteJavaBeanToFile class and refresh our project, we can see that the jox-test.xml file appears at the root level of our project folder.

Generation of jox-test.xml file

The generated jox-test.xml file contains the bean data in a very readable form.


<?xml version="1.0" encoding="ISO-8859-1"?>
<testString>test bean says hi</testString>

A great thing about this is that the contents of the bean have been 'serialized' into an xmlW form that is very readable. Of course, given your requirements, this may be a bad thing, but in general this is a very good thing. If you've ever stored serialized JavaSW objects in a file system or a databaseW (using the normal Java serializationW mechanisms), you may have run into complexities trying to determine what was in the serialized objects (ie, you need to deserialize them to read them). The great thing about having the objects stored as XML in this fashion is that you can view and edit your data within your objects in the XML form with no deserialization required. Awesome!

Page: < 1 2