Re: simple xml object
| From: | Mark Cilissen | Date: | Tue, 27 Oct 2009 16:53:57 +0000 |
| Subject: | Re: simple xml object | ||
| References: | 1 | Groups: | php.general php.general |
| Request: | Send a blank email to php-general+get-299397@lists.php.net to get a copy of this message | ||
AChris W schreef:
Although I'm not that familiar with SimpleXML, since the value returned is an object, wouldn't $Result->0 do the trick? -- Kind regards, Mark Cilissen / Pixlism http://www.ninyou.nlI have the following xml with standard tags changed to [ and ] to prevent mail clients from encoding it as html.[?xml version="1.0"?] [resultset errors="0" results="86"] [result id="20080922133104871678" lastinspected="9/29/2009 0:00"]0.4[/result] [result id="20080922133104871678" lastinspected="8/28/2009 0:00"]1.1[/result] . . . I am using the simplexml_load_string to read it in to an object and execute the following code $xml = simplexml_load_string($content); foreach($xml as $Result){ print_r($Result); foreach($Result->attributes() as $i => $v){$$i = $v; print "Attr: $i = '$v'\n";} } that all works fine. Problem is I can't figure out how to get the acutual value (0.4 and 1.1). I also don't know why I can't simply do something like.... $id = $Result->attributes()->id; the output of this looks like .... SimpleXMLElement Object ( [@attributes] => Array( [id] => 20080922133104871678 [lastinspected] => 9/29/2009 0:00 )[0] => 0.4 ) Attr: id = '20080922133104871678' Attr: lastinspected = '9/29/2009 0:00' SimpleXMLElement Object ( [@attributes] => Array( [id] => 20080922133104871678 [lastinspected] => 8/28/2009 0:00 )[0] => 1.1 ) Attr: id = '20080922133104871678' Attr: lastinspected = '8/28/2009 0:00' How do I read the [0] value? $Result[0] gives me nothing.