note 90554 modified in book.simplexml by cumhuronat

From: Date: Tue, 28 Apr 2009 07:41:23 +0000
Subject: note 90554 modified in book.simplexml by cumhuronat
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-153890@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; ?> --was-- 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; ?> http://php.net/manual/en/book.simplexml.php

« previous php.notes (#153890) next »