#51154 [Opn->Bgs]: SimpleXMLElement does not support dash in nodename
| From: | aharvey@php.net | Date: | Fri, 26 Feb 2010 09:14:27 +0000 |
| Subject: | #51154 [Opn->Bgs]: SimpleXMLElement does not support dash in nodename | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-148073@lists.php.net to get a copy of this message | ||
ID: 51154
Updated by: aharvey@php.net
Reported By: mr at inpay dot com
-Status: Open
+Status: Bogus
Bug Type: SimpleXML related
Operating System: Windows 7 Professional
PHP Version: 5.3.1
New Comment:
This works fine, so long as you use the right syntax. Example 3 at
http://au2.php.net/manual/en/simplexml.examples-basic.php
covers this.
In your case, you would access http-code as follows:
$httpCode = $xml->{'http-code'};
Previous Comments:
------------------------------------------------------------------------
[2010-02-26 08:40:34] mr at inpay dot com
Oops, but accident i switched the "Expected result" and "Actual
result"
Expected result should be SimpleXMLElement Object ( [http_code] => 200
)
Actual result should be SimpleXMLElement Object ( [http-code] => 200 )
Sorry for the inconvinience.
------------------------------------------------------------------------
[2010-02-26 08:38:41] mr at inpay dot com
Description:
------------
Having a XML string, where one or more of the nodenames contains a -
(dash) it is impossible to return that value, as dash is not allowed in
attributes on an object. Consider replacing all dash'es with
underscores.
Reproduce code:
---------------
<?php
$xml_string = "<response><http-code>200</http-code></response>";
$xml = new SimpleXMLElement($xml_string);
print_r($xml);
?>
Expected result:
----------------
SimpleXMLElement Object ( [http-code] => 200 )
Actual result:
--------------
SimpleXMLElement Object ( [http_code] => 200 )
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=51154&edit=1