#27709 [NEW]: SimpleXML xpath function doesn't like default namespaces

From: Date: Fri, 26 Mar 2004 09:51:30 +0000
Subject: #27709 [NEW]: SimpleXML xpath function doesn't like default namespaces
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-56861@lists.php.net to get a copy of this message
From:             fjortiz at comunet dot es
Operating system: Windows 2000 Server
PHP version:      5.0.0RC1
PHP Bug Type:     SimpleXML related
Bug description:  SimpleXML xpath function doesn't like default namespaces

Description:
------------
Hi,

this example works with SimpleXML xpath:

$string = <<<XML
<?xml version="1.0" encoding ="UTF-8" ?>
<a xmlns:ns="urn:1">
 <b>
  <c>text</c>
  <c>stuff</c>
 </b>
 <d>
  <c>code</c>
 </d>
</a>
XML;

$xml = simplexml_load_string($string);
$res = $xml->xpath('//a'); // returns array(1)

But if we don't use a namespace prefix (default namespace), xpath, returns
an empty array, array(0), for any xpath search:

$string = <<<XML
<?xml version="1.0" encoding ="UTF-8" ?>
<a xmlns="urn:1">
 <b>
  <c>text</c>
  <c>stuff</c>
 </b>
 <d>
  <c>code</c>
 </d>
</a>
XML;

$xml = simplexml_load_string($string);
$res = $xml->xpath('//a'); // returns array(0)

This is a simple example, I found the problem with a bigger XML file (a
WSDL file). This WSDL has 5 namespaces defined, and no problem at all with
SimpleXML, as long as you don't define a default namespace...

Thanks for your attention




-- 
Edit bug report at http://bugs.php.net/?id=27709&edit=1
-- 
Try a CVS snapshot (php4):  http://bugs.php.net/fix.php?id=27709&r=trysnapshot4
Try a CVS snapshot (php5):  http://bugs.php.net/fix.php?id=27709&r=trysnapshot5
Fixed in CVS:               http://bugs.php.net/fix.php?id=27709&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=27709&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=27709&r=needtrace
Need Reproduce Script:      http://bugs.php.net/fix.php?id=27709&r=needscript
Try newer version:          http://bugs.php.net/fix.php?id=27709&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=27709&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=27709&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=27709&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=27709&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=27709&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=27709&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=27709&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=27709&r=isapi
Install GNU Sed:            http://bugs.php.net/fix.php?id=27709&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=27709&r=float


Thread (5 messages)

« previous php.bugs (#56861) next »