Remove XML Node With jQuery

il15

New Member
I wonder whether someone may be able yo help me please.I've put together this page which allows users to view a gallery of their uploaded images.Upon initial upload, the physical images are saved in the following file structure:\[code\]UploadedFiles/userid/locationid/image\[/code\] and the details of the image i.e. description etc are saved in an xml file called \[code\]files.xml\[/code\] which is in the same directory as the physical images.I'm now working on allowing the user to be able to delete these images.By way of a deletion icon under each image, I've, admitedly with some help, put together the following which successfully deletes the physical image.'Deletion Icon Onclick Event'\[code\]<script type="text/javascript"> Galleria.ready(function() { this.$('thumblink').click(); $(".galleria-image").append( "<span class='btn-delete ui-icon ui-icon-trash'></span>"); $(".btn-delete").live("click", function(){ var img = $(this).closest(".galleria-image").find("img"); // send the AJAX request $.ajax({ url : 'delete.php', type : 'post', data : { image : img.attr('src') }, success : function(){ alert('Deleting image... '); img.parent().fadeOut('slow'); } }); return false; }); });</script>\[/code\]Original 'delete.php'\[code\]<?phpif (!empty($_POST)) {$image = $_POST['image'];if (file_exists($image)) {unlink($image);} }?>\[/code\]Updated 'delete.php'\[code\]<?phpif (!empty($_POST)) {$image = $_POST['image'];if (file_exists($image)) {unlink($image);} }$doc = new DOMDocument; $doc->load('files.xml'); $thedocument = $doc->documentElement; $list = $thedocument->getElementsByTagName('files'); $nodeToRemove = null; foreach ($list as $domElement){ $attrValue = http://stackoverflow.com/questions/10552309/$domElement->getAttribute('file_name'); if ($attrValue =http://stackoverflow.com/questions/10552309/='image') { $nodeToRemove = $domElement;} } if ($nodeToRemove != null) $thedocument->removeChild($nodeToRemove); echo $doc->saveXML(); ?> \[/code\]The problem I'm having is deleting the xml node form the xml file. I've provided an extract of the XML file below.\[code\] <?xml version="1.0" encoding="utf-8" ?> - <files> <file name="stag.jpg" source="stag.jpg" size="21341" originalname="stag.jpg" description="No description provided" userid="1" locationid="1" /> </files>\[/code\]I've done quite a bit of research about how to go about this and found that jQuery had it's own command i.e. \[code\]jQuery.remove\[/code\] which I thought would be able to delete the node. Following the brief tutorial I added the following to the end of my 'Onclick Event' script:\[code\]var doc = $(files.xml);doc.find('file_name:src').remove();\[/code\]Unfortunately, although I don't receive a specific error, the node isn't being deleted from the file. I'm a complete beginner when it comes to XML so perhaps I'm looking at this too simplistically.I just wondered wheteher someone could perhaps have a look at this please and let me know where I'm going wrong.Many thanks and regards
 
Back
Top