Save XML file to local system
2007-11-30 16:18
489 查看
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>
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>
相关文章推荐
- SystemTimeToFileTime、FileTimeToLocalFileTime、LocalFileTimeToFileTime三函数的跨平台实现
- Home not found. Define system property "openfireHome" or create and add the openfire_init.xml file to the classpath
- Save an XML File to Database and Send an Email using XSLT
- 利用 Hadoop FileSystem moveToLocalFile 方法下载文件 实现HDFS操作
- hadoop2.2.0 core-site.xml--Local file system
- hadoop2.2.0 core-site.xml--Local file system
- How to Read XMLDocument into a SQL Sever XML field / saving XML to database or filesystem...best method?
- ES报错dangling index, exists on local file system, but not in cluster metadata, auto import to cluster
- SYSTEMTIME FileTimeToLocalFileTime 使用
- SystemTimeToFileTime、FileTimeToLocalFileTime、LocalFileTimeToFileTime三函数的跨平台实现
- org.apache.poi.poifs.filesystem.OfficeXmlFileException: The supplied data appears to be in the Office 2007+ XML.
- 用java运行Hadoop程序报错:org.apache.hadoop.fs.LocalFileSystem cannot be cast to org.apache.
- 4000 org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [XXX.xml]';
- IDl save the command line to file
- Extending FileSystemWatcher to ASP.NET
- Spring源码学习-容器初始化之FileSystemXmlApplicationContext(二)路径格式及解析方式(上) 推荐
- [ERROR]-Error: failure: repodata/filelists.xml.gz from addons: [Errno 256] No more mirrors to try.
- Use Jdom to Read XML file
- (转)windows平台时间函数性能比较QueryPerformanceCounter,GetTickCount,ftime,time,GetLocalTime,GetSystemTimeAsFileTime
- Chrome无法打开文件的错误 [Not allowed to load local resource: file://XXXX]