Re: simple xml object

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



AChris W schreef:
I 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.


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.nl

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux