Groups | Blog | Home
all groups > dotnet xml > april 2005 >

dotnet xml : Save DB query results as XML file


Trillium
4/21/2005 1:20:03 PM
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?

Oleg Tkachenko [MVP]
5/1/2005 12:00:00 AM
[quoted text, click to view]

XmlTextWriter w = new XmlTextWriter(file, encoding);
while (reader.Read())
w.WriteNode(r, false);
w.Close();
r.Close();


--
Oleg Tkachenko [XML MVP, MCP]
AddThis Social Bookmark Button