ID: 46265
Updated by: [EMAIL PROTECTED]
Reported By: josh at coady dot us
-Status: Open
+Status: Wont fix
Bug Type: DOM XML related
Operating System: ubuntu 8.04.1
PHP Version: 5.2.6
New Comment:
Just check, if it has a parentNode. If it has, it does exist, if it
doesn't, it does not exist in the tree.
Previous Comments:
------------------------------------------------------------------------
[2008-10-09 19:23:16] josh at coady dot us
reproduce code should be the following (I realized the code wasnt
duplicating the exact situation I was encountering, so I modified it to
better match)
$doc =
DOMDocument::loadXML('<doc><x><a>1</a></x><x><a>1</a><y><a>1</a><a>0</a></y></x></doc>');
$nodes = $doc->getElementsByTagName('a');
$nodesToRemove = array();
foreach($nodes as $node)
{
if($node->nodeValue == 1)
{
$nodesToRemove[] = $node;
}
}
foreach($nodesToRemove as $node)
{
$node->parentNode->parentNode->removeChild($node->parentNode);
}
------------------------------------------------------------------------
[2008-10-09 19:17:38] josh at coady dot us
Description:
------------
DOMNode should have a property like $exists to check if the node still
exists. This would be useful to avoid the "Node no longer exists"
warning.
We should be able to do something like
$node->parentNode->removeChild($node);
if($node->exists)
{
// use node ..
}
Reproduce code:
---------------
$doc =
DOMDocument::loadXML('<doc><x><a>1</a></x><x><a>1</a><y><a>1</a><a>0</a></y></x></doc>');
$nodes = $doc->getElementsByTagName('a');
$nodesToRemove = array();
foreach($nodes as $node)
{
if($node->nodeValue == 1)
{
$nodesToRemove[] = $node;
$node->parentNode->removeChild($node);
}
}
foreach($nodesToRemove as $node)
{
$node->parentNode->removeChild($node);
}
Expected result:
----------------
This is more of a feature request. I expect to change the last loop to
something like
foreach($nodesToRemove as $node)
{
if($node->exists)
{
$node->parentNode->removeChild($node);
}
}
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=46265&edit=1