Reputation: 2277
I want to remove the whole sticker node by calling the id 100. But nothing happens really. Any idea ?
$xml = new DOMDocument();
$xml->load('../write.xml');
$result = $xpath->query('/stickers/sticker[id="100"]');
$result->childNodes->item(0)->parentNode->removeChild($result->childNodes->item(0));
$xml->save('../write.xml');
<stickers>
<sticker> /* Remove */
<text>Thaishi1</text>
<id>100</id>
</sticker>
<sticker>
</position>
<text>Thaishi2</text>
<id>200</id>
</sticker>
</stickers>
Upvotes: 0
Views: 190
Reputation: 96325
If “nothing happens”, configure your error_reporting to a sensible debugging level – you should get warnings that there is no ->childNodes
property.
$result->item(0)->parentNode->removeChild($result->item(0));
This should work.
Upvotes: 1