This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Java in General and the fly likes XML serialization Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "XML serialization" Watch "XML serialization" New topic

XML serialization

omar bili
Ranch Hand

Joined: Aug 13, 2004
Posts: 177
Hi, i like to serialize to XML format using java5
does someone know how to do that
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

serialize to XML format

Not sure what you mean - serializing an object turns it into a byte stream. Are you looking for a way to turn a stream of bytes into an XML document? Can you explain again what you are trying to do?

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Cal Watson

Joined: Sep 03, 2004
Posts: 8
have you looked at xstream? I haven't actually used it and I am not sure if it will work for Java 5, but I know it is a wat to serialize Java Objects to XML.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17423

Seemed plain enough to me. Write out an XML file. Only gets tricky if you worry about extended character sets (e.g. UTF-16).

I went looking the other day and I still haven't found an industry-standard package for writing out XML, though if you use Xerces, I think they have a DOMWriter class these days. I have an XMLWriter class I did in my EJBWizard that's pretty easy to use, although slightly quirky. I've recommended to others and they've been happy with it.

It's at Grab the source tarball (WinZip can unzip it) and look for the XMLWriter class. I think the package name is something like com.mousetech.ejbwizard.util.xml. This class is completely independent of the rest of the EJBWizard code, so you you can just pull it out and use it (or modify it) as you wish.

An IDE is no substitute for an Intelligent Developer.
Barry Andrews
Ranch Hand

Joined: Sep 05, 2000
Posts: 523

You do not need to use a 3rd party library. You can use java.beans.XMLEncoder.
It works just like ObjectOutputStream except the output is of course XML. To use it your classes must follow the JavaBean standard. I ran into a situation where a library I was using did not follow proper naming standards for the accessor methods so the XMLEncoder would not work. I ended up using XStream which works like a charm. With XStream you do not need to follow any naming standards at all. It just works!
Marian Olteanu

Joined: Dec 02, 2004
Posts: 9
You might wanna try:

<a href="" target="_blank" rel="nofollow">Marian</a>
I agree. Here's the link:
subject: XML serialization
It's not a secret anymore!