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
 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 06:01:29 2024 UTC