I have an XML file - for example:
<slideshow>
<image src="myPhotos/1.jpg" desc="Sample" />
<image src="myPhotos/2.jpg" desc="Sample" />
<image src="myPhotos/3.jpg" desc="Sample" />
<image src="myPhotos/4.jpg" desc="This is image 4" />
<image src="myPhotos/5.jpg" desc="This is image 5" />
<image src="myPhotos/6.jpg" desc="This is image 6" />
<image src="myPhotos/7.jpg" desc="This is image 7" />
<image src="myPhotos/8.jpg" desc="This is image 8" />
</slideshow>
Alright, so what I need help with is (without explaining my whole project). I want PHP to find a child node in an XML file by it's attribute and that attribute is "src".
Then once it finds the correct attribute - then I need to jump to the "desc"
in the same child though! and only change the "desc" attribute.
I have this working with the code below - but the only issue is that if my attribute values are the same, it changes all the "desc".
<?php
$currentTextHeading = $_POST['currentTextHeading'];
$newTextHeading = $_POST['newTextHeading'];
$dom = new DomDocument;
$dom->load('myPhotos.xml');
$xpath = new DomXPath($dom);
$cAttribs = $xpath->query('//*[@desc= "'.$currentTextHeading.'"]');
foreach ($cAttribs as $entry) {
$entry->setAttribute('desc', $newTextHeading);
}
$dom->save('myPhotos.xml');
header('Location: ' . $_SERVER['HTTP_REFERER']);
die();
?>
I want to first look for the "src" attribute because that attribute will always be unique, then change the "desc" of that child and only that one!
The user will be changing these "attributes" by a html text form.