php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #11903 xpath_eval does not work with default namespace.
Submitted: 2001-07-05 08:44 UTC Modified: 2001-11-29 07:42 UTC
From: peter at wingercom dot net Assigned:
Status: Not a bug Package: DOM XML related
PHP Version: 4.0.6 OS: FreeBSD 4.3
Private report: No CVE-ID: None
 [2001-07-05 08:44 UTC] peter at wingercom dot net
Hi, When using default namespace in the XML (XHTML) source 
xpath_eval will not return any result except with the request "//*" whereby it will return the whole XML source.
When making another namespace than "xmlns" everything works fine.

// The xpaht_eval() will NOT work with this line
    $xhtml = '<html xmlns="http://www.w3.org/1999/xhtml"><head><title>hummmm......</title></head><body></body></html>';
    // The xpaht_eval() will work with this line
    $xhtml = '<html BUGxmlns="http://www.w3.org/1999/xhtml"><head><title>hummmm......</title></head><body></body></html>';
   
    $doc = xmldoc($xhtml);
    $ctx = xpath_new_context($doc); 
    $node = xpath_eval_expression($ctx,"//title");
    var_dump($node->nodeset);

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-07-05 08:51 UTC] peter at wingercom dot net
I forgot.

This namespace decleration will also work with xpath_eval
<html xmlns:thisworks="http://www.w3.org/1999/xhtml">
 [2001-07-06 04:44 UTC] peter at wingercom dot net
I forgot again....

libxml version: 2.3.10
iconv version: 2.0
 [2001-11-29 07:42 UTC] mfischer@php.net
This is because title actually *IS* in the namespace. This is how XML and namespace works.

I suggest further reading on
http://www.w3.org/TR/REC-xml-names/
and
http://www.w3.org/TR/xpath#function-local-name

In you're case I'ld use "//*[local-name() = 'title']" instead of "//title"

(thanks to Daniel Veillard pointing this out)

Bogus (not a PHP bug).

PS: thnx anyway, found a segfault in xpath_eval_expression :)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 14:01:32 2024 UTC