#39593 [NEW]: XPath NodeList: "Couldn't fetch DOMElement: Node no longer exists"
| From: | dave dot lane at gmx dot net | Date: | Wed, 22 Nov 2006 17:54:18 +0000 |
| Subject: | #39593 [NEW]: XPath NodeList: "Couldn't fetch DOMElement: Node no longer exists" | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-105322@lists.php.net to get a copy of this message | ||
From: dave dot lane at gmx dot net
Operating system: Linux
PHP version: 5.2.0
PHP Bug Type: DOM XML related
Bug description: XPath NodeList: "Couldn't fetch DOMElement: Node no longer exists"
Description:
------------
The following code does not work. When the nodes in a NodeList that is the
result of an XPath query are copied into an array and returned from a
function. When the nodes in the array are used a warning results:
"Couldn't fetch DOMElement. Node no longer exists..."
Reproduce code:
---------------
bug.php:
<?
$DOMMain =& OpenXMLDoc('main.xml');
$aArray =& GetArray($DOMMain);
echo 'After return: '.$aArray[0]->localName->localName."<br>\n";
function &OpenXMLDoc($sFileName) {
$DOM = new DOMDocument();
$DOM->preserveWhiteSpace = false;
$DOM->load($sFileName);
return $DOM;
}
function &ExecuteXPath($sXPath, DOMDocument &$DOMDocument, DOMNode
&$DOMNode) {
$objXPath = new DOMXPath($DOMDocument);
return $objXPath->query($sXPath, $DOMNode);
}
function &GetArray(&$DOMMain) {
$DOMInclude =& OpenXMLDoc('include.xml');
$NodeImported = $DOMMain->importNode($DOMInclude->documentElement,
true);
$NodeListImported =& ExecuteXPath('./include1', $DOMMain,
$NodeImported);
$NodeListImported = $NodeListImported->item(0)->childNodes;
echo 'In NodeList:
'.$NodeListImported->item(0)->localName."<br>\n";
$aArray = array();
foreach($NodeListImported as $Node) {
$aArray[] = $Node;
}
echo 'In Array: '.$aArray[0]->localName."<br>\n";
return $aArray;
}
?>
main.xml:
<?xml version = "1.0" encoding="ISO-8859-1"?>
<root>
</root>
include.xml:
<?xml version = "1.0" encoding="ISO-8859-1"?>
<include>
<include1>
<div>
<span>test</span>
</div>
</include1>
</include>
Expected result:
----------------
In NodeList: div
In Array: div
After return: div
Actual result:
--------------
In NodeList: div
In Array: div
Warning: Couldn't fetch DOMElement. Node no longer exists in
/var/www/html/usr/dla/csc/V2/bug/bug.php on line 5
After return:
--
Edit bug report at http://bugs.php.net/?id=39593&edit=1
--
Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=39593&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=39593&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=39593&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=39593&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=39593&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=39593&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=39593&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=39593&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=39593&r=support
Expected behavior: http://bugs.php.net/fix.php?id=39593&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=39593&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=39593&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=39593&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=39593&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=39593&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=39593&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=39593&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=39593&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=39593&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=39593&r=mysqlcfg