View Full Version : XML + Internet Explorer + Character Encoding = Big Headaches

08-24-2009, 03:17 PM
Today I found another reason to hate Internet Explorer.

I've been creating a web based database application for a client and am using some Adobe Spry AutoSuggest AJax functionality to create dynamic drop down lists instead of using traditional HTML select input fields. All was going well, or so I thought. The dynamic fields were working brilliantly in Firefox, Safari and Opera. When I tested in MSIE, I got the error "

Switch from current encoding to specified encoding not supported. Error processing resource

All of my searching on the Internet turned up reference that lead me to believe I needed to change the following reference:

<?xml version="1.0" encoding="iso-8859-1"?>


<?xml version="1.0" encoding="UTF-8"?>

So, naturally I tried the change. Per my normal testing practice, I tested MSIE via the development version of the website, which is housed on an Apache/PHP/MySQL install on my laptop before uploading the change and all appeared to be working just fine.

Then came one of those dreaded emails from the client that all those beautiful dynamic drop downs were not working on Internet Explorer.



I tested MSIE again on the development version of the site and everything looked good. Then when I tested the live version of the site, sure enough the drop downs were not working in MSIE. I then tested the live version of the site in Firefox, Safari and Opera and everything was working just fine.


Naturally I thought I forgot to upload a file and I went through and made sure all of the files were synchronized between the test version and the live version of the website. No luck, things were still broken. I manually requested one of the XML files that is used to generate the drop down list via Internet Explorer and it downloaded just fine with appropriate values. It just seemed that the Spry AJax code wouldn't populate the drop down list.

I searched and searched and could not find any suggested solutions although there were occasional references to character set encodings.

Since the rest of the site other than the XML files were using ISO-8859-1 I thought well maybe this was the problem and I needed to figure out why the XML files would generate errors unless they were set to UTF-8.


I tried adding ISO-8859-1 character encodings to the headers of the XML files via .htaccess the PHP "header()" function (this was redundant, but I wanted to be sure) I then reverted back to:

<?xml version="1.0" encoding="iso-8859-1"?>

Of course when I did this, MSIE would no longer open the XML file and would instead give me that utterly useless error message. I then requested the XML file in Firefox, which opened it just fine like it had all along. Then I looked at the page info.....


@#*@!L#* @#(@&$# ###$****!!!!

When the XML file was opened in Firefox and I looked at the page info, Firefox was telling me that the page encoding was UTF-8.

Yes, I had declared the character encoding in three different ways to be ISO-8859-1 but Firefox was reporting that it was UTF-8.

I opened the the php file that generated the XML for the drop down lists in Windows Notepad and did a "Save As" to see what encoding was used when the file was saved. It should have been saved using ANSI, but no it was saved as UTF-8. Apparently the normal text editor had at some point had started converting my files over to UTF-8 when they were saved. Either that or it started creating new files as UTF-8. There is no way of knowing.

As soon as I resaved all of the files that are used to generate the various XML files for my dynamic drop downs using ANSI encoding via Windows Notepad and then uploaded the files to the webserver, drop downs on the live version of the site started working correctly in Internet Explorer and Firefox was reporting that the character encoding was ISO-8859-1 as it should have been.

I wasted a huge section of my day trying to track down a really obscure issue, simply because in one detail Internet Explorer is absolutely unforgiving in a most bizarre way. What really blows my mind is why the drop downs would work correctly in MSIE on the Apache/PHP install on my Windows based laptop, but would utterly fail on the Apache/PHP install on the FreeBSD server the live site is hosted on. This is absolutely illogical in the most extreme.

In over 13 years of website development experience, this has to go down as just about the most bizarre, illogical and frustrating web browser incompatibility issues I have come across. It is also another reason why I hate MSIE.

If you come across this post searching for why you are getting the error:

Switch from current encoding to specified encoding not supported. Error processing resource

Open the text files that house the code you use to generate your XML files in Windows Notepad and then go to save as. Make a note of what encoding Notepad wants to save the file using and make sure this is compatible with the encoding you have declared in the XML declaration. E.g.:

<?xml version="1.0" encoding="UTF-8"?>

Unless you have really overwhelming need to support multiple languages and/or non-Latin character sets, I strongly recommend you save all files as "ANSI" and use a non-UTF character set like ISO-8859-1. It will just make your life simpler.

08-24-2009, 05:50 PM
I hate that IE8 sucks even worse than IE7.

08-24-2009, 08:23 PM
Here's another reason to hate IE. If you are using UTF-8 the UTF-8 BOF bit throws IE into quirks mode even if the entire webpage validates to HTML specifications and the doc type is the very first thing in the file. How stupid is that?

02-06-2010, 05:36 PM
I just love it when I'm working on resolving an issue by searching Google and Google sends me back to my own thread that I started months earlier on the subject. Man I'm going in circles.

02-07-2010, 06:40 AM
But the good thing is... this site ranks well.

02-07-2010, 06:43 AM
But the good thing is... this site ranks well.
Fortunately for me. I forgot I had already been down this path before. Finding this thread saved me from repeating what I did above. :p

Tim Boothby
08-19-2010, 08:46 AM
This is frustrating isn't it!!

I hit the same kind of problem, I tried the solutions you mention, but they didn't work.

Eventually the solution I found that worked with both IE and other browsers was to declare the content type as utf-8 in php

header('Content-Type: text/xml, charset=utf-8');

and have the XML the php generates also declared as utf-8

<?xml version="1.0" encoding="utf-8"?>

I just couldn't get ISO-8859-1 to work.

Many thanks for your post, I'm sure it greatly reduced the amount of time I spent banging my head against the wall and muttering expletives about Microsoft.