473,327 Members | 1,920 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

XML Generation

I've got a few tables that I want to select records out of and put into an XML file. Each table will have its own node tree with it's records underneath. Is there a "good" way to do this besides doing it manually (looping thru datareaders and stuff like that). I've tried using the XmlReader/DataSet.WriteXml() and only get one record. I'm using a SQL Server query with FOR XML AUTO, ELEMENTS appended to it. Any help would be greatly appreciated.

Todd
Jul 21 '05 #1
8 1542
What about using the Dataset and it's methods to create the XML?

"Todd Bright" <To********@discussions.microsoft.com> wrote in message
news:CE**********************************@microsof t.com...
I've got a few tables that I want to select records out of and put into an XML file. Each table will have its own node tree with it's records
underneath. Is there a "good" way to do this besides doing it manually
(looping thru datareaders and stuff like that). I've tried using the
XmlReader/DataSet.WriteXml() and only get one record. I'm using a SQL
Server query with FOR XML AUTO, ELEMENTS appended to it. Any help would be
greatly appreciated.
Todd

Jul 21 '05 #2
Have you looked at the managed SQLXML classes
http://msdn.microsoft.com/library/de...otnet_0jck.asp ?

"Jim Douglas" wrote:
What about using the Dataset and it's methods to create the XML?

"Todd Bright" <To********@discussions.microsoft.com> wrote in message
news:CE**********************************@microsof t.com...
I've got a few tables that I want to select records out of and put into an

XML file. Each table will have its own node tree with it's records
underneath. Is there a "good" way to do this besides doing it manually
(looping thru datareaders and stuff like that). I've tried using the
XmlReader/DataSet.WriteXml() and only get one record. I'm using a SQL
Server query with FOR XML AUTO, ELEMENTS appended to it. Any help would be
greatly appreciated.

Todd


Jul 21 '05 #3
Todd Bright wrote:
I've got a few tables that I want to select records out of and put into an
XML file. Each table will have its own node tree with it's records
underneath. Is there a "good" way to do this besides doing it manually
(looping thru datareaders and stuff like that). I've tried using the
XmlReader/DataSet.WriteXml() and only get one record. I'm using a SQL
Server query with FOR XML AUTO, ELEMENTS appended to it. Any help would
be greatly appreciated.

Todd


This is easy as pie.

Instead of doing an ExecuteReader on your SqlCommand, do an ExecuteXMLReader
and it loads it into an XML file.

XMLReader xr = myCmd.ExcecuteXMLReader();

Take the resultant ( xr ) and create an XML Document with it.

XMLDocument xd = new XMLDocument(xr);

Then do a xd.Save("<filename>") name on the Document.

--
w:4

Jul 21 '05 #4
Tried this one too. It only gives me one record back, unless I do a read for each record. And as far as I can tell, there's no way to tell how many records there are.

"Benjamin Disraeli" wrote:
Todd Bright wrote:
I've got a few tables that I want to select records out of and put into an
XML file. Each table will have its own node tree with it's records
underneath. Is there a "good" way to do this besides doing it manually
(looping thru datareaders and stuff like that). I've tried using the
XmlReader/DataSet.WriteXml() and only get one record. I'm using a SQL
Server query with FOR XML AUTO, ELEMENTS appended to it. Any help would
be greatly appreciated.

Todd


This is easy as pie.

Instead of doing an ExecuteReader on your SqlCommand, do an ExecuteXMLReader
and it loads it into an XML file.

XMLReader xr = myCmd.ExcecuteXMLReader();

Take the resultant ( xr ) and create an XML Document with it.

XMLDocument xd = new XMLDocument(xr);

Then do a xd.Save("<filename>") name on the Document.

--
w:4

Jul 21 '05 #5
According to the docs, SQLXML is able to be used if VS .Net is installed? Yet the IDE will still not show me the System.Data.SqlXml class? Guess I'm just gonna have to do this manually.

"Niroo" wrote:
Have you looked at the managed SQLXML classes
http://msdn.microsoft.com/library/de...otnet_0jck.asp ?

"Jim Douglas" wrote:
What about using the Dataset and it's methods to create the XML?

"Todd Bright" <To********@discussions.microsoft.com> wrote in message
news:CE**********************************@microsof t.com...
I've got a few tables that I want to select records out of and put into an

XML file. Each table will have its own node tree with it's records
underneath. Is there a "good" way to do this besides doing it manually
(looping thru datareaders and stuff like that). I've tried using the
XmlReader/DataSet.WriteXml() and only get one record. I'm using a SQL
Server query with FOR XML AUTO, ELEMENTS appended to it. Any help would be
greatly appreciated.

Todd


Jul 21 '05 #6
I made a mistake... one of the examples references using Microsoft.Data.SqlXml. But intellisense doesn't show a Data class under the Microsoft class???

"Todd Bright" wrote:
According to the docs, SQLXML is able to be used if VS .Net is installed? Yet the IDE will still not show me the System.Data.SqlXml class? Guess I'm just gonna have to do this manually.

"Niroo" wrote:
Have you looked at the managed SQLXML classes
http://msdn.microsoft.com/library/de...otnet_0jck.asp ?

"Jim Douglas" wrote:
What about using the Dataset and it's methods to create the XML?

"Todd Bright" <To********@discussions.microsoft.com> wrote in message
news:CE**********************************@microsof t.com...
> I've got a few tables that I want to select records out of and put into an
XML file. Each table will have its own node tree with it's records
underneath. Is there a "good" way to do this besides doing it manually
(looping thru datareaders and stuff like that). I've tried using the
XmlReader/DataSet.WriteXml() and only get one record. I'm using a SQL
Server query with FOR XML AUTO, ELEMENTS appended to it. Any help would be
greatly appreciated.
>
> Todd

Jul 21 '05 #7
Todd Bright wrote:

Left off a step:

http://www.dbforums.com/t698233.html

strTmp = xmlReader.ReadOuterXml()
While strTmp.Length > 0
sbBuilder.Append(strTmp)
strTmp = xmlReader.ReadOuterXml()
End While
sbBuilder.Append("")

xmlReader.Close()
xmlReturn.LoadXml(sbBuilder.ToString())

Tried this one too. It only gives me one record back, unless I do a read
for each record. And as far as I can tell, there's no way to tell how
many records there are.

"Benjamin Disraeli" wrote:
Todd Bright wrote:
> I've got a few tables that I want to select records out of and put into
> an
> XML file. Each table will have its own node tree with it's records
> underneath. Is there a "good" way to do this besides doing it manually
> (looping thru datareaders and stuff like that). I've tried using the
> XmlReader/DataSet.WriteXml() and only get one record. I'm using a SQL
> Server query with FOR XML AUTO, ELEMENTS appended to it. Any help
> would be greatly appreciated.
>
> Todd


This is easy as pie.

Instead of doing an ExecuteReader on your SqlCommand, do an
ExecuteXMLReader and it loads it into an XML file.

XMLReader xr = myCmd.ExcecuteXMLReader();

Take the resultant ( xr ) and create an XML Document with it.

XMLDocument xd = new XMLDocument(xr);

Then do a xd.Save("<filename>") name on the Document.

--
w:4


--
w:4

Jul 21 '05 #8
I'll have to bookmark this one.

I ended up just looping thru the recordset manually and using the XmlTextWriter object. MUCH more straightforward than the XmlReader. I spent half a day investigating different ways to execute a SQL statement back and put into an XML file, none of which worked the way I was looking for. Took me maybe an hour to investigate the XmlTextWriter and write the code to implement it.

"William Ewart Gladstone" wrote:
Todd Bright wrote:

Left off a step:

http://www.dbforums.com/t698233.html

strTmp = xmlReader.ReadOuterXml()
While strTmp.Length > 0
sbBuilder.Append(strTmp)
strTmp = xmlReader.ReadOuterXml()
End While
sbBuilder.Append("")

xmlReader.Close()
xmlReturn.LoadXml(sbBuilder.ToString())

Tried this one too. It only gives me one record back, unless I do a read
for each record. And as far as I can tell, there's no way to tell how
many records there are.

"Benjamin Disraeli" wrote:
Todd Bright wrote:

> I've got a few tables that I want to select records out of and put into
> an
> XML file. Each table will have its own node tree with it's records
> underneath. Is there a "good" way to do this besides doing it manually
> (looping thru datareaders and stuff like that). I've tried using the
> XmlReader/DataSet.WriteXml() and only get one record. I'm using a SQL
> Server query with FOR XML AUTO, ELEMENTS appended to it. Any help
> would be greatly appreciated.
>
> Todd

This is easy as pie.

Instead of doing an ExecuteReader on your SqlCommand, do an
ExecuteXMLReader and it loads it into an XML file.

XMLReader xr = myCmd.ExcecuteXMLReader();

Take the resultant ( xr ) and create an XML Document with it.

XMLDocument xd = new XMLDocument(xr);

Then do a xd.Save("<filename>") name on the Document.

--
w:4


--
w:4

Jul 21 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

51
by: Mudge | last post by:
Please, someone, tell me why OO in PHP is better than procedural.
8
by: Max M | last post by:
Yesterday there was an article on Slashdot: http://books.slashdot.org/article.pl?sid=03/09/04/1415210&mode=flat&tid=108&tid=126&tid=156 It is about automatic code generation. I got interrested...
0
by: Rasmus Fogh | last post by:
Someone raised the question of automatic code generation a few weeks back. And yes, we (CCPN) are using automatic Python code generation in a major way. Basically we are making data models in...
8
by: | last post by:
Wel, I am rebuilding the VC# 2002 project that I have deployment problems with the 2003 version, hoping this solves the problems, but now I encounter this wierd bug??? If I have the project, and...
9
by: Hayato Iriumi | last post by:
Hello, I hear some hypes about creating code to generate C# or VB .NET code, that is, code generation (sounds straight forward enough). I haven't really seen how it's done in real world. I'm...
1
by: George Meng | last post by:
I want to evaluate some code generation tool for my company. Want to get some idea from you. The bottom line is I want to get a tool to generate both store procedure as well as business object...
3
by: Eddy Ilg | last post by:
Hi, I would like to suppress .pyc generation or have the .pyc generation in a speical seperate root (I found something about PYCROOT). Has this been implemented yet? Is there an environment...
31
by: eliben | last post by:
Hello, In a Python program I'm writing I need to dynamically generate functions and store them in a dict. eval() can't work for me because a function definition is a statement and not an...
4
by: Troels Arvin | last post by:
Hello, We have started planning our DB2 generation 8 -9.1/9.5 upgrades, as April 30 2009 is no longer distant future (ordinary support for DB2 generation 8 on Linux/Unix/Windows==LUW will end on...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.