php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39505 xpath query failed if root element has xmlns attribute
Submitted: 2006-11-13 19:08 UTC Modified: 2006-11-13 20:50 UTC
From: sghnqk at gmail dot com Assigned:
Status: Not a bug Package: DOM XML related
PHP Version: 5.2.0 OS: linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: sghnqk at gmail dot com
New email:
PHP Version: OS:

 

 [2006-11-13 19:08 UTC] sghnqk at gmail dot com
Description:
------------
according to http://www.w3.org/TR/REC-xml-names/ ,
both 
   <root xmlns="...">
and 
   <root xmlns:ns="...">
are valid,

xpath->query() will fail with the first case.


Reproduce code:
---------------
<?php
$xml=<<<end
<?xml version="1.0"?>
<root xmlns="urn:schemas-upnp-org:device-1-0">
<child />
</root>
end;

$doc=new DomDocument();
$doc->loadXML($xml);

$xpath=new DomXpath($doc);

$query='/root';

$result=$xpath->query($query);
echo $result->length;


Expected result:
----------------
string '1'

Actual result:
--------------
string '0'

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-11-13 20:50 UTC] rrichards@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

first case is correct - xpath is namespace aware and root in def ns.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Jul 12 13:01:33 2025 UTC