English 中文(简体)
access namespace element/attribute in xml/atom document with simplexml
原标题:

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

最佳回答
$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>";
    }
}
问题回答

暂无回答




相关问题
Parse players currently in lobby

I m attempting to write a bash script to parse out the following log file and give me a list of CURRENT players in the room (so ignoring players that left, but including players that may have rejoined)...

How to get instance from string in C#?

Is it possible to get the property of a class from string and then set a value? Example: string s = "label1.text"; string value = "new value"; label1.text = value; <--and some code that makes ...

XML DOM parsing br tag

I need to parse a xml string to obtain the xml DOM, the problem I m facing is with the self closing html tag like <br /> giving me the error of Tag mismatch expected </br>. I m aware this ...

Ruby parser in Java

The project I m doing is written in Java and parsers source code files. (Java src up to now). Now I d like to enable parsing Ruby code as well. Therefore I am looking for a parser in Java that parses ...

Locating specific string and capturing data following it

I built a site a long time ago and now I want to place the data into a database without copying and pasting the 400+ pages that it has grown to so that I can make the site database driven. My site ...

热门标签