使用 simplexml 访问 xml/atom 文档中的命名空间元素/属性

发布于 2024-08-16 03:42:34 字数 624 浏览 4 评论 0原文

我可能有一个简单的问题, 我需要知道如何访问嵌套命名空间属性/元素,如下所示,

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

这来自 google-api

另外,我现在不确定应该使用哪一个 网址.../作品集 或者 投资组合/1/头寸 获取股票报价

所以,我对此可能是错的。 (上面的xml来自投资组合)

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

感谢adv,Richard

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱冒险 2024-08-23 03:42:34
$response= simplexml_load_string($response);

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

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

或者,您可以这样做,这将回显所有数据和上面的符号:

$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>";
    }
}
$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>";
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文