glfminh Posted May 17, 2011 Share Posted May 17, 2011 -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. Link to comment Share on other sites More sharing options...
jeffman Posted May 17, 2011 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? Link to comment Share on other sites More sharing options...
glfminh Posted May 17, 2011 Author 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? Link to comment Share on other sites More sharing options...
jeffman Posted May 17, 2011 Share Posted May 17, 2011 There are a lot of things that can go wrong. Post the code you are trying to use. Link to comment Share on other sites More sharing options...
packrat Posted May 17, 2011 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. Link to comment Share on other sites More sharing options...
glfminh Posted May 18, 2011 Author 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> Link to comment Share on other sites More sharing options...
glfminh Posted May 18, 2011 Author Share Posted May 18, 2011 I want it to be append new node into XML file by JSP, can you help me? Link to comment Share on other sites More sharing options...
jeffman Posted May 18, 2011 Share Posted May 18, 2011 You may have to be patient. We only have a few JSP users on the board. Link to comment Share on other sites More sharing options...
glfminh Posted May 19, 2011 Author Share Posted May 19, 2011 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. Link to comment Share on other sites More sharing options...
glfminh Posted May 25, 2011 Author Share Posted May 25, 2011 Ok, I wait, It is so important to me.Where are everyone? help me Link to comment Share on other sites More sharing options...
birbal Posted May 26, 2011 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. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.