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

User999999
  • 2,500
  • 7
  • 37
  • 63
  • 4
    More detailed answer on the same topic is given here: http://stackoverflow.com/a/2163400 – Soham Feb 19 '14 at 13:24
  • Brings up good results, but i still don't get when i should be using Response.Write or Response.Output(stream) – User999999 Feb 19 '14 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. – Damon Feb 19 '14 at 14:10
  • I can only deduct from the post that Reponse.Output is the way to follow while outputting xml. My questions was more along the lines of "When should I opt to use Response.Write". Is there a special reason for its existance? – User999999 Feb 19 '14 at 14:23
  • 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. – the_lotus Feb 19 '14 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: http://www.dotnetperls.com/response-write – Soham Feb 20 '14 at 04:42

0 Answers0