Display XML in the browser#

Had a requirement to throw some XML at the browser and thought this would be a useful snippet to show.

string xmlstr = @"

<statistics>

<gather>66400</gather>

<user_count>666452</user_count>

<user_demand>23.83</user_demand>

</statistics>";

Not much to it really!  The key is to flush and end the response, so no interference comes from the standard asp.net output trying to offer other bits of content type.

XmlDocument doc = new XmlDocument();

doc.LoadXml(xmlstr);

Response.Clear();

Response.ContentType = "text/xml; charset=utf-8";

Response.Write(doc.OuterXml);

Response.Flush();

Response.End();

11/7/2006 1:16:44 PM (GMT Standard Time, UTC+00:00) #    Comments  |  Trackback

 

All content © 2009, John Timney
On this page
This site
Calendar
<January 2009>
SunMonTueWedThuFriSat
28293031123
45678910
11121314151617
18192021222324
25262728293031
1234567
Archives
Sitemap
Blogroll OPML
Talk to Me

The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

Send mail to the author(s) E-mail