From: winner5 at interia dot pl
Operating system: Linux
PHP version: 5.2.11
PHP Bug Type: DOM XML related
Bug description: DOMXPath caanot find anything without thw namespace specified.
Description:
------------
DOMXPath do not find anything, like it should due to php.net online guide,
it requires to registerNamespace in DOMXPath
Reproduce code:
---------------
<?php
$dom = new DOMDocument();
$dom->loadXML('<?xml version="1.0" encoding="utf-8"
standalone="no"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html
xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
dir="ltr"><head><title>Title</title></head><body><div><div
id="read"><p>This</p></div></div></body></html>');
header('Content-Type: application/xhtml+xml; charset="utf-8"');
$xpath = new DOMXPath($dom);
$nodelist = $xpath->query('/html/body/div/d...@id=\'read\'][1]');
$root = $nodelist->item(0);
$root->appendChild($dom->createElement('p', $root->nodeName));
print($dom->saveXML());
?>
Expected result:
----------------
Just the same as:
<?php
$dom = new DOMDocument();
$dom->loadXML('<?xml version="1.0" encoding="utf-8"
standalone="no"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html
xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
dir="ltr"><head><title>Title</title></head><body><div><div
id="read"><p>This</p></div></div></body></html>');
header('Content-Type: application/xhtml+xml; charset="utf-8"');
$xpath = new DOMXPath($dom);
$xpath->registerNamespace('x', $dom->documentElement->namespaceURI);
$nodelist =
$xpath->query('/x:html/x:body/x:div/x:d...@id=\'read\'][1]');
$root = $nodelist->item(0);
$root->appendChild($dom->createElement('p', $root->nodeName));
print($dom->saveXML());
?>
Actual result:
--------------
Fatal error: Call to a member function appendChild() on a non-object in
./index.php on line 10
--
Edit bug report at http://bugs.php.net/?id=50325&edit=1
--
Try a snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=50325&r=trysnapshot52
Try a snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=50325&r=trysnapshot53
Try a snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=50325&r=trysnapshot60
Fixed in SVN:
http://bugs.php.net/fix.php?id=50325&r=fixed
Fixed in SVN and need be documented:
http://bugs.php.net/fix.php?id=50325&r=needdocs
Fixed in release:
http://bugs.php.net/fix.php?id=50325&r=alreadyfixed
Need backtrace:
http://bugs.php.net/fix.php?id=50325&r=needtrace
Need Reproduce Script:
http://bugs.php.net/fix.php?id=50325&r=needscript
Try newer version:
http://bugs.php.net/fix.php?id=50325&r=oldversion
Not developer issue:
http://bugs.php.net/fix.php?id=50325&r=support
Expected behavior:
http://bugs.php.net/fix.php?id=50325&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=50325&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=50325&r=submittedtwice
register_globals:
http://bugs.php.net/fix.php?id=50325&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=50325&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=50325&r=dst
IIS Stability:
http://bugs.php.net/fix.php?id=50325&r=isapi
Install GNU Sed:
http://bugs.php.net/fix.php?id=50325&r=gnused
Floating point limitations:
http://bugs.php.net/fix.php?id=50325&r=float
No Zend Extensions:
http://bugs.php.net/fix.php?id=50325&r=nozend
MySQL Configuration Error:
http://bugs.php.net/fix.php?id=50325&r=mysqlcfg