#26743 [Opn->Csd]: getElementsByTagName doesn't work properly
| From: | rrichards@php.net | Date: | Mon, 29 Dec 2003 16:42:23 +0000 |
| Subject: | #26743 [Opn->Csd]: getElementsByTagName doesn't work properly | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-52587@lists.php.net to get a copy of this message | ||
ID: 26743
Updated by: rrichards@php.net
Reported By: olivier dot bichler at laposte dot net
-Status: Open
+Status: Closed
Bug Type: *XML functions
Operating System: Windows XP (with SP1)
PHP Version: 5.0.0b2 (beta2)
New Comment:
This bug has been fixed in CVS.
In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at http://snaps.php.net/.
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.
In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
Thank you for the report, and for helping us make PHP better.
Previous Comments:
------------------------------------------------------------------------
[2003-12-29 10:43:58] olivier dot bichler at laposte dot net
I have modified the title...
------------------------------------------------------------------------
[2003-12-29 10:42:32] olivier dot bichler at laposte dot net
Sorry, the name of the function is getElementsByTagName with "s" at
"Element".
------------------------------------------------------------------------
[2003-12-29 10:34:18] olivier dot bichler at laposte dot net
Description:
------------
The DOM function "getElementByTagName" doesn't work properly when it's
call from an element.
The W3C specification say "Returns a NodeList of all DESCENDANT
Elements with a given tag name, in the order in which they are
encountered in a preorder traversal of this Element tree."
But getElementByTagName return ALL elements encountered after the
current element and not only the descendant elements in the tree...
Reproduce code:
---------------
<?php
$xml = '<?xml version="1.0"?>
<config><section id="section1">
<param name="param1">value1</param>
<param name="param2">value2</param>
</section>
<section id="section2">
<param name="param3">value3</param>
</section>
</config>';
$dom = new DomDocument;
$dom -> loadXML($xml);
$params = $dom -> documentElement -> firstChild ->
getElementsByTagName('param');
foreach ($params as $param) {
echo $param -> getAttribute('name').'<br />';
}
?>
Expected result:
----------------
param1
param2
(according with the W3C specifications)
Actual result:
--------------
param1
param2
param3
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=26743&edit=1