glfminh 0 Posted May 17, 2011 Report Share Posted May 17, 2011 (edited) -I have one file books.xml:<bookstore><book> <title>Everyday Italian</title> <author>Giada De Laurentiis</author></book></bookstore>-I want to add one node* into books.xml<book> <title>ABC</title> <author>VTM</author></book>The file books.xml after process:<bookstore><book> <title>Everyday Italian</title> <author>Giada De Laurentiis</author></book><book> <title>ABC</title> <author>VTM</author></book></bookstore>-my file html :<html><head><script type="text/javascript" src="loadxmldoc.js"> </script></head><body><script type="text/javascript">xmlDoc=loadXMLDoc("books.xml");newel=xmlDoc.createElement("book");x=xmlDoc.getElementsByTagName("book")[0];x.appendChild(newel);</script></body></html>where loadxmldoc.js: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;} BUT AFTER PROCESS, I DON'T CHANGE IN FILE books.xml.Can you help me, thannks. Edited May 17, 2011 by vtm Quote Link to post Share on other sites
jeffman 86 Posted May 17, 2011 Report Share Posted May 17, 2011 We could use more information. Are you trying to add the node in an XML editor, using a PHP object, a JavaScript object, or what? Quote Link to post Share on other sites
glfminh 0 Posted May 17, 2011 Author Report Share Posted May 17, 2011 We could use more information. Are you trying to add the node in an XML editor, using a PHP object, a JavaScript object, or what?I want to do by javascript, Can you help? Quote Link to post Share on other sites
jeffman 86 Posted May 17, 2011 Report Share Posted May 17, 2011 There are a lot of things that can go wrong. Post the code you are trying to use. Quote Link to post Share on other sites
packrat 0 Posted May 17, 2011 Report Share Posted May 17, 2011 try out the examples to see how the syntax works:http://w3schools.com/xml/xml_examples.aspCreate XML Element example // this statement will append your new book node as a child of the selected book node rather than a sibling as intended.x=xmlDoc.getElementsByTagName("book")[0];x.appendChild(newel); if you're wanting to modify the actual file you'll have to use a server side process for that, posting your xml text back to the server to write the file; JavaScript cannot write files. Quote Link to post Share on other sites
glfminh 0 Posted May 18, 2011 Author Report Share Posted May 18, 2011 try out the examples to see how the syntax works:http://w3schools.com/xml/xml_examples.aspCreate XML Element example// this statement will append your new book node as a child of the selected book node rather than a sibling as intended.x=xmlDoc.getElementsByTagName("book")[0];x.appendChild(newel); if you're wanting to modify the actual file you'll have to use a server side process for that, posting your xml text back to the server to write the file; JavaScript cannot write files. I have seen code, thanks, I want to modify the actual file on server, Do you have JSP?<?xml version="1.0" encoding="utf-8"?><bookstore> <book> <title>abc</title> <author>xyz</author> </book>this node I want to add <book> <title>goo</title> <author>jkl</author> </book></bookstore> Quote Link to post Share on other sites
glfminh 0 Posted May 18, 2011 Author Report Share Posted May 18, 2011 I want it to be append new node into XML file by JSP, can you help me? Quote Link to post Share on other sites
jeffman 86 Posted May 18, 2011 Report Share Posted May 18, 2011 You may have to be patient. We only have a few JSP users on the board. Quote Link to post Share on other sites
glfminh 0 Posted May 19, 2011 Author Report Share Posted May 19, 2011 (edited) You may have to be patient. We only have a few JSP users on the board.Ok, I wait, It is so important to me. Edited May 19, 2011 by vtm Quote Link to post Share on other sites
glfminh 0 Posted May 25, 2011 Author Report Share Posted May 25, 2011 Ok, I wait, It is so important to me.Where are everyone? help me Quote Link to post Share on other sites
birbal 168 Posted May 26, 2011 Report Share Posted May 26, 2011 i am not sure ..i think you should try to open a topic in jsp forum (or moving the topic there by mods). the few jsp people who come here probably wont come in this forum. If its PHP you can get helped from here more quickly though. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.