简体   繁体   English

在IE8中使用“另存为” execCommand将XML文件保存为ANSI格式,而不是UCS2-Little Endian

[英]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. 我目前仅在Internet Explorer 8中尝试使用Javascript中的“ SaveAs” execCommand保存XML数据。我在打开窗口后使用document.write(xml)写入xml内容。IE8中的document对象使用saveAs Exec命令,允许用户将xml文件保存在本地文件夹中。生成了XML文件,但没有为我需要发送此ANSI / UTF-8编码的XML的其他接口设置编码为我的首选类型我只能将XML保存为UCS2小端编码格式。以下是我正在使用的代码。

 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 我的目的是将XML以ANSI / UTF-8编码保存而没有BOM格式。我不能使用ActiveX对象的Scripting.FileSystemObject方法。

Strip out unsupported characters from XML 从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. 由于XML文档中并非所有UTF-8字符都被接受,因此您需要从生成的任何XML中剥离所有此类字符。 After reading the xml file replace '/[^\\x{0009}\\x{000a}\\x{000d}\\x{0020}-\\x{D7FF}\\x{E000}-\\x{FFFD}]+/u' with '' 读取xml文件后,替换'/ [^ \\ x {0009} \\ x {000a} \\ x {000d} \\ x {0020}-\\ x {D7FF} \\ x {E000}-\\ x {FFFD}] + /你和''

or try with testlink.document.charset="UTF-8"; 或尝试使用testlink.document.charset =“ UTF-8”;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Internet Explorer中的execCommand使用USC-2 Little Endian编码保存csv文件,如何以UTF-8格式保存? - execCommand in internet explorer saves the csv file using USC-2 Little endian encoding, how to save it with UTF-8 format? 在IE8中使用xmlhttp加载XML文件 - Loading an XML file using xmlhttp in IE8 在IE中,“文件”->“另存为”和document.execCommand('SaveAs')有什么区别? - In IE, what's the difference between File->Save As and document.execCommand('SaveAs')? execcommand(“SaveAs”,null,“file.csv”)在IE8中不起作用 - execcommand(“SaveAs”,null,“file.csv”) is not working in IE8 IE8 execCommand insertorderedlist忽略BR元素 - IE8 execCommand insertorderedlist ignores BR elements Javascript使用ANSI编码将二进制数据保存到文件 - Javascript save binary data to file with ANSI encoding execCommand不适用于xml文件 - execCommand not working for xml file 在IE中“保存为”按钮,在客户端保存文件 - “Save as”-button in IE, save file on client side 使用COM + IE自动化保存文本文件后执行JavaScript回传 - Following a javascript postback using COM + IE automation to save text file 使用var将xml标记数据保存到xml文件中 - using var save xml tag data in to xml file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM