|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2007-08-27 10:29 UTC] jani@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 02 17:00:02 2025 UTC |
Description: ------------ Elements of the array returned by xpath() cannot be deleted. I can change those elements, but deleting is impossible. How can I delete a node returned by xpath()? Is there a way to find out where the node I found is within the whole xml tree? Thanks, G?nther. Reproduce code: --------------- <?php $xmlstr = <<<XML <?xml version='1.0' standalone='yes'?> <root> <movie>Movie One</movie> <movie>Movie Two</movie> </root> XML; $xml = new SimpleXMLElement($xmlstr); $movs = $xml->xpath('//movie'); // Trying to delete the reference returned by xpath unset($movs[0]); // $movs[0] = NULL; doesn't work either // No changes echo $xml->asXML(); ?> Expected result: ---------------- <?xml version="1.0" standalone="yes"?> <root> <movie>Movie Two</movie> </root> Actual result: -------------- <?xml version="1.0" standalone="yes"?> <root> <movie>Movie One</movie> <movie>Movie Two</movie> </root>