Re: Problem reading SimpleXML array

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

 



Richard,

I'm guessing you haven't played with simpleXML ...

(apologies inadvance for any/all mistakes :-)

chances are the var_dump() pointer you gave (which under
normal circumstances would be spot on) will probably
lead to more confusion. to put it lightly SimpleXML
doesn't lend itself to introspection (ATM?) because of the
very #%^$ (for the totally naive: that was masking the word 'nice')
string casting magic. at least it drove me absolutely nuts.

anyway copious and experimental use of explicit casting to
strings [i.e. using '(string)'] was the order of the day for me.

as far as I understand it the problem lies in the fact that the object
you get back has properties which behave as strings and objects which
for good measure can (all) can be iterated [foreach] like arrays.

all very simple, well ... you decide. :-)

Richard Lynch wrote:
On Mon, October 24, 2005 3:50 am, George Pitcher wrote:

Hi,

I'm having a problem reading an xml feed. This is my object:

SimpleXMLElement Object (
	[Header] => SimpleXMLElement Object (
		[ID] => FX12GB
		[Test] => false
		[Name] => Foreign Exchange United Kingdom Pound Noon Rates
		[Prepared] => 2005-10-24
		[Sender] => SimpleXMLElement Object (
			[Name] => Federal Reserve Bank of New York
			[Contact] => SimpleXMLElement Object (
				[Name] => George Matthes
				[Email] => george.matthes@xxxxxxxxxx ) )
		[ReportingBegin] => 1994-01-06 )
	[DataSet] => SimpleXMLElement Object (
		[Series] => SimpleXMLElement Object (
			[Key] => SimpleXMLElement Object (
				[FREQ] => D
				[CURR] => GBP
				[FX_TIME] => 12
				[FX_TYPE] => S )
			[Obs] => SimpleXMLElement Object (
				[TIME_PERIOD] => 2005-10-21
				[OBS_VALUE] => 1.7692 ) ) ) )

I'm trying to get those last two lines: TIME_PERIOD and OBS_VALUE.

I can get the ID (third line) using $s->Header->ID (where $s is my
object).
$s->DataSet->Series->Obs->TIME_PERIOD;   // 'Trying to get property of
non-object'



echo "<PRE>";
var_dump($s);
echo "<hr />\n";
var_dump($s->DataSet);
echo "<hr />\n";
var_dump($s->DataSet->Series);
echo "<hr />\n";
.
.
.


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