ID: 31071
User updated by: claudio dot bertoli at gmail dot com
Reported By: claudio dot bertoli at gmail dot com
-Status: Feedback
+Status: Open
Bug Type: DOM XML related
Operating System: Linux (not checked on other)
PHP Version: 5.0.2
New Comment:
sorry, back to work only today ^^;
from phpinfo():
libxml Version 2.5.10
Previous Comments:
------------------------------------------------------------------------
[2004-12-14 10:21:04] [EMAIL PROTECTED]
Works for me
which libxml2 version are you using?
------------------------------------------------------------------------
[2004-12-13 15:33:52] claudio dot bertoli at gmail dot com
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 this bug report at http://bugs.php.net/?id=31071&edit=1