ID: 37957 User updated by: jfowlie at navarik dot com Reported By: jfowlie at navarik dot com Status: Closed Bug Type: DOM XML related Operating System: Linux PHP Version: 5.1.4 New Comment:
In case anyone wants a workaround... Check that a node hasChildNodes and that the firstChild->nodeType is XML_TEXT_NODE. Then you can just set the value of the node with firstChild->nodeValue I.e. change the foreach loop in the reproduce code to: foreach($bookmarks as $bookmark_node){ ++$count; $id_value = $bookmark_node->getAttribute('id'); print "Id value: ".$id_value."<br />\n"; if ($bookmark_node->hasChildNodes() && $bookmark_node->firstChild->nodeType == XML_TEXT_NODE) { print "Node value: ".$bookmark_node->firstChild->nodeValue."<br />\n"; print "Setting nodeValue to 'test$count'<br />\n"; $bookmark_node->firstChild->nodeValue = 'test'.$count; print "Node value has been set! ({$bookmark_node->firstChild->nodeValue})<hr />\n"; } } Previous Comments: ------------------------------------------------------------------------ [2006-07-06 19:42:23] [EMAIL PROTECTED] It'll be ready when it's ready. ------------------------------------------------------------------------ [2006-07-06 19:32:38] jfowlie at navarik dot com Thanks. The CVS snapshot for v5.2 has fixed the issue. Any word on when this version will become the official release? i.e. production ready? I can't use a development version of php on our production servers... Cheers ------------------------------------------------------------------------ [2006-06-29 08:19:59] [EMAIL PROTECTED] Please try using this CVS snapshot: http://snaps.php.net/php5.2-latest.tar.gz For Windows: http://snaps.php.net/win32/php5.2-win32-latest.zip Can't reproduce. ------------------------------------------------------------------------ [2006-06-29 06:16:51] jfowlie at navarik dot com Description: ------------ I was attempting to update the content of some anchor elements by setting the nodeValue. It doesn't seem to matter how high I set the max_execution_time limit, if there is a entity in the nodeValue, PHP just hangs until it times out. (It works just fine with & though...) Reproduce code: --------------- <?php $xhtml = <<<XHTML <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Untitled</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> </head> <body> <a href="#" id="id-goes-here">Link 1</a> <a href="#" id="id-2-goes-here">Link 2 &</a> <a href="#" id="id-3-goes-here">Link 3 </a> </body> </html> XHTML; $dom = new DOMDocument('1.0','iso-8859-1'); // I tried it with this set to true or false //$xml->preserveWhiteSpace = FALSE; // You need this, otherwise the nbsp entity is not valid $dom->resolveExternals = TRUE; $dom->loadXML($xhtml); $bookmarks = $dom->getElementsByTagName('a'); $count = 0; foreach($bookmarks as $bookmark_node){ ++$count; $id_value = $bookmark_node->getAttribute('id'); print "Id value: ".$id_value."<br />"; print "Node value: ".$bookmark_node->nodeValue."<br />"; print "Setting nodeValue to 'test$count'<br />"; $bookmark_node->nodeValue = 'test'.$count; print "Node value has been set! ({$bookmark_node->nodeValue})<hr />"; } ?> Expected result: ---------------- Id value: id-goes-here Node value: Link 1 Setting nodeValue to 'test1' Node value has been set! (test1) Id value: id-2-goes-here Node value: Link 2 & Setting nodeValue to 'test2' Node value has been set! (test2) Id value: id-3-goes-here Node value: Link 3 Setting nodeValue to 'test3' Node value has been set! (test3) Actual result: -------------- Id value: id-goes-here Node value: Link 1 Setting nodeValue to 'test1' Node value has been set! (test1) Id value: id-2-goes-here Node value: Link 2 & Setting nodeValue to 'test2' Node value has been set! (test2) Id value: id-3-goes-here Node value: Link 3 Setting nodeValue to 'test3' Fatal error: Maximum execution time of 30 seconds exceeded in nbsp-dom-test.php on line 39 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=37957&edit=1