php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45315 DOMElement removeChild don't work properly
Submitted: 2008-06-19 13:55 UTC Modified: 2008-06-19 14:42 UTC
From: bigben3333 at gmail dot com Assigned:
Status: Not a bug Package: DOM XML related
PHP Version: 5.2.6 OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: bigben3333 at gmail dot com
New email:
PHP Version: OS:

 

 [2008-06-19 13:55 UTC] 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>

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-06-19 13:59 UTC] bigben3333 at gmail dot com
error in the bug description
 [2008-06-19 14:04 UTC] bigben3333 at gmail dot com
Error in the bug description : It's when i try to delete <a> node, not <li> node.
 [2008-06-19 14:42 UTC] chregu@php.net
use ->saveXML() instead of ->saveHTML() if you want XHTML instead of 
HTML 4.

There is no bug, it's correct behaviour.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Oct 31 23:01:28 2024 UTC