Save XML file to local system

本文介绍了一种使用XML DOM对象与FileSystemObject (FSO)来保存XML文件的方法。当发现XML DOM对象的save方法在客户端不起作用时,作者采用FSO创建文本文件并利用Element的xml属性获取XML内容,但这种方法限定了文件只能使用ASCII或Unicode编码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 
Off course, this operation need user’s permission, but when I using xml_dom_obj.save(), nothing happened, even a permission requesting dialog.
I donot know if it was blocked by my IE browser or the save method just can not work at the client side.
so I found another way to do this.
use FileSystemObject to save my xml file, and use Element.xml property to get my xml content.
Because of FileSystemObject.CreateTextFile() just support two charset (ASCII, Unicode), so your xml files will be limited in the 2 encodings.
 
 1
 2 <script type="text/javascript">
 3
 4 function verify()
 5 { 
 6     if (xmlDoc.readyState != 4)
 7     { 
 8         return false;
 9     }
10 }
11
12 var browserok=window.ActiveXObject
13 if (browserok)
14 var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
15 xmlDoc.async="false";
16 xmlDoc.onreadystatechange=verify;
17 xmlDoc.load('hello.xml');
18 // Gets a reference to the root node of the document.
19 root_node=xmlDoc.documentElement;
20
21 var fso = new ActiveXObject("Scripting.FileSystemObject")
22
23 // object.CreateTextFile(filename[, overwrite[, unicode]])
24 // 3rd param
25 // The value is true if the file is created as a Unicode file,
26 // false if it's created as an ASCII file
27 var tf = fso.CreateTextFile("output.xml", true, true);
28
29 tf.WriteLine("<?xml version=/"1.0/" encoding=/"UTF-16/"?>")
30 tf.write(root_node.xml)
31 tf.close()
32
33 alert("ok")
34
35 </script>
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值