This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes constructing xml through java bean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "constructing xml through java bean" Watch "constructing xml through java bean" New topic

constructing xml through java bean

srinu reddy

Joined: Oct 21, 2007
Posts: 12
I have java bean in session, please, let me kow how can i construct a xml file with ben properties and values as xml nodes.
which is the best approach to take.
i have to do it in jsp or in a class.
provide me details.

Thanks & Regards
srinivas reddy
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 32481

You want to do this in a Java class, not in the JSP. That would be way too much logic in a JSP.

It's just a matter of writing a method on the java bean that writes out XML. You need to decide on what the XML should look like. What should be the node names, etc.

If you are just doing this once, it is easiest to hand code. If you are doing it a lot, there are Java/XML mapping libraries that can generate the XML.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Pavel Cherkashin
Ranch Hand

Joined: Mar 04, 2005
Posts: 47
Have something to add.
If there is no requirement to xml structure and the main idea - convert bean to xml and back populate to bean, then the XStream is very usable. Refer this two minutes tutorial
May be that is the best choice in your situation.

Pavel Cherkashin - <br />SCJP, SCWCD, SCDJWS, SCBCD, SCEA, ...<br />
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42958
If the beans truely conform to the JavaBeans spec, then the easiest would be to use the java.beans.XMLEncoder/XMLDecoder classes. No extra library to use and learn - very handy!
Have you checked out Aspose?
subject: constructing xml through java bean
jQuery in Action, 3rd edition