admin管理员组文章数量:1292052
i have function readXML that will read the value from given xml file and it will replace specific node value , after replacing the specific value, same thing has to be reflected the raw file( I mean books.xml file), after doing the modification how to save the content in xml file.
Ex: Code for replacing node.
function readXML() {
xmlDoc = loadXMLDoc("books.xml");
x = xmlDoc.documentElement;
//create a book element, title element and a text node
newNode = xmlDoc.createElement("book");
newTitle = xmlDoc.createElement("title");
newText = xmlDoc.createTextNode("A Notebook");
//add the text node to the title node,
newTitle.appendChild(newText);
//add the title node to the book node
newNode.appendChild(newTitle);
y = xmlDoc.getElementsByTagName("book")[1]
//replace the first book node with the new node
x.replaceChild(newNode, y);
z = xmlDoc.getElementsByTagName("title");
for (i = 0; i < z.length; i++) {
alert(z[i].childNodes[0].nodeValue);
}
//Here i have to save the xmlDoc in my local system.
}
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;
}
I am new to XML.
i have function readXML that will read the value from given xml file and it will replace specific node value , after replacing the specific value, same thing has to be reflected the raw file( I mean books.xml file), after doing the modification how to save the content in xml file.
Ex: Code for replacing node.
function readXML() {
xmlDoc = loadXMLDoc("books.xml");
x = xmlDoc.documentElement;
//create a book element, title element and a text node
newNode = xmlDoc.createElement("book");
newTitle = xmlDoc.createElement("title");
newText = xmlDoc.createTextNode("A Notebook");
//add the text node to the title node,
newTitle.appendChild(newText);
//add the title node to the book node
newNode.appendChild(newTitle);
y = xmlDoc.getElementsByTagName("book")[1]
//replace the first book node with the new node
x.replaceChild(newNode, y);
z = xmlDoc.getElementsByTagName("title");
for (i = 0; i < z.length; i++) {
alert(z[i].childNodes[0].nodeValue);
}
//Here i have to save the xmlDoc in my local system.
}
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;
}
I am new to XML.
Share Improve this question asked Jan 8, 2014 at 12:53 BilalBilal 471 gold badge3 silver badges8 bronze badges 1- If you want to save it on the server side, you will have to upload the manipulated file and store it with serverside logic. – Bergi Commented Jan 8, 2014 at 14:08
1 Answer
Reset to default 5You can download it using FileSaver
var blob = new Blob([xmpString], {type: "text/xml"});
saveAs(blob, "test.xmp");
本文标签: Saving XML File using JavascriptStack Overflow
版权声明:本文标题:Saving XML File using Javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741541076a2384324.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论