php - How to get an element from simplexml -
this question has answer here:
- simplexml node value 2 answers
simplexmlelement object ( [smsmessage] => simplexmlelement object ( [sid] => xyz [dateupdated] => 2013-05-02 18:43:19 [datecreated] => 2013-05-02 18:43:19 [datesent] => 1970-01-01 05:30:00 [accountsid] => xx [to] => 09011148771 [from] => xx [body] => hello [bodyindex] => simplexmlelement object ( ) [status] => sending [direction] => outbound-api [price] => simplexmlelement object ( ) [apiversion] => simplexmlelement object ( ) [uri] => /v1/accounts/xx/sms/messages/xyz ) )
i tried:
$xml->sid;
but returns simplexmlelement object ( )
i tried $xml->title
, returned same simplexmlelement object ( )
how sid above xml
i've been fiddling bit , recreated structure similar yours:
$string='<?xml version="1.0"?> <xml> <smsmessage> <sid>xyz</sid> <dateupdated>2013-05-02 18:43:19</dateupdated> </smsmessage> </xml>'; $xml = new simplexmlelement($string); print_r($xml);
this outputs:
simplexmlelement object ( [smsmessage] => simplexmlelement object ( [sid] => xyz [dateupdated] => 2013-05-02 18:43:19 ) )
which equal yours. , print xyz doing:
echo $xml->smsmessage->sid;
try out, might missing parent node or something.
Comments
Post a Comment