How to serialize an object to XML

I want to serialize an object to XML (actually, a list of objects over time).  the file will be append only (the list of objects can only grow).  

my object looks like this:  

public class MyObject{
     public String recordUID;
     public String userID;
     public String contentType;
     public String[] tags;
     public Date timeStamp;
     public String data;
     public String signature;
}

and I want to get an xml file that looks like this:

<MyObjects>
<MyObject>
      <recordUID>1234</recordUID>
      <userID>me</userID>
      <contentType>something</conentType>
      <tags>
                <tag>tag1</tag>
                <tag>tag2</tag2>
       </tags>
       <timeStam>23:59 2005</timeStamp>
       <data>CDATA here</data>
       <signature> CDATA here</signature>
</MyObject>

are there any good ways to do this other than by hand?  and If I do do it by hand, which xml writer should I use?  
LVL 5
jjacksnAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
Use XMLEncoder
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
radarshCommented:
I guess you can go for the solution CEHJ suggested in your previous question,
"XML Encoding / Deconding" if you don't care about the tag names.

However, if you want to define the tag names yourself, you can try any of

1. Castor - http://www.castor.org
2. Digester - http://jakarta.apache.org/commons/digester/
3. XMLBeans - http://java-source.net/open-source/xml-parsers/xmlbeans
________
radarsh
0
objectsCommented:
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

Manikandan ThiagarajanSenior consultantCommented:
0
mrigankCommented:
I had one question. What do you mean by file shall be append only.
once I create a xml file and save it, further invocation should only append data and not recreate a new file ?

If that is the case, then I think you need to read the xml file into java objects, add the objects that you want to add and then save the  entire object group back into the xml file.
0
mightyoneCommented:
// Serialize the document
      OutputFormat format = new OutputFormat(doc);
      format.setLineWidth(65);
      format.setIndenting(true);
      format.setIndent(2);
      XMLSerializer serializer = new XMLSerializer(System.out, format);
      serializer.serialize(doc);
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.