• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

XML serialization

 
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, i like to serialize to XML format using java5
does someone know how to do that
thx
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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?
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Saloon Keeper
Posts: 22483
151
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 http://www.mousetech.com/EJBWizard.html. 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.
 
Ranch Hand
Posts: 529
C++ Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might wanna try:
http://jsx.org/
http://xstream.codehaus.org/
 
I don't get it. A whale wearing overalls? How does that even work? It's like a tiny ad wearing overalls.
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic