• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Resultset to Xml File?

 
Ram Mohan
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Sanju

I will try.

Ram Mohan.
 
Ram Mohan
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Still I couldn't overcome the hurdles.
Does anyone have some sample codes.

Ram Mohan.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which database are you using? Some (such as SQL server) support returning results as XML.
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ram Mohan
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul,
Its a new idea over sql I ever got.
It will make some sense.
Thank you.

Ram Mohan.
 
Ganga Raju Kolli
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 862
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Ram Mohan
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank You STEVE,
Surely I will look through it.

Ram Mohan.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic