This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach 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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "constructing xml through java bean" Watch "constructing xml through java bean" New topic
Author

constructing xml through java bean

srinu reddy
Greenhorn

Joined: Oct 21, 2007
Posts: 12
Hello
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30068
    
149

Srinivas,
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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, 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 />www.linkedin.com/in/pcherkas
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41063
    
  43
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!


Ping & DNS - my free Android networking tools app
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: constructing xml through java bean
 
Similar Threads
IBATIS
java bean to xml
conversion from form bean to XML
How to convert xml file to javax.xml.soap.SOAPElement [ ] array?
To create an xml from a java bean