Jump to content

I can not add node into file XML


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 post
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 post
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 post
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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...