使用Javascript创建XML文件 [英] Creating an XML file using Javascript

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

问题描述

我有以下代码:

xmlDoc=loadXMLDoc("dbbackup.xml");
x=xmlDoc.getElementsByTagName("record");
alert(x);
for (i=0;i<3;i++) {
  newel=xmlDoc.createElement("edition");
  newtext=xmlDoc.createTextNode("first");
  alert("x  : "+x[i]);
  alert("newtext :"+newtext.nodevalue);
  x[i].appendChild(newel);
  alert("sd");
}
function loadXMLDoc(dname) {
  if (window.XMLHttpRequest) {
    xhttp=new XMLHttpRequest();
  } else {
    xhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
  xhttp.open("GET",dname,false);
  xhttp.send();
  return xhttp.responseXML;
}

我创建了 dbbackup.xml 在同一位置,XML文件如下:

I have created dbbackup.xml in the same location and the XML file looks like:

<sticky>
  <record></record>
</sticky>

但在运行我的脚本后, xml 文件没有得到更新。

But after running my script the xml file is not getting updated.

推荐答案

您可以从客户端的网页收集数据并将其发送到服务器(ajax) ,然后生成xml文件并发回文件链接(ajax)。使用javascript使用服务器返回的链接生成下载链接。

You can collect data from the web page in client side and send them to the server (ajax), which will then generate the xml file and send back a link to the file (ajax). Use javascript to generate a download link using the link returned by the server.

这是我在我的一个项目中解决问题的方法。

This is the way I do to solve the problem in one of my project.

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

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