Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / XML / June 2007

Tip: Looking for answers? Try searching our database.

Export DataTable to XML using XSL file

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
J055 - 19 Jun 2007 13:09 GMT
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
Tim Van Wassenhove - 19 Jun 2007 16:16 GMT
J055 schreef:
> Hi
>
[quoted text clipped - 19 lines]
>
> 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...

Signature

Tim Van Wassenhove - Read my mind <url:http://www.timvw.be/>

Martin Honnen - 19 Jun 2007 16:40 GMT
> 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
[quoted text clipped - 17 lines]
>
> 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);
}

Signature

    Martin Honnen --- MVP XML
    http://JavaScript.FAQTs.com/

WenYuan Wang [MSFT] - 21 Jun 2007 11:01 GMT
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.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.