如何使用Javascript保存xml文件? [英] how to save xml files using Javascript?

查看:69
本文介绍了如何使用Javascript保存xml文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图


1)使用javascript作为对象加载xml文件,比如 note.xml

2)然后将对象保存到新的xml文件,例如 note_new.xml

2) then save the object to a new xml file, say note_new.xml

我做了1)但失败了2)

I did 1) but failed 2)

我试图用方法save()做2)。我失败后,我检查了ms网站,他们说不支持save()....

I tried to use method save() to do 2). After my failure, I checked ms site and they said save() is not supported....

有人可以告诉我如何进行保存吗?

could some one enlighten me how to do the save?

谢谢!

这里是代码:

<html>
<head>  
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body>
<h1>W3Schools Internal Note</h1>
<p><b>To:</b> <span id="to"></span><br />
<b>From:</b> <span id="from"></span><br />
<b>Message:</b> <span id="message"></span>

<script type="text/javascript">
if (window.ActiveXObject){
alert("there is ActiveXObject");
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async=false; 
xmlDoc.load("note.xml"); 
}else{
alert("i am not withActiveXObject!");
xhttp=new XMLHttpRequest();
xhttp.open("GET","note.xml",false);
xhttp.send("");
xmlDoc=xhttp.responseXML;
}
xmlDoc.save("note_new.xml"); 
</script>

</body>
</html>

更新:

似乎这是相关的安全问题。我向那些经验丰富的程序员道歉,因为这似乎是一个新手问题。

seems this is related to security issue. I appologize to those experienced programmers for my putting this question in a rush because it seems a newbie question.

推荐答案

您的问题是:javaScript没有输入/输出( I / O )API,因为它是客户端脚本语言,因此无法通过服务器访问文件系统。您需要使用服务器端脚本语言将数据保存到服务器。客户端可能存在解决问题的黑客攻击,但它们可能是无法解决的,也可能是其他问题。 (顺便说一下:什么api是保存方法成员?你做到了吗?)

Your problem is: javaScript does not have an input/output (I/O) API as it is a client-side scripting language and consequently has no access to the file system via the server. You would need to use a server-side scripting language to save data to a server. There may be hacks to solve your problem client-side, but they are probably either unsave or otherwise buggy. (btw: what api is the save method member of? Did you make that up?)

你能做什么do将数据临时保存到任何DOM元素(例如窗口或javaScript)对象。然而,无法永久地进行这些更改。

What you can do is save data temporarily to any DOM element (e.g. window, or a javaScript) object. There is however no way to make these changes permanent.

在您的情况下,查看 PHP 脚本可能是最好的方式。

In your case, looking in to PHP scripting might be the best way to go.

这篇关于如何使用Javascript保存xml文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆