DataSet into XmlReader

  • Thread starter Thread starter George Durzi
  • Start date Start date
G

George Durzi

Folks, I'd like to write out a DataSet's Xml into an XmlReader? How do I do
that?
Thanks!
 
My head hurts from trying to figure how how one could write to a reader...

Happy New Year, everyone!

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
I guess I used some wrong terminology. I guess if the reader is "reading",
something is writing to it ... hahah

DataSet oDataSet = Some Report Data
XmlTextReader oXmlTextReader = new XmlTextReader(oDataSet.GetXml(),
XmlNodeType.Document, null);
 
Folks, I'd like to write out a DataSet's Xml into an XmlReader? How do I do
that?

Why do you need to do this? DataSet.WriteXml can convert the DataSet
into an XML format and then the Reader can read the XML. But if you
just want the data from the DataSet, why serialize it to XML?
 
Here's the background ... When I was passing an XmlDataDocument to an
XslTransform, I was getting HORRIBLE performance.

Someone no the Xsl newsgroups suggested I pass an XPathDocument instead. The
XPathDocument constructor that made most sense was the one that took an
XmlReader in.

I got an incredible performance improvement when using the XPathDocument as
opposed to the XmlDataDocument... All I needed was to figure out how to get
the Xml into an XmlTextReader, then cast it to an XmlReader, and use it to
create the XPathDocument

DataSet oDataSet = populate dataset with some report data
XmlTextReader oXmlTextReader = new XmlTextReader(oDataSet.GetXml(),
XmlNodeType.Document, null);
System.IO.FileStream oFileStream = new System.IO.FileStream(exportPath,
System.IO.FileMode.Create);
System.Xml.XmlTextWriter oXmlTextWriter = new
System.Xml.XmlTextWriter(oFileStream, System.Text.Encoding.Unicode);
try
{
XmlUrlResolver oXmlUrlResolver = new XmlUrlResolver();
oXmlUrlResolver.Credentials = CredentialCache.DefaultCredentials;
System.Xml.Xsl.XslTransform oXslTransform = new
System.Xml.Xsl.XslTransform();
oXslTransform.Load(_XslPath, oXmlUrlResolver);
XPathDocument oXPathDocument = new XPathDocument(oXmlReader);
oXslTransform.Transform(oXPathDocument, null, oXmlTextWriter,
oXmlUrlResolver);
oXmlTextWriter.Close();

return exportPath; // path of exported file
}
catch (Exception ex)
{
oXmlTextWriter.Close();
System.IO.File.Delete(exportPath);
throw(ex);
}
 
All I needed was to figure out how to get
the Xml into an XmlTextReader, then cast it to an XmlReader, and use it to
create the XPathDocument

An XmlTextReader is an XmlReader, so no casting should be necessary.
 
Back
Top