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 how to convert a result set into a xml file 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 "how to convert a result set into a xml file" Watch "how to convert a result set into a xml file" New topic
Author

how to convert a result set into a xml file

selva suresh
Greenhorn

Joined: Jul 11, 2009
Posts: 11
Hai Guys,
I need some java code to store my resultset in a xm file (ie the details about some books ).
and next the buyer or the user will select the books deponds on the price ,so i have to store all the books in a xml
and search acording to the price. can any one help me.

Thanks & Regards
SURESH
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Writing out data to an XML file can be accomplished in a *lot* of different ways, from just marshaling the data "by hand" (in other words, just writing XML tags and the data from the result set to a file manually) to using any number of XML libs/transformation solutions.

As far as searching goes I'm not quite sure what your actual requirements are here--how the data is stored shouldn't really matter to the searching, unless they're searching XML by just looking at the file. If you want the data ordered in the XML file there are also a number of ways that could be done.

What are your *actual* requirements?
selva suresh
Greenhorn

Joined: Jul 11, 2009
Posts: 11
Hi David,
I want to store the data retrieved from the database in a XML format and from that i will select some records which satisfy the criteria .I don't want to go again and hit the db server. i can take the details from the XML file itself . without hitting the db server.
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
The Hibernate Framework includes functionality for producing XML-based data derived from relational data. There is a simple toXML() method which handles this.

Hibernate is Great!
Dan Walin
Ranch Hand

Joined: Nov 11, 2003
Posts: 109
Here's an example of something I sometimes do. In this example, the xml is "manually generated" but it's pretty simple code I think. This method gets an object which contains various fields (which end up being elements in the xml). The object was created by other code which just looped through the results assigning the results of each field to a field in the object. Once the CMRAll object is created, then "xmlIt" is called with that object as a parameter. This code just loops through all the fields and for each field an element is created and then the value of that field is added. The nice thing about this code is that it's relatively reusable because none of the fields are hardcoded, this method just figures out what fields exist and what their values are.

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

FWIW (w/ normal edited code caveats):Note that this will only print public fields--using public properties runs counter to most Java programming philosophies, but may work fine for your situation.

As simple as this is, I'd still probably just use an existing library for this functionality, probably one that allowed marking (and possibly transforming) input bean properties via annotations etc.
selva suresh
Greenhorn

Joined: Jul 11, 2009
Posts: 11
Hi David,
Thanks for your valueable efforts , spending time for me .But i am now not in the office. my company is closed due to some finacial suitation .if i get another chance i will surely disturb you all guys until bye .

Thanks @ Regards
Suresh
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to convert a result set into a xml file
 
Similar Threads
xml bible
Attribute of a xml tag should contain content of a xml file.
IDE Defaults
XML Books
Finding best deal of mall program in java