Why my browsers display XML files as blank pages?

If the XML file is malformed, then the browser will not know what to do with it, and in my experience show nothing.

If the XML file is valid then most browsers (IE8, Chrome and Firefox) give a message like This XML file does not appear to have any style information associated with it. The document tree is shown below. and go into a special mode for showing XML files with features like being able to collapse code blocks.

Look here: XML Validator


I just got and solved a similar issue: from my ASP.NET MVC application I have a controller that returns raw XML which I want to see in the web browser as a DOM tree.

Chrome does it fine, but IE 11 simply shows a blank page.

The problem seems to be the "Content-Type" HTTP header: if it does not contain a charset value, IE simply shows a blank page (unless you have a Content-Disposition header, in which case IE offers you to save the XML).

So, the following HTTP response is OK for Chrome, but IE shows a blank page:

HTTP/1.1 200 OK
Cache-Control: private, s-maxage=0
Content-Type: application/xml
Server: Microsoft-IIS/8.0
Date: Fri, 25 Jul 2014 14:29:02 GMT
Content-Length: 693

<?xml version="1.0" encoding="utf-16"?><data>...</data>

Note: Make sure to provide the correct Content-Length, although I did not test what happens if the Content-Length header is missing or has a wrong value. Also, I removed the X- headers generated by IIS from this printout, but it is safe to leave them.


But the following does work under both IE and Chrome:

HTTP/1.1 200 OK
Cache-Control: private, s-maxage=0
Content-Type: application/xml; charset=utf-8
Server: Microsoft-IIS/8.0
Date: Fri, 25 Jul 2014 14:29:02 GMT
Content-Length: 693

<?xml version="1.0" encoding="utf-16"?><data>...</data>

The only difference it the addition of ; charset=utf-8 in the Content-Type header.

For ASP.NET MVC developers, this means that if you want to render raw XML and support IE, you cannot use:

string xmldata = ...
return this.File(Encoding.UTF8.GetBytes(xmldata), "application/xml");

Instead, the following works:

string xmldata = ...
Response.ContentType = "application/xml";
Response.ContentEncoding = Encoding.UTF8;
Response.AddHeader("Content-Length", Convert.ToString(xmldata.Length));
return this.Content(xmldata);

Kind regards.