ID:               42325
 User updated by:  cpriest at warpmail dot net
 Reported By:      cpriest at warpmail dot net
-Status:           Bogus
+Status:           Open
 Bug Type:         SimpleXML related
 Operating System: Windows
 PHP Version:      5.2.4RC2
 New Comment:

I'm not sure I understand why I would have to call
registerXPathNamespace() to use a default namespace?  I thought one of
the reasons to use SimpleXML was to parse XML documents.

If I make the one default namespace
(xmlns="http://zzz.com/webservices";) a non-default such as xmlns:test=,
then it properly queries the /result value.

To do what you're suggestion I would have to parse the XML document
myself looking for the namespace I would want to query against.

The code below also works if you simply remove the xmlns="" attribute. 
Are you sure that I'm supposed to be using registerXPathNamespace()


Previous Comments:
------------------------------------------------------------------------

[2007-08-17 07:01:04] [EMAIL PROTECTED]

You have to register default namespaces with

http://ch2.php.net/manual/en/function.simplexml-element-
registerXPathNamespace.php




------------------------------------------------------------------------

[2007-08-17 04:08:56] cpriest at warpmail dot net

Description:
------------
SimpleXML is having some difficulty in parsing XML which contains a
default xmlns entry.

Reproduce code:
---------------
<?
        header('Content-Type: text/plain');
        
        $ResponseBody = '<?xml version="1.0" encoding="UTF-8"?>
<result xmlns="https://zzz.com/webservices";
xmlns:xsd="https://www.w3.org/2001/XMLSchema";
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance";>Test</result>';
        
        $objXML = new SimpleXMLElement($ResponseBody);
        
        $tMatches = $objXML->xpath('/result');
        print_r((string)$tMatches[0]);
?>

Expected result:
----------------
Expect print_r() to print "Test"

Actual result:
--------------
$tMatches is an empty array()

If you change the xmlns="https://zzz.com/webservices"; to
xmlns:zzz="https://zzz.com/webservices"; (add a namespace sub-string), it
works fine.


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=42325&edit=1

Reply via email to