[jdom-interest] JDOM - XStream integration

Laurent Bihanic laurent.bihanic at atosorigin.com
Thu Aug 26 01:16:27 PDT 2004


Hi,

For those interested in Java-XML binding, XStream 
(http://xstream.codehaus.org/) is a very good solution. Unfortunately, it 
doesn't come with native JDOM integration.

For our current project, I've implemented XStream's HierarchicalStreamReader 
and Writer interfaces for JDOM. Using these classes, it is now possible to 
convert Java objects into JDOM documents and vice versa in few lines of code:

// Marshal object to JDOM document
JDOMWriter writer = new JDOMWriter();
xstream.marshal(x, writer);
List result = writer.getResult();

// Unmarshal JDOM document
MyObject obj = (MyObject) xstream.unmarshal(new JDOMReader(doc));

The attached JAR file contains the JDOMWriter and JDOMReader classes for JDOM 
b9. JDOM b10 users need to uncomment the b10-related code in 
JDOMReader.moveUp() (handling of the Parent interface).

Laurent
-------------- next part --------------
A non-text attachment was scrubbed...
Name: jdom-xstream-1.0.jar
Type: application/octet-stream
Size: 5171 bytes
Desc: not available
Url : http://servlets.com/pipermail/jdom-interest/attachments/20040826/36e79caa/jdom-xstream-1.0.obj


More information about the jdom-interest mailing list