Google
 

«           »

XmlHttpRequest, Unicode and Firefox

Posted October 27, 2008 – 3:46 pm by Yakov Shafranovich in Website

Just a quick post about a problem I ran into earlier today. It seems that when using Javascript in Firefox 3 with document.implementation.createDocument to create XML documents (for XmlHttpRequest), the encoding stays as ISO-8859-1 instead of Unicode (UTF-8). What it really should be doing, is making the encoding same as the parent document. This seems to be a bug in Firefox 3 which is documented at Bugzilla as # 431701 and on track to be fixed in Firefox 3.04 and Firefox 3.1.

HOWEVER, a related bug report (# 407213) has an interesting workaround which actually points to an undocumented feature in Firefox. By default, the property document.characterSet is ready only, however if you parse a new XML file with the encoding processing instruction set to a different character set, it will change the internal character set in the resulting XML DOM document even if that encoding is different than the parent document. Here is what the workaround in the bug report looks like:

var domDocument = new DOMParser().parseFromString("<?xml version='1.0'
encoding='UTF-8'?><dummy/>","application/xml");

It relies on the DOMParser object which is Firefox specific. For cross browser support, you can use Sarissa, which is a cross browser XML library for Javascript.

Tags: , , ,

Permalink | Trackback URL | This post has

  1. 1 Trackback(s)

  2. Oct 27, 2008: Personal Website of Yakov Shafranovich » Blog Archive » QuickBase and Unicode Support

Post a Comment