Jump to content

I can not add node into file XML


glfminh
 Share

Recommended Posts

-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 by vtm
Link to comment
Share on other sites

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

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

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...