|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2009-07-14 14:53 UTC] piotr dot baranowski at zeno dot pl
Description: ------------ Just as in the title. There's no way now to delete XML node in SimpleXML. It would be nice to have SimpleXML method that would delete given node. Reproduce code: --------------- --- From manual page: book.simplexml --- PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Dec 03 23:00:01 2025 UTC |
Sorry, i forgot to write that this is about nodes selected by xpath ;-) Yeah, i know, so lame of me. <?php $xml = simplexml_load_string('<?xml version="1.0" encoding="UTF-8"?> <root> <recipes> <recipe> <id>1</id> </recipe> <recipe> <id>2</id> </recipe> </recipes> </root>'); print_r($xml); $node = $xml->xpath('recipes/recipe[id="1"]'); $foo = &$node[0]; unset($node[0]); $node[0] = null; unset($foo); $foo = null; print_r($xml); ?> print_r gives same result before and after unset or setting node to null. It's because only the reference, not content of reference, is unset(). There's no way to delete (or no way that i could thought about) to delete node selected by xpath.