[jdom-interest] Convert XML data to Java ojbects

Guy Nirpaz guyn at tantian.com
Tue Sep 5 01:09:20 PDT 2000


Hi all,

I wrote a simple utility that helps you convert XML data to instantiated
Java objects and vice-versa.
It uses a simple naming convention schema that can be overridden by a
configuration file.

In order to convert an XML file to a Java object you use something similar
to :
<code>
  XMLConversionRule rule = new DefaultXMLConversionRule ( new File
 "person_in.xml" ) ) ;
  XMLConvertor converter = new XMLConvertor () ;
  Object obj = converter.convert( doc.getRootElement() , rule ) ;
</code>

And for the opposite direction you use :
<code>
  ObjectConvertor converter = new ObjectConvertor () ;
  ObjectConversionRule rule = new DefaultObjectConversionRule ( new File
 "person_out.xml" ) ) ;
  Element root = converter.convert( person , rule );
</code>

I'm not sure if I should enclose a jar file to the entire list.
So if someone is interested, I'll be happy to contribute the code.

Hope you'll find it useful

Guy Nirpaz
Java Architect

Tantian Corp.
guyn at tantian.com




More information about the jdom-interest mailing list