我是新来的JavaScript和使用它我的项目。在那我需要读取XML文件,然后操纵后,我想将更新的值存储回xml文件。我从XML文件成功,但无法获得值将值存储回xml文件。 这是我试过的代码。如何使用JavaScript将数据存储在xml文件中?
<html>
<head>
<title>
Hello
</title>
</head>
<body>
<script>
function loadXML()
{
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","data.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
//saving XML from document input fields
xmlDoc.getElementsByTagName("Name")[0].childNodes[0].nodeValue = document.getElementById("name").value;
xmlDoc.getElementsByTagName("Address")[0].childNodes[0].nodeValue = document.getElementById("address").value;
xmlDoc.getElementsByTagName("Contact")[0].childNodes[0].nodeValue = document.getElementById("contact").value;
xmlDoc.save();
}
</script>
<form action="Display.html" method="post">
<table>
<tr>
<td>Name :</td>
<td>
<input type="text" id="name"/>
</td>
</tr>
<tr>
<td>Address :</td>
<td>
<input type="text" id="address"/>
</td>
</tr>
<tr>
<td>Contact :</td>
<td>
<input type="text" id="contact"/>
</td>
</tr>
<tr><td></td><td></td><td><input type="button" value="Submit" onclick="loadXML()"></td></tr>
</table>
</form>
</body>
</html>
如果有人知道answer.Please用例子来解释如果可能的话 在此先感谢...
您需要一些服务器端代码来为您节约。 – alex
欢迎来到StackOverflow!我已经为您解决了问题中的代码格式。请花点时间阅读“问题提示”区域右侧的方便的**如何格式化**框和**中的[链接页面](http://stackoverflow.com/editing-help) ?] **就在问题区域上方。 (还有一个预览框显示在提问框中,您可以在其中预览您的问题。) –