DataSet into XmlReader

G

George Durzi

Folks, I'd like to write out a DataSet's Xml into an XmlReader? How do I do
that?
Thanks!
 
K

Kevin Spencer

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.
 
G

George Durzi

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);
 
P

Patrick Steele [MVP]

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?
 
G

George Durzi

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);
}
 
P

Patrick Steele [MVP]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top