aspose file tools
The moose likes JDBC and the fly likes Resultset to Xml File? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "Resultset to Xml File?" Watch "Resultset to Xml File?" New topic
Author

Resultset to Xml File?

Ram Mohan
Greenhorn

Joined: Oct 21, 2005
Posts: 26
hai friends,

Now I got a requirement to produce XML files dynamically from the
RESULTSET I am getting by executing some queries.

But I have no idea about XML.
I found some codes which is helpful to me in xml generation.But they are all static.ie predefining the required tags.

Any one have some idea or sample codes.
waiting for fast response.

Ram Mohan.
Sanju Thomas
Ranch Hand

Joined: Dec 29, 2004
Posts: 243
You can use JDom for this. It will be vert simple to create an XML file form result set, use ResultSetMetaData to get the column name and use those names for tags, then iterate thru resultSet and create the XML file. I don't think this will take more than one hour..!!
Ram Mohan
Greenhorn

Joined: Oct 21, 2005
Posts: 26
Thank you Sanju

I will try.

Ram Mohan.
Ram Mohan
Greenhorn

Joined: Oct 21, 2005
Posts: 26
Still I couldn't overcome the hurdles.
Does anyone have some sample codes.

Ram Mohan.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Which database are you using? Some (such as SQL server) support returning results as XML.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 35250
    
    7
This page has the JDBCSAXParser and JDBCInputSource code examples, which show how generate SAX events from a ResultSet. You can use those as starting points to build an XML document, either as a DOM tree in memory, or by writing directly to a file.


Android appsImageJ pluginsJava web charts
Ram Mohan
Greenhorn

Joined: Oct 21, 2005
Posts: 26
First of all thankx for caring

ans 1: I am using Sql Server database.
ans 2: Iwill look through the link.Thank you

Ram Mohan.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

If you append "FOR XML RAW" to your sql query your results will be returned as an XML String. Creating a Document from this is trivial. However, if you need more control over the structure of the XML you produce look at the link Ulf has posted (which is worth doing anyway, regardless of how you decide to create your XML document)
Ram Mohan
Greenhorn

Joined: Oct 21, 2005
Posts: 26
Paul,
Its a new idea over sql I ever got.
It will make some sense.
Thank you.

Ram Mohan.
Ganga Raju Kolli
Greenhorn

Joined: Dec 14, 2005
Posts: 1
Hi Ram mohan!
You could use Rowset Objects instead of Result set for that u need "rowset.jar" file in ur class path. It can solve ur problem very easily in the RowsetObjects u can find one of the type is Webrowset Object it will automatically generate XML file for ur resultent Resultset.

Enjoy the java world
Ganga raju.
steve souza
Ranch Hand

Joined: Jun 26, 2002
Posts: 852
I have an open source project called the FormattedDataSet that creates text (including html, csv, xml,...) from any tabular data (including ResultSets, arrays, Collections). In general it is flexible and easy to work with. You have total control of what text is generated.

Look at www.fdsapi.com. From here you can see sample code and look at the live demo.

Here is some sample code. Note you can pass queries or ResultSets or arrays and all will generate the text.


[ December 22, 2005: Message edited by: steve souza ]

http://www.jamonapi.com/ - a fast, free open source performance tuning api.
JavaRanch Performance FAQ
Ram Mohan
Greenhorn

Joined: Oct 21, 2005
Posts: 26
Thank You STEVE,
Surely I will look through it.

Ram Mohan.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Resultset to Xml File?
 
Similar Threads
combining 2 dom trees
ResultSet to XML file
Recordset to XML
JSTL EL language not resolving
grep like "where clause"?