472,146 Members | 1,564 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Save DB query results as XML file

I am trying to query a SQL Server database, retrieve the results as XML, and
save them to a file. I was trying to use the SqlXmlCommand,
SqlXmlCommandType.XPath and an xsd to query the database, and load the
results into a XmlTextReader. This works fine. But then I get stuck. I
don't want to DO anything with the data besides putting it into a file.
Should I be loading the results into a stream, instead? Then load the stream
into a string, to an XmlDocument, then .Save(...)? Or might a XmlTextWriter
have a role in here somewhere?

Can anyone give me a hint on how I should approach this?
Nov 12 '05 #1
1 1481
Trillium wrote:
I am trying to query a SQL Server database, retrieve the results as XML, and
save them to a file. I was trying to use the SqlXmlCommand,
SqlXmlCommandType.XPath and an xsd to query the database, and load the
results into a XmlTextReader. This works fine. But then I get stuck. I
don't want to DO anything with the data besides putting it into a file.
Should I be loading the results into a stream, instead? Then load the stream
into a string, to an XmlDocument, then .Save(...)? Or might a XmlTextWriter
have a role in here somewhere?

Can anyone give me a hint on how I should approach this?


XmlTextWriter w = new XmlTextWriter(file, encoding);
while (reader.Read())
w.WriteNode(r, false);
w.Close();
r.Close();
--
Oleg Tkachenko [XML MVP, MCP]
http://blog.tkachenko.com
Nov 12 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Nikhil Tayal | last post: by
2 posts views Thread by nuhura01 | last post: by
reply views Thread by leo001 | last post: by

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.