bakunin Posted July 4, 2009 Share Posted July 4, 2009 Im trying to delete an xml node by using an "ID" attribute, here is my code:XML: <?xml version="1.0" encoding="UTF-8"?><ROOT> <object id="7"> test </object></ROOT> JS: var xmlDoc= new ActiveXObject("Microsoft.XMLDOM");xmlDoc.load("books.xml");var id = 7;var path = "//object[@id[text()='" + id + "']]"; // result: //object[@id='7'] node = xmlDoc.selectSingleNode(path);xmlDoc.documentElement.removeChild(node); xmlDoc.SaveXML("books.xml"); What am i doing wrong ? Link to comment Share on other sites More sharing options...
Ingolme Posted July 4, 2009 Share Posted July 4, 2009 The node is being deleted just fine, but Javascript does not modify files, so it's not putting the DOM tree back into the XML file. Link to comment Share on other sites More sharing options...
bakunin Posted July 4, 2009 Author Share Posted July 4, 2009 Its client side so it can't edit something on the server it make sens i was trying to do something that can't be done. In other word evry time i want to modify the file i will have to use php and refresh the page. Link to comment Share on other sites More sharing options...
boen_robot Posted July 5, 2009 Share Posted July 5, 2009 In other word evry time i want to modify the file i will have to use php and refresh the page.Not exactly. Even though the changes can't be saved to a file, the modified XML can be used within that same JavaScript that modified it. Therefore, you don't have to refresh the page to see the result. In fact, if you refresh the page, you will loose all changes, since they weren't saved to a file.If you wish to keep the changes from one refresh to another, you'll have to either do it upon page load with PHP, or make an XMLHttpRequest with JavaScript (which is pretty much the same thing, only it happens via JavaScript, and not by a user activating a link). Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.