ID:               20639
 Updated by:       [EMAIL PROTECTED]
 Reported By:      [EMAIL PROTECTED]
-Status:           Open
+Status:           Closed
 Bug Type:         DOM XML related
 Operating System: Mac OS X 10.2.2
 PHP Version:      4CVS-2002-11-26 (stable)
 New Comment:

This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at http://snaps.php.net/.
 
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.

In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
 
Thank you for the report, and for helping us make PHP better.




Previous Comments:
------------------------------------------------------------------------

[2002-11-26 02:34:49] [EMAIL PROTECTED]

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 this bug report at http://bugs.php.net/?id=20639&edit=1

Reply via email to