| 
        php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             
             [2004-12-14 10:21 UTC] chregu@php.net
  [2004-12-20 08:55 UTC] claudio dot bertoli at gmail dot com
  [2004-12-23 15:54 UTC] claudio dot bertoli at gmail dot com
  [2004-12-23 17:30 UTC] chregu@php.net
  | 
    |||||||||||||||||||||||||||
            
                 
                Copyright © 2001-2025 The PHP GroupAll rights reserved.  | 
        Last updated: Tue Nov 04 00:00:01 2025 UTC | 
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