| 
        php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             
             [2003-12-29 10:42 UTC] olivier dot bichler at laposte dot net
  [2003-12-29 10:43 UTC] olivier dot bichler at laposte dot net
  [2003-12-29 11:42 UTC] rrichards@php.net
  | 
    |||||||||||||||||||||||||||
            
                 
                Copyright © 2001-2025 The PHP GroupAll rights reserved.  | 
        Last updated: Tue Nov 04 07:00:01 2025 UTC | 
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