• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1182
  • Last Modified:

How to convert a List Object in Java to XML?

I'm currently creating a web application and need to convert the Java List<Object> Type which results from a database select into an XML file. What is the most efficient way of doing this?

2 Solutions
One elegant way to do this is using XML serialization, but you can also build the xml yourself using loops and string concatenation.
I also recommend building the XML from actual DOM objects. This way you'll automatically ensure that everything is legal, and have a simple support for hierarchy.
You can see a sample of creating an XML structure and converting it to string here:
This link here has a very simple and easy to do code - http://www.roseindia.net/java/java-conversion/ObjectToXML.shtml

You need to code the xml fields though.
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.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now