getElementsByTagName returns subset if elements are arbitrarily nested

[email protected] ("Philip Fletcher") Mon, 8 Dec 2003 15:57:19 -0000 (GMT)
Newsgroups php.xml.dev
Message-ID <[email protected]>
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