【问题标题】:Using "Save As" execCommand in IE8 to save XML file in ANSI format instead of UCS2-Little Endian在 IE8 中使用“另存为”execCommand 将 XML 文件保存为 ANSI 格式而不是 UCS2-Little Endian
【发布时间】:2015-02-19 20:06:07
【问题描述】:

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

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

【问题讨论】:

  • 任何人都可以提出一些建议。这将有很大的帮助

标签: javascript encoding internet-explorer-8 window.open


【解决方案1】:

从 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";

【讨论】:

  • Sudha--我自己尝试了很多选项后粘贴了这个问题;并且仅仅因为我猜你不确定导致问题的正确情况,它并不能反映回答和回答任何问题的合理性
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-06-17
  • 2011-01-16
  • 2016-07-10
  • 1970-01-01
  • 2016-05-09
  • 1970-01-01
  • 2015-02-22
相关资源
最近更新 更多