[英]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.