Connecting Tech Pros Worldwide Help | Site Map

Problem outputting xml from ASP.Net page

Newbie
 
Join Date: Sep 2009
Posts: 1
#1: Sep 30 '09
I want to output XML from an ASP.Net page and have created the code below:

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Web;
  7. using System.Data.SqlClient;
  8. using System.Xml;
  9. using System.Text;
  10. using System.Data.OleDb;
  11.  
  12. public partial class Resources_Booking_xmlBookingData : System.Web.UI.Page
  13. {
  14.     public DateTime SelectedDate = System.DateTime.Today;
  15.     public DateTime FirstofWeek = System.DateTime.Today;
  16.     public int ResourceCategory;
  17.  
  18.     protected void Page_Load(object sender, EventArgs e)
  19.     {
  20.         // Create a new XmlTextWriter instance
  21.         XmlTextWriter writer = new XmlTextWriter(Response.OutputStream, Encoding.UTF8);
  22.  
  23.         Response.Cache.SetCacheability(HttpCacheability.NoCache);
  24.  
  25.         // Start Writing
  26.         writer.WriteStartDocument();
  27.  
  28.         /* MY ACTUAL XML, GENERATED FROM DB QUERIES */
  29.     }
  30. }
But this just outputs a blank browser window, with the following source:

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  2. <HTML><HEAD>
  3. <META content="text/html; charset=utf-8" http-equiv=Content-Type></HEAD>
  4. <BODY></BODY></HTML>
Maybe I am missing something obvious, can anyone see what it may be?
Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,066
#2: Oct 1 '09

re: Problem outputting xml from ASP.Net page


I'm surprised that you're even seeing that HTML...

Browsers use HTML in order to determine how to display the output.
You can't just send a browser any old XML...it has to be HTML in order to display.

If you are writing XML directly to the output stream then you are sending the browser XML, not HTML.

How is the browser supposed to know what to do with it?

-Frinny
Reply


Similar ASP.NET bytes