469,275 Members | 1,871 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,275 developers. It's quick & easy.

Export DataTable to XML using XSL file

Hi

I'd like to get a populated datatable, create an in memory xml document
(file shouldn't be more than a couple of meg), load an XSLT file, do a
transform and stream it to a browser. What am I Missing please?

MemoryStream strm = new MemoryStream();

XmlWriter writer = XmlWriter.Create(strm);

DataTable dataTbl = new myBLL().GetAll();

dataTbl.WriteXml(writer);

// Load the style sheet.

XslCompiledTransform xslt = new XslCompiledTransform();

xslt.Load(Server.MapPath("~/docs/Accounts.xsl"));

// Execute the transform and output the results to a file.

xslt.Transform(?, file to sent to response stream);

Thanks

Andrew
Jun 19 '07 #1
3 10783
J055 schreef:
Hi

I'd like to get a populated datatable, create an in memory xml document
(file shouldn't be more than a couple of meg), load an XSLT file, do a
transform and stream it to a browser. What am I Missing please?

MemoryStream strm = new MemoryStream();

XmlWriter writer = XmlWriter.Create(strm);

DataTable dataTbl = new myBLL().GetAll();

dataTbl.WriteXml(writer);

// Load the style sheet.

XslCompiledTransform xslt = new XslCompiledTransform();

xslt.Load(Server.MapPath("~/docs/Accounts.xsl"));

// Execute the transform and output the results to a file.

xslt.Transform(?, file to sent to response stream);
Since you're talking about streaming to webbrowser i'll presume you have
access to an HttpContext... Output the right content-type header
(probably text/xml) and create an XmlWriter from the
Response.Outputstream... Then pass in that writer instance in the
Transform method...
--
Tim Van Wassenhove - Read my mind <url:http://www.timvw.be/>
Jun 19 '07 #2
J055 wrote:
I'd like to get a populated datatable, create an in memory xml document
(file shouldn't be more than a couple of meg), load an XSLT file, do a
transform and stream it to a browser. What am I Missing please?

MemoryStream strm = new MemoryStream();

XmlWriter writer = XmlWriter.Create(strm);

DataTable dataTbl = new myBLL().GetAll();

dataTbl.WriteXml(writer);

// Load the style sheet.

XslCompiledTransform xslt = new XslCompiledTransform();

xslt.Load(Server.MapPath("~/docs/Accounts.xsl"));

// Execute the transform and output the results to a file.

xslt.Transform(?, file to sent to response stream);


MemoryStream strm = new MemoryStream();
DataTable dataTbl = new myBLL().GetAll();

dataTbl.WriteXml(strm);

strm.Position = 0;

// Load the style sheet.

XslCompiledTransform xslt = new XslCompiledTransform();

xslt.Load(Server.MapPath("~/docs/Accounts.xsl"));

// Execute the transform and output the results to a file.

Response.ContentType = "application/xml";

using (XmlReader xmlReader = XmlReader.Create(strm))
{
xslt.Transform(xmlReader, (XsltArgumentList)null, Response.OutputStream);
}
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Jun 19 '07 #3
Hello Andrew,
Thanks for Martin and Tim's suggestion.

I also agree with them.
xslt.Transform(xmlReader, (XsltArgumentList)null, Response.OutputStream)
could output the stream transformed from XSLT to web browser.

Do you meet any further issue on this?
Please feel free to update here. Thus, we could follow up.:)

Have a great day,
Sincerely,
Wen Yuan
Microsoft Online Community Support
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Jun 21 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by DC Gringo | last post: by
3 posts views Thread by nologin | last post: by
2 posts views Thread by David Richards | last post: by
4 posts views Thread by =?Utf-8?B?anAybXNmdA==?= | last post: by
19 posts views Thread by cj2 | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.