Solved

How to convert a List Object in Java to XML?

Posted on 2009-07-16
3
1,159 Views
Last Modified: 2012-08-14
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?


Thanks
0
Comment
Question by:Amos_Mike
3 Comments
 
LVL 14

Expert Comment

by:flob9
ID: 24868823
One elegant way to do this is using XML serialization, but you can also build the xml yourself using loops and string concatenation.
0
 
LVL 8

Accepted Solution

by:
ozlevanon earned 300 total points
ID: 24868954
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:
http://www.genedavis.com/library/xml/java_dom_xml_creation.jsp
0
 
LVL 20

Assisted Solution

by:a_b
a_b earned 200 total points
ID: 24870309
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.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question