Solved

How to convert a List Object in Java to XML?

Posted on 2009-07-16
3
1,155 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
XML to SQL Table using c# 5 56
diffSum example 4 26
Help with Syntax 9 27
java jdbc batch example 8 22
The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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.

920 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now