PHP SimpleXML 命名空间问题 [英] PHP SimpleXML Namespace Problem
本文介绍了PHP SimpleXML 命名空间问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试获取 RSS 源中每个条目的 entry->id 和 entry->cap:parameter->value.... 下面是我正在使用的代码.它正确显示了 id 但它没有显示值字段....请帮忙.
I'm trying to get the entry->id and entry->cap:parameter->value for every entry in the RSS feed.... below is the code I'm using. It is displaying the id correctly however it is not displaying the value field.... please help.
$url = 'http://alerts.weather.gov/cap/us.php?x=1';
$cap = simplexml_load_file($url);
foreach($cap->entry as $entry){
echo 'ID: ', $entry->id, "
";
echo 'VTEC: ', $entry->children('cap', true)->parameter->value, "
";
echo "<hr>";
}
提前感谢您的帮助.
推荐答案
元素不在同一个 namespace 作为
:
The <value>
element is not in the same namespace as <cap:parameter>
:
<cap:parameter>
<valueName>VTEC</valueName>
<value>/O.CON.KMPX.FL.W.0012.000000T0000Z-110517T1800Z/</value>
</cap:parameter>
所以你必须再次调用children()
.
$feed = simplexml_load_file('http://alerts.weather.gov/cap/us.php?x=1');
foreach ($feed->entry as $entry){
printf(
"ID: %s
VTEC: %s
<hr>",
$entry->id,
$entry->children('cap', true)->parameter->children()->value
);
}
这篇关于PHP SimpleXML 命名空间问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文