[Project_owners] Convert a windows-1251 encoded string into a UTF-8 string

Eric Jung grimholtz at yahoo.com
Mon Jul 18 05:57:54 EDT 2005


Is the XmlHttpRequest object acquiring XML? If so, you can specify
the encoding in the XML processing instruction:

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



--- Didier Ernotte <didier at ernotte.com> wrote:

> Hi,
> 
> I want to display in a textbox a windows-1251 encoded string that
> comes
> from the source of a web page (loaded from an XmlHttpRequest
> object). I
> guess I have to encode it into a UTF-8 string before displaying it
> in a
> textbox (direct display shows me garbage). 
> I try to use 
> 
> var uConv =
> Components.classes['@mozilla.org/intl/utf8converterservice;1'].
>   createInstance(Components.interfaces.nsIUTF8ConverterService);
> var str =
> uConv.convertStringToUTF8(gRssXmlHttpRequest.responseText,
> gRssXmlHttpRequest.getResponseHeader("Content-Encoding"), false);
> document.getElementById("inforss.html.code").value =
> gRssXmlHttpRequest.str;
> 
> without success. I have also tried
> 
> var unicodeConverter =
>
Components.classes["@mozilla.org/intl/scriptableunicodeconverter"].createInstance(Components.interfaces.nsIScriptableUnicodeConverter);
> unicodeConverter.charset =
> gRssXmlHttpRequest.getResponseHeader("Content-Encoding");
> var str = unicodeConverter.ConvertToUnicode(
> gRssXmlHttpRequest.responseText ) + unicodeConverter.Finish();
> document.getElementById("inforss.html.code").value =
> gRssXmlHttpRequest.str;
> 
> without success. 
> 
> I have saw that in the localization XPCOM object there are
> "Character
> Set Detectors". How can I use them to check the encoding of the
> source
> string ?
> 
> Does anyone have a clue  ?
> 
> Thanks
> 
> Didier
> _______________________________________________
> Project_owners mailing list
> Project_owners at mozdev.org
> http://mozdev.org/mailman/listinfo/project_owners
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 


More information about the Project_owners mailing list