MSIE hates my xml
April 9th, 2006
Internet Explore 6 kept on giving me the wierdest error on an XML document that I knew was fine.
The XML page cannot be displayed
Cannot view XML input using style sheet. Please correct the error and then click the Refresh button, or try again later.
System does not support the specified encoding. Error processing resource ‘http://localhost/tfhcc/feed.php’. Line 1, Position 38
<?xml version=”1.0″ encoding=”utf8″?>
It was build from PHP5’s DOM functionality, and of course worked in firefox. In fact, I had no style sheet specified, so the error was with IE’s internal styling.
To make short work of the problem, IE doesn’t like the initial XML declaration. So, give it when I can.
header("Content-type: application/xml");
if( strpos($_SERVER['HTTP_USER_AGENT'],”MSIE”) )
print $dom->saveHTML();
else
print $dom->saveXML();
A standard PHP detect, A nice XML DOM view for all.
Update
Mr. Stenström is correct - I incorrectly specified the encoding. So the correct code to get the xml view in both browsers is
$dom = new DomDocument('1.0', 'utf-8');
...
header("Content-type: application/xml");
print $dom->saveXML();
Posted in PHP |
May 1st, 2006 at 3:48 pm
The problem is actually that you have spelled the encoding wrong. It should be utf-8 (note the dash).