#42325 [Opn->Bgs]: xmlns parsing issues
| From: | rrichards@php.net | Date: | Fri, 17 Aug 2007 14:45:18 +0000 |
| Subject: | #42325 [Opn->Bgs]: xmlns parsing issues | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-116247@lists.php.net to get a copy of this message | ||
ID: 42325
Updated by: rrichards@php.net
Reported By: cpriest at warpmail dot net
-Status: Open
+Status: Bogus
Bug Type: SimpleXML related
Operating System: Windows
PHP Version: 5.2.4RC2
New Comment:
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
Previous Comments:
------------------------------------------------------------------------
[2007-08-17 14:35:16] cpriest at warpmail dot net
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()
------------------------------------------------------------------------
[2007-08-17 07:01:04] chregu@php.net
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