note 90554 added to book.simplexml
| From: | mail at kleineedv dot de | Date: | Tue, 28 Apr 2009 07:37:29 +0000 |
| Subject: | note 90554 added to book.simplexml | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-153889@lists.php.net to get a copy of this message | ||
I had a problem with simplexml reading nodes from an xml file. It always return an SimpleXML-Object
but not the text inside the node.
Example:
<?xml version="1.0" encoding="UTF-8"?>
<Test>
<Id>123</Id>
</Test>
Reading this xml into a variable called $xml and then doing the following
<?php
$myId = $xml->Id;
?>
did not return 123 in $myId, but instead I got a SimpleXMLElement Object.
The solution is simple, when you know it. Use explicit string conversion.
<?php
$myId = (string)$xml->Id;
?>
----
Server IP: 209.41.74.194
Probable Submitter: 80.153.55.209
----
Manual Page -- http://www.php.net/manual/en/book.simplexml.php
Edit -- https://master.php.net/note/edit/90554
Del: integrated -- https://master.php.net/note/delete/90554/integrated
Del: useless -- https://master.php.net/note/delete/90554/useless
Del: bad code -- https://master.php.net/note/delete/90554/bad+code
Del: spam -- https://master.php.net/note/delete/90554/spam
Del: non-english -- https://master.php.net/note/delete/90554/non-english
Del: in docs -- https://master.php.net/note/delete/90554/in+docs
Del: other reasons-- https://master.php.net/note/delete/90554
Reject -- https://master.php.net/note/reject/90554
Search -- https://master.php.net/manage/user-notes.php