• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java and XML

 
sandeep dhingra
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an application in which data is stored in some Java object, I want this to be written to a file and this file should be a XML file, because if changes are made later to the structure of the object(a new version is developed)it is easy to convert the old file with the same structure as the new one.
Anybody here can help me in this.
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can serialize those objects to XML and store in a file.
 
Shoumin Li
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes ,you can use XMLserializer to serialize objects to XML file.
http://www.onjava.com/pub/a/onjava/2004/12/15/jaxb.html
here is a sample,maybe help
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the class follows JavaBeans semantics, then it's very easy to serialize it using the java.beans.XMLEncoder and XMLDecoder classes.
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JAXB - Java API for XML Binding, would do the job required for you.

Perhaps, this tutorial from Sun about JAXB would help you with a quick example.
 
sandeep dhingra
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks every body.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!