简体   繁体   中英

Using “Save As” execCommand in IE8 to save XML file in ANSI format instead of UCS2-Little Endian

I am currently trying to save an XML data using "SaveAs" execCommand from Javascript in Internet Explorer 8 only.I am using document.write(xml) to write the xml content after i open a window.The document object in IE8 uses a saveAs Exec Command to allow the user to save the xml file in the local folder.The XML file is generated but it doesnt set the encoding to my preferred type for a different interface where i need to send this XML which is ANSI/UTF-8 encoding.I can only save the XML in UCS2 little Endian encoding format.Below is the code i am using.

 var location = "D:\\export_to_MCT"+dateTime+".xml";

    var xml = tmpSelectedConfigurationXML.transformNode(xslDoc);// XML Is generated here
   alert(xml);
     **var testlink = window.open  ("about:blank","_blank","toolbar=no,status=no,menubar=no,scrollbars=no,resizable=no,left=10000, top=10000, width=10, height=10, visible=none");
     testlink.document.write(xml); //fileData has contents for the file
testlink.document.close();
testlink.document.execCommand('SaveAs', false, location);**
testlink.close();

My purpose is to save the xml in ANSI/UTF-8 encoding without BOM format.I cant use Scripting.FileSystemObject method of ActiveX object.Please suggest

Strip out unsupported characters from XML

Since not all UTF-8 characters are accepted in an XML document, you'll need to strip any such characters out from any XML that you generate. After reading the xml file replace '/[^\\x{0009}\\x{000a}\\x{000d}\\x{0020}-\\x{D7FF}\\x{E000}-\\x{FFFD}]+/u' with ''

or try with testlink.document.charset="UTF-8";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM