I wonder whether someone may be able to help please.

I've put together this page http://www.mapmyfinds.co.uk/development/deletetest.php which allows users to view a gallery of their uploaded images.

Upon upload, each physical image is saved in the following file structure:
The image details i.e description, filename etc are saved in an XML file called 'files.xml' which is in the same location as the images. An extract of which can be seen below.

 <?xml version="1.0" encoding="utf-8" ?> 
- <files>
  <file name="_47061196_greatbritainjpg.jpg" source="_47061196_greatbritainjpg.jpg" size="227505" originalname="_47061196_greatbritainjpg.jpg" description="No description provided" userid="1" locationid="1" /> 
  <file name="stag.jpg" source="stag.jpg" size="21341" originalname="stag.jpg" description="No description provided" userid="1" locationid="1" /> 
You will see under each image there is an icon which allows the user to delete the image. This done via the following:

Icon Click Event

<script type="text/javascript"> 
		Galleria.ready(function() {

		"<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
		url : 'delete.php',
		type : 'post',
		data : { image : img.attr('src') },
		success : function(){
		alert('Deleting image... ');

		return false;


PHP Code:

if (!empty($_POST)) { 
$image $_POST['image']; 

if (
file_exists($image)) { 

$doc = new DOMDocument

$thedocument $doc->documentElement

$list $thedocument->getElementsByTagName('files'); 

$nodeToRemove null
foreach (
$list as $domElement){ 
$attrValue $domElement->getAttribute('file_name'); 
if (
$attrValue == 'image') { 
$nodeToRemove $domElement

if (
$nodeToRemove != null

With this, I can succesfully delete the physical image, but what I'm having great difficulty in doing is deleting the corresponding child node in the XML file.

I really quite new to dealing with XML but I've been working on this for weeks now, and I'm still no further forward.

I just wondered whether someone could perhaps have a look at this please and let me know where I'm going wrong.

Many thanks and regards