ID: 49835
User updated by: vtap at club-internet dot fr
Reported By: vtap at club-internet dot fr
Status: Open
Bug Type: DOM XML related
Operating System: Windows 7 RTM
PHP Version: 5.3.0
New Comment:
Found a bypass solution :
$query = "//body";
foreach ($xpath -> query($query) as $element) {
$names = array();
foreach ($element -> attributes as $attribute) {
$names[] = $attribute -> name;
}
foreach ($names as $name) {
$element -> removeAttribute($name);
}
}
ugly but it works...
Previous Comments:
------------------------------------------------------------------------
[2009-10-10 23:55:23] vtap at club-internet dot fr
Description:
------------
Trying to remove all attributes of the <body> tag in an HTML file.
1/ Just counting : count is always equal to 1 whatever the real number
of attributes is (varying from 0 to 3) though the name function
retrieves all entries
2/ Removing : count is always equal to 1, only the first attribute is
removed and breaks the loop, showing only the first one. Tried
removeAttribute and removeAttributenode
Reproduce code:
---------------
$html = new DOMDocument();
$html -> loadHTMLFile("mypath\\myfile.html");
//Recherche du body et suppression de tous ses attributs
$xpath = new DOMXPath($html);
$query = "//body";
foreach ($xpath -> query($query) as $node) {
echo "Count before = " .
count($node-> attributes) .
"<br />";
foreach ($node-> attributes as $attribute) {
// $node-> removeAttributenode($attribute);
echo "$attribute->name <br />";
// $node-> removeAttribute($attribute -> name);
}
echo "Count after = " .
count($node-> attributes) .
"<br />";
}
Expected result:
----------------
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
displays (just counting)
Count before = 1
bgcolor
text
Count after= 1
displays (removing)
Count before = 1
bgcolor
Count after= 1
and gives
<body text="#000000">
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=49835&edit=1