#45315 [Opn]: DOMElement removeChild don't work properly

From: Date: Thu, 19 Jun 2008 13:59:53 +0000
Subject: #45315 [Opn]: DOMElement removeChild don't work properly
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-125890@lists.php.net to get a copy of this message
ID: 45315 User updated by: bigben3333 at gmail dot com Reported By: bigben3333 at gmail dot com Status: Open Bug Type: DOM XML related Operating System: Linux PHP Version: 5.2.6 New Comment: error in the bug description Previous Comments: ------------------------------------------------------------------------ [2008-06-19 13:55:45] bigben3333 at gmail dot com Description: ------------ When i try to delete <li> nodes by removeChild, it delete the </li> too and i think it's anormal. If i add a space before the a tag, there is no problem. Reproduce code: --------------- <?php $html = '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> <html><body> <ul> <li><a href="link1.php">ITEM 1</a></li> <li><a href="link2.php">ITEM 2</a></li> </ul> </body></html>'; $doc = new DOMDocument(); $doc->loadHTML($html); while ($nd = $doc->getElementsByTagName('a')->item(0)) $nd->parentNode->removeChild($nd); echo $doc->saveHTML(); Expected result: ---------------- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> <html><body> <ul> <li></li> <li></li> </ul> </body></html> Actual result: -------------- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> <html><body> <ul> <li> <li> </ul> </body></html> ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=45315&edit=1

« previous php.bugs (#125890) next »