File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes Jscript How to: String encoding Converting and Save File Problem in IE 6.0? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of Practical Unit Testing with TestNG and Mockito this week in the Testing forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Reply Bookmark "Jscript How to: String encoding Converting and Save File Problem in IE 6.0? " Watch "Jscript How to: String encoding Converting and Save File Problem in IE 6.0? " New topic
Author

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

v. Ng
Greenhorn

Joined: Jun 02, 2004
Posts: 1
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,


v.
 
 
subject: Jscript How to: String encoding Converting and Save File Problem in IE 6.0?
 
Threads others viewed
export data from db and put it into xml file
Failed to set external entity into CDATA
XML DOM is not working
Hexadecimal to Japanese
What's wrong with it?
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com