getElementsByTagName returns subset if elements are arbitrarily nested

From: Date: Mon, 08 Dec 2003 15:57:19 +0000
Subject: getElementsByTagName returns subset if elements are arbitrarily nested
Groups: php.xml.dev 
Request: Send a blank email to php-xml-dev+get-263@lists.php.net to get a copy of this message
Hi According to the w3c spec the method 'getElementsByTagName' "returns a NodeList of all the Elements in document order with a given tag name and arecontained in the document". However, in practice, if there is some interesting (but legal) nesting going on, then everything outside of the parent of the first match is ignored. eg: $dom = new DomDocument(); $xml = '<a name="a1"> <b name="b1"> <c name="c1"> </c> </b> <c name="c2"> </c> <c name="c3"> </c> </a>'; $dom->loadXml($xml); foreach($dom->getElementsByTagName('c') as $elem ) { echo $elem->getAttribute('name'); } Will return only c1. If the closing </b> is moved below the closing of "c2", then c1c2 will be returned. This is not what I'd expect (I would like 'c1c2c3' as per xpath query '//c' ) - have I misinterpreted the w3c spec? Regards Philip

« previous php.xml.dev (#263) next »