gpt4 book ai didi

javascript - 在 IE8 中使用 "Save As"execCommand 以 ANSI 格式而不是 UCS2-Little Endian 格式保存 XML 文件

转载 作者:行者123 更新时间:2023-11-28 00:37:36 24 4
gpt4 key购买 nike

我目前正在尝试仅在 Internet Explorer 8 中使用 JavaScript 中的“SaveAs”execCommand 来保存 XML 数据。我在打开窗口后使用 document.write(xml) 写入 xml 内容。IE8 中的文档对象使用 saveAs Exec 命令允许用户将 xml 文件保存在本地文件夹中。生成了 XML 文件,但它没有将编码设置为我需要发送此 ANSI/UTF XML 的不同接口(interface)的首选类型-8编码。我只能以UCS2 Little Endian编码格式保存XML。下面是我正在使用的代码。

 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();

我的目的是以ANSI/UTF-8编码保存没有BOM格式的xml。我不能使用ActiveX对象的Scripting.FileSystemObject方法。请建议

最佳答案

从 XML 中删除不支持的字符

由于 XML 文档中并非接受所有 UTF-8 字符,因此您需要从生成的任何 XML 中删除任何此类字符。读取xml文件后替换 '/[^\x{0009}\x{000a}\x{000d}\x{0020}-\x{D7FF}\x{E000}-\x{FFFD}]+/你'与''

或者尝试与teSTLink.document.charset="UTF-8";

关于javascript - 在 IE8 中使用 "Save As"execCommand 以 ANSI 格式而不是 UCS2-Little Endian 格式保存 XML 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28322815/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com