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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: peter at wingercom dot net
New email:
PHP Version: OS:

 

 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2019 The PHP Group
All rights reserved.
Last updated: Wed Nov 13 14:01:29 2019 UTC