From: [EMAIL PROTECTED]
Operating system: Mac OS X 10.2.2
PHP version: 4CVS-2002-11-26 (stable)
PHP Bug Type: DOM XML related
Bug description: DomElement->get_elements_by_tagname() doesn't work
It looks like DomElement->get_elements_by_tagname() should work like
DomDocument->get_elements_by_tagname() but returns nothing:
<?php
header("Content-Type: text/plain");
$src = <<< _END
<html>
<head><title> Test </title></head>
<body>
<h1>Test</h1>
<ul>
<li>foo</li>
<li>bar</li>
</ul>
</body>
</html>
_END;
$doc = domxml_open_mem($src);
$n = $doc->get_elements_by_tagname("li");
print get_class($doc) . "->get_elements_by_tagname:\n";
print_r($n);
$ctx = $doc->xpath_new_context();
$Bodies = $doc->get_elements_by_tagname("body");
foreach ($Bodies as $Body) {
print get_class($Body) . "->get_elements_by_tagname:\n";
print_r($Body->get_elements_by_tagname("li"));
$xp = getXPath($Body) . "/*/li";
print get_class($ctx) . " xpath ($xp):\n";
$res = $ctx->xpath_eval($xp);
print_r($res->nodeset);
}
function getXPath($node) {
/* node id is held in a property named '1', this is
illegal in php so we use a workaround */
$one = '1';
$xpath = '';
while ($parent = $node->parent_node()) {
$siblings = $parent->child_nodes();
$index = 1;
foreach ($siblings as $sibling) {
if ($sibling->type != XML_ELEMENT_NODE || $sibling->tagname !=
$node->tagname) continue;
if ($sibling->$one == $node->$one) {
$xpath = '/' . $node->tagname . '[' . $index .
']' . $xpath;
break;
}
$index++;
}
$node = $parent;
}
return $xpath;
}
?>
returns
domdocument->get_elements_by_tagname:
Array
(
[0] => domelement Object
(
[type] => 1
[tagname] => li
[0] => 3
[1] => 1985152
)
[1] => domelement Object
(
[type] => 1
[tagname] => li
[0] => 4
[1] => 2523424
)
)
domelement->get_elements_by_tagname:
Array
(
)
XPathContext xpath (/html[1]/body[1]/*/li):
Array
(
[0] => domelement Object
(
[type] => 1
[tagname] => li
[0] => 3
[1] => 1985152
)
[1] => domelement Object
(
[type] => 1
[tagname] => li
[0] => 4
[1] => 2523424
)
)
--
Edit bug report at http://bugs.php.net/?id=20639&edit=1
--
Try a CVS snapshot: http://bugs.php.net/fix.php?id=20639&r=trysnapshot
Fixed in CVS: http://bugs.php.net/fix.php?id=20639&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=20639&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=20639&r=needtrace
Try newer version: http://bugs.php.net/fix.php?id=20639&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=20639&r=support
Expected behavior: http://bugs.php.net/fix.php?id=20639&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=20639&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=20639&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=20639&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=20639&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=20639&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=20639&r=isapi