7

Every time I open an XML file, all I get is blank page instead of tag tree. The file itself is correct and loads okay, I can see it via View Source or in the Firebug. I've tried turning off all my addons and tried running Firefox in safe mode, but the problem was not solved.

I'm guessing that I've messed up my configuration somehow and Firefox now tries to render XML files as HTML ones. I've tried googling, but with no success. Help, please?

UPD: example file: http://lj.lain.ru/3/1273657698603.sample.xml Also I've noticed that somehow all of the browsers on the machine are now acting the same, so I'm changing the question accordingly

n1313
  • 653
  • Which version of Firefox do you use? The latest? – sv88 May 12 '10 at 09:14
  • yes, of course. – n1313 May 12 '10 at 09:36
  • Have you tried re-installing or is that not an option? It seems like some files are broken.. – sv88 May 12 '10 at 09:36
  • This problem is here with me, like, for a year. I've upgraded Firefox several times. Does this count as reinstalling? – n1313 May 12 '10 at 09:44
  • That probably counts. What operating system do you use and what browsers? For example, Internet Explorer, Firefox and Opera have a XML view, while Safari and Chrome display blank pages. – sv88 May 12 '10 at 10:04
  • I am on Windows 7. I have Firefox, Chrome, IE8, Opera -- all of them display that example file as blank. I was mistaken when I said that only Firefox misbehaves, sorry about that. I've edited the question – n1313 May 12 '10 at 10:35
  • I Just tried looking at it on my Mac under Safari 4 and I couldn't see it either. Its probably a problem with the XML. – Wuffers May 12 '10 at 14:59
  • Safari does not output an XML in node view, but only shows the content between certain tags. The example does not have that, so the page is blank in Safari. It is not an XML error, Firefox should properly list the nodes of the XML. – sv88 May 12 '10 at 15:30
  • My Firefox 4 displays the file as normal XML, what gives? – Bora May 16 '11 at 12:52
  • Are you by any chance sitting behind a proxy that might fiddle with the HTML headers? Because, when that happens your XML won't be identified as XML, but as another file, like text or html. – Bora May 16 '11 at 12:54
  • I can see the tag tree. Firefox 16 – pratnala Nov 20 '12 at 02:15

6 Answers6

3

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

3

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.

codetuner
  • 131
0

In addition to what others have written, some/most webbrowsers cannot render xml files that are written according to the XML 1.1 standard

Firefox will show an error message pointing to the version 1.1 in the xml prolog.

<?xml version="1.1"?>
---------------^

Internet explorer will just show a blank page.

If you are a software developer, then be aware that the lack of XML 1.1 support is not just limited to webbrowsers. There is also a lack of support for XML 1.1 in many programming languages. (i.e. the default DOM parser of Java 8 does not support XML 1.1). You may altogether prefer to stick to XML version 1.0, if you have a choice.

You could of course just strip the prolog from your xml file. But that won't always work. (i.e. xml nodes can contain some specific control characters, which were forbidden in version 1.0).

bvdb
  • 161
0

This is specific to Firefox but I reckon is worth a shot:

Go to Help\Troubleshooting Information on the Firefox menu and click the button to open the containing folder of your profile.

Backup and then delete the mimeTypes.rdf file, close all instances of Firefox and open Firefox again.

This will force FF to re-generate the default actions for the mime types it knows about, this may fix the issue if it's caused by something weird FF is doing.

sblair
  • 12,697
ChrisB
  • 1,606
0

If you are loading the XML from a server, you need to set the header context type to text/xml.

For example, in PHP you need to put this ahead of your text output:

header("Content-type: text/xml");
Indrek
  • 24,424
Brian
  • 1
0

Does the xml have a tag at the top similar to this?

<?xml version="1.0"?>

This will prepare the browser so it knows what to do.

nhutto
  • 283