atom feed9 messages in org.codehaus.xstream.userRE: [xstream-user] Dom4j example
FromSent OnAttachments
Raymond AugeOct 3, 2006 11:21 am 
Raymond AugeOct 3, 2006 11:46 am 
Jörg SchaibleOct 4, 2006 6:46 am 
Raymond AugeOct 4, 2006 7:45 am 
Jörg SchaibleOct 4, 2006 4:58 pm 
Raymond AugeOct 5, 2006 6:16 am 
Jörg SchaibleOct 5, 2006 9:51 am 
Raymond AugeOct 5, 2006 11:40 am 
Jörg SchaibleOct 6, 2006 12:35 pm 
Subject:RE: [xstream-user] Dom4j example
From:Raymond Auge (
Date:Oct 4, 2006 7:45:21 am

Hello Jörg,

about 3/4 of the way down you'll see:

org.dom4j.Document document = // an existing doc xstream.marshal(myObject), new Dom4JWriter(document)); // serialize Object newObject = xstream.unmarshal(new Dom4JReader(document)); // deserialize

This isn't how it actually works.

But, it would be really very nice if we could do this.

It would also be nice if I could grab an dom4j.Element and pass it as the input to xstream, or get the output of xstream as an Element which I can copy and append as a child element of an existing tree.

I'm currently building an archiving framework for an open source portal. When we are archiving the data, we are storing all kinds of data into an xml file, the xstream serialization is a perfect way to store many of the objects in a portable format. We compress the entire result of course.

I'm currently doing something like, getting the List of hundreds, potentially thousands of entries from Hibernate and simply passing the complete List to xstream. I then append the whole output to the already initialized xml archive under a new Element.

List articlesList = dao.getAllArticles(); XStream xstream = new XStream(new Dom4JDriver()); Element articles = root.addElement("articles").addAttribute(...)... SAXReader reader = SAXReaderFactory.getInstance(); Document holderDoc = StringReader(xstream.toXML())); articles.content().add(holderDoc.getRootElement().createCopy());

That's only six lines of code, the import side is also only slightly more than 6 lines long.

If I could do what is described in the snippet above, that would avoid the SAXReader/String processing level and would make me feel a lot more comfortable, plus it would be very cool to go direct.


On Wed, 2006-10-04 at 15:46 +0200, Jörg Schaible wrote:

Hi Raymond,

Raymond Auge wrote on Tuesday, October 03, 2006 8:46 PM:

Right now I have...

XStream xstream = new XStream(new Dom4JDriver()); xstream.alias("structures", List.class); String xml = xstream.toXML(structuresList);

SAXReader reader = SAXReaderFactory.getInstance(); Document structureDoc = StringReader(xml)); root.content().add(structureDoc.getRootElement().createCopy());

But it would be nice to be able to avoid the String and SAXReader portion and go direct to a dom4j.Element. or dom4j.Document, but Dom4JWriter doesn't take a document as an arg, as in the TSS example.

the DOM4JDriver alone does not help, since it only uses the DOM4J to *read* XML
and to format XML output, but it does not render into a DOM4J

Do you have a pointer to the TSS example?

- Jörg

--------------------------------------------------------------------- To unsubscribe from this list please visit: