views:

49

answers:

2

Dear All,

Can one write the results of a XSLTransform.Transform to a memorystream instead of a XMLTextWriter object?

I need to be able to send the results of my transform over the wire to a webbrowser, so writing it to a file on disk on the server is no good.

Tony

A: 

You can easily hook an XmlTextWriter up to a StringWriter, and then send the resulting string to the browser:

StringWriter stringWriter = new StringWriter();
XmlTextWriter xmlTextWriter = new XmlTextWriter(stringWriter);

// write your transform to xmlTextWriter...

xmlTextWriter.Flush();
xmlTextWriter.Close();
stringWriter.Flush();

string result = stringWriter.ToString();
GraemeF
+1  A: 

The other option is to use the newer XslCompiledTransform, which has an overload to output to a Stream.

AJ