views:

351

answers:

1

Hello, I may have a simple question, I need to know how to get to nested namespace attributes/elements like below

<gf:marketValue>
    <gd:money amount='150990.0' currencyCode='USD'/>
  </gf:marketValue>

this is from the google-api

Also, I am now not sure wich one I should use the url .../portfolio or portfolio/1/positions to get the stockquotes

So, I may be wrong about this. (the xml above are from portfolio)

$response= simplexml_load_string($response);
foreach($response->entry as $entry)
{
$ns_gf = $entry->children('http://schemas.google.com/finance/2007');

thanks in adv, Richard

+2  A: 
$response= simplexml_load_string($response);

$entry_data = $response ->  xpath("//positionData");

foreach($entry_data as $data)
{
echo $data["shares"] ." <br />";

Or, you could go with this, which would echo out all data and the symbol above:

$entries = $response -> xpath("//entry");

foreach($entries as $entry) {
    echo $entry->symbol['symbol']."<br />";
    foreach($entry -> positionData -> attributes() as $att_name => $att_value) {
        echo $att_name. " = ". $att_value."</br>";
    }
}
Anthony
thanks, so both are xpath, is it also do able with children(), also on a sitenote. Do I get the quotes from different stocks from shares or from marketvalue?
Richard
got a blank screen with xpath?
Richard
sorry, it should probably be `xpath("//gf:entry")`
Anthony
the xpath worked. The problem was also, that I was expecting more variables to be returned. I don't understand the googlefinance api yet.Anyway, there is a far better option to get realtime stockqutes and that is a simple query.
Richard