Reputation: 2339
my xml file:
<temporary>
<users>
<temp>
<id>1</id>
<title> Undercover</title>
<author>Wiwit</author>
</temp>
<nissi>
<confirm>3977678bce8515e8cdbfa64850904ad1</confirm>
<firstname>hi</firstname>
<lastname>hhey</lastname>
<day>1</day>
</nissi>
</users>
</temporary>
my php:
<?php
$user="nissi";
$xml = simplexml_load_file("temporary.xml")
or die("Error: Cannot create object");
unset($xml->temporary->users->$user);
?>
Why is this not working. The unset is not working.The node ins'nt getting deleted.
Upvotes: 0
Views: 2899
Reputation: 10219
It works like this :
$user="nissi";
$xml = simplexml_load_file("temporary.xml")
or die("Error: Cannot create object");
unset($xml->users->$user);
echo $xml->asXML();
You mustn't take the root of your xml in the "request" temporary
here.
Upvotes: 3
Reputation: 42040
You cannot do it with SimpleXML alone, you have to use DOMElement conversion as explained here:
Remove a child with a specific attribute, in SimpleXML for PHP
Upvotes: -1