ID:               50325
 User updated by:  winner5 at interia dot pl
 Reported By:      winner5 at interia dot pl
 Status:           Bogus
 Bug Type:         DOM XML related
 Operating System: Linux
 PHP Version:      5.2.11
 New Comment:

Thank you. In php guide actually there was an example without xmlns
defined. My mistake.


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

[2009-11-30 10:19:12] rricha...@php.net

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Default namespaces must always be registered. A prefix is required to 
use namespaces in xpath queries. Not a PHP issue

------------------------------------------------------------------------

[2009-11-29 14:40:11] winner5 at interia dot pl

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

Reply via email to