...

View Full Version : Jscript How to: String encoding Converting and Save File Problem in IE 6.0?



gnv9000
06-02-2004, 04:08 PM
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:
1.
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.

2.
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,


g.n.

jbot
06-02-2004, 04:18 PM
i know it's a bleeding obvious question, but have you checked out MSDN (http://msdn.microsoft.com/) ? ;)

gnv9000
06-02-2004, 04:24 PM
I already checked out the MSDN and got the above approaches that not working. Do you have any other advice? Thanks!

jbot
06-02-2004, 04:31 PM
sorry, but my first thought was ActiveX.

signed java applets might be worth a look, since, I believe, they get round sandbox issues of vanilla applets (though don't quote me on this).

i've not done what your asking before, so i've got no more advice for you. i'm only guessing in the end. ;)

gnv9000
06-04-2004, 02:32 PM
Now I know ADODB.Stream can do the trick. Thanks.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum