Change XML node element value in PHP and save file.
Posted
by Hannes
on Stack Overflow
See other posts from Stack Overflow
or by Hannes
Published on 2010-06-02T10:01:34Z
Indexed on
2010/06/02
10:03 UTC
Read the original article
Hit count: 195
<testimonials>
<testimonial id="4c050652f0c3e">
<nimi>John</nimi>
<email>[email protected]</email>
<text>Some text</text>
<active>1</active>
</testimonial>
<testimonial id="4c05085e1cd4f">
<name>ats</name>
<email>[email protected]</email>
<text>Great site!</text>
<active>0</akctive>
</testimonial>
</testimonials>
I have this XML strcuture and i need to find a testimonial with specific id and change its value and save file. I have a PHP script deleting specific testimonial according its ID:
<?php
$xmlFile = file_get_contents('test.xml');
$xml = new SimpleXMLElement($xmlFile);
$kust_id = $_GET["id"];
foreach($xml->testimonial as $story) {
if($story['id'] == $kust_id) {
$dom=dom_import_simplexml($story);
$dom->parentNode->removeChild($dom);
$xml->asXML('test.xml');
header("Location: newfile.php");
}
}
?>
© Stack Overflow or respective owner