2

I'm getting some strange behavoir with my xml-ouput.

I'm filling my xml using a Stringwriter and a xmltextwriter.

Using textw As New IO.StringWriter
    Using xmlw As New System.Xml.XmlTextWriter(textw)
    ....
    End Using

However when outputting the data. i'm getting two different results for the same ('in my eyes') methodoligy. In both situations tw will contain my xml

Non working version: (in IE)

Response.Clear()
Response.Write(textw.ToString)
Response.ContentEncoding = System.Text.Encoding.UTF8
Response.ContentType = "text/xml"
Response.End()

Errormessage is telling there is an error in the contents of my xml.

working version: (in IE)

Response.Clear()
Dim xmlDoc As New XmlDocument
xmlDoc.LoadXml(textw.ToString)
xmlDoc.Save(Response.OutputStream)
Response.ContentEncoding = System.Text.Encoding.UTF8
Response.ContentType = "text/xml"
Response.End()

Question: What is the difference between Response.write and Response.Outputstream?

Note: Both method appear to be working in firefox & chrome. The xml is valid as its already in use at the moment (using the working version).

6
  • 4
    More detailed answer on the same topic is given here: stackoverflow.com/a/2163400 Commented Feb 19, 2014 at 13:24
  • Brings up good results, but i still don't get when i should be using Response.Write or Response.Output(stream) Commented Feb 19, 2014 at 13:33
  • The answer suggested by @Soham actually details that you shouldn't use either (and the reasons why). Instead you should be using Response.Output. Commented Feb 19, 2014 at 14:10
  • 1
    When doing <% = %> in the aspx, it like calling Response.Write(). Maybe it just depends on if you happen to have a string or a stream. And for using Output or OutputStream it all depends on what type of stream you have. Commented Feb 19, 2014 at 15:02
  • 1
    @svranken Response.Write adds string data to the Response buffer. It usually used to write text & if possible, should avoid all concatenations. See this link for benchmarks of different usage scenarios: dotnetperls.com/response-write Commented Feb 20, 2014 at 4:42

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.