#31071 [NEW]: DOMNodeList->item(int index) always returns first element
| From: | claudio dot bertoli at gmail dot com | Date: | Mon, 13 Dec 2004 14:33:53 +0000 |
| Subject: | #31071 [NEW]: DOMNodeList->item(int index) always returns first element | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-70151@lists.php.net to get a copy of this message | ||
From: claudio dot bertoli at gmail dot com
Operating system: Linux (not checked on other)
PHP version: 5.0.2
PHP Bug Type: DOM XML related
Bug description: DOMNodeList->item(int index) always returns first element
Description:
------------
DOMNodeList->item(int index) always returns first element in the list.
I tried to cycle over childNodes, using a for cycle: it finds the correct
child count, but always gets first item!
I tried on this xml:
<?xml version="1.0"?>
<root><child
id="1">value 1</child><child
id="2">value 2</child><child
id="3">value 3</child><child
id="4">value 4</child></root>
Reproduce code:
---------------
<pre><?php
$domdoc = new DOMDocument();
//$domdoc->
$domdoc->load("test.xml");
$domdoc->normalize();
$root = $domdoc->getElementsByTagName("root")->item(0);
echo wordwrap(htmlentities($domdoc->saveXML()))."\n------\n";
$nodeList = $root->childNodes;
$childrenCount = $nodeList->length;
echo "\tchildren count: ".$childrenCount."\n";
for ($i = 0; $i < $childrenCount; $i++)
{
$_tmp_node = $nodeList->item($i);
echo $i."\t";
echo $_tmp_node->tagName."\t";
echo $_tmp_node->getAttribute("id")."\t";
echo $_tmp_node->nodeValue."\n";
}
?></pre>
Expected result:
----------------
<?xml version="1.0"?>
<root><child id="1">value 1</child><child
id="2">value 2</child><child
id="3">value 3</child><child
id="4">value 4</child></root>
------
children count: 4
0 child 1 value 1
1 child 2 value 2
2 child 3 value 3
3 child 4 value 4
Actual result:
--------------
<?xml version="1.0"?>
<root><child id="1">value 1</child><child
id="2">value 2</child><child
id="3">value 3</child><child
id="4">value 4</child></root>
------
children count: 4
0 child 1 value 1
1 child 1 value 1
2 child 1 value 1
3 child 1 value 1
--
Edit bug report at http://bugs.php.net/?id=31071&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=31071&r=trysnapshot4
Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=31071&r=trysnapshot50
Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=31071&r=trysnapshot51
Fixed in CVS: http://bugs.php.net/fix.php?id=31071&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=31071&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=31071&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=31071&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=31071&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=31071&r=support
Expected behavior: http://bugs.php.net/fix.php?id=31071&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=31071&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=31071&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=31071&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=31071&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=31071&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=31071&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=31071&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=31071&r=float
MySQL Configuration Error: http://bugs.php.net/fix.php?id=31071&r=mysqlcfg