Question

I'm encountering an issue with UTF-16 encoded XML and Firefox that I can't seem to resolve.

I'm working with the TFS11 web access API in order to create a custom work item control. That should be irrelevant, but suffice it to say that I'm not at liberty to mess with any of the web server settings or the way in which the application sends the data.

The general workflow is that the control pulls down an attachment file, parses it as XML, and then works with the XML in order to render data for the end-user. This all works perfectly in IE8, IE9, and Chrome. However, in FireFox 11, it does not.

Here's a snippet of code that demonstrates how I'm grabbing my XML and parsing it:

$.ajax({
    url: uri,
    async: true,
    dataType: "text",
    complete: function (xhr, status) {
        if (xhr.responseText != null) {
            data = null; 
            if (window.DOMParser) {
                parser = new DOMParser();
                var responseText = xhr.responseText; 
                data = parser.parseFromString(responseText, "text/xml");
            }
        }
    }
});

The problem is the contents of xhr.responseText. In FireFox, it contains ��<?�x�m�l� �v�e�r�s�i�o�n�=�"�1�.�0�"� �e�n�c�o�d�i�n�g�=�"�u�t�f�-�1�6�"�?�> (and so on).

The first two characters are FF FE. I've read up on it, and I know that this is the Byte Order Marker. What I don't understand is why I'm seeing this instead of correctly encoded text.

Here are my response headers from the request:

HTTP/1.1 200 OK
Cache-Control: private
Content-Type: application/octet-stream
Server: Microsoft-IIS/7.5
X-TFS-ProcessId: 0bc401d6-0b5d-47a4-85b8-114344957d22
X-AspNetMvc-Version: 3.0
Content-Disposition: attachment; filename=d187d991-550a-4f49-b379-3bea7f9518c8.xml
X-AspNet-Version: 4.0.30319
Persistent-Auth: true
X-Powered-By: ASP.NET
X-Content-Type-Options: nosniff
X-FRAME-OPTIONS: SAMEORIGIN
Date: Thu, 15 Mar 2012 17:15:00 GMT
Content-Length: 7520

Is there a workaround for this?

Was it helpful?

Solution

Send the right encoding in your response? It looks like Firefox is not looking at the BOM in your data, so doesn't realize your data is UTF-16 and not UTF-8....

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top