Output XML data from ASP

These are the steps you need to take to output XML data from ASP script:

  • Clear the output buffer to ensure no HTML tags are sent to the client;
  • Set the content-type to text/xml;
  • Optionally (but highly recommended) set the character set to utf-8 and change the ASP code page;
  • Output the XML data (for example, writing a DOM object xml property to the output stream);
  • Stop ASP script processing.

The sample ASP code is included below and you can get more in-depth description of the necessary operations in my InformIT article Optimized presentation of XML content.

Response.Clear
Response.ContentType = contentType
Response.Charset = "utf-8"
Response.Codepage = 65001
Response.Write txt
Response.End

Note: this post is part of You've asked for it series of articles.

No comments:

Post a Comment