Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

Jscript How to: String encoding Converting and Save File Problem in IE

IE6 UTF-8 Save XML File



2:50 pm on Jun 2, 2004 (gmt 0)

Inactive Member
Account Expired


Hi all,

I am writing a cross-browser(i.e. 6 and netscape 7.1) javascript program to save an XML file to local file system.

I have an xml string like below:

var xmlStr = "<?xml version="1.0" encoding="UTF-8"?><a>some info</a>";

I want to save this xml file to local file system with JavaScript,

in Netscape 7.1, this is easy with XPCOM:

var uConv = Components.classes['@mozilla.org/intl/scriptableunicodeconverter'].createInstance(Components.interfaces.nsIScriptableUnicodeConverter);
//uConv = Components.classes["@mozilla.org/intl/scriptableunicodeconverter"].createInstance(Components.interfaces.nsIUTF8ConverterService);

uConv.charset = "UTF-8";

var xmlStrUTF8 = uConv.ConvertFromUnicode(fileStr);

then save the utf-8 encoded file to local file system.

But how can I do the same stuff in IE 6.0?

I tried two approaches but not working:
convert the xml string to XML DOM object, try to use the XML DOM save method, but IE6.0 use msxml 3.0 and it doesn't work by calling save() from browser due to security issue.

using ActiveX filesystem object's createTextFile method, then call write() method. But the problem is the write() method only can save a text file with ASCII encoding or utf-16 encoding. My xml file needs "utf-8" encoding.

So I am wondering how to do it in IE. or if there is some small free window utility I can call from Javascript to convert a utf-16 to utf-8?

Thanks much,