PHP SimpleXML命名空间问题
发布时间:2020-12-13 17:38:07 所属栏目:PHP教程 来源:网络整理
导读:我正在尝试获取RSS提要中每个条目的entry- id和entry- cap:parameter-值….下面是我正在使用的代码.它正确显示id,但它没有显示值字段….请帮忙. $url = 'http://alerts.weather.gov/cap/us.php?x=1';$cap = simplexml_load_file($url);foreach($cap-entry a
我正在尝试获取RSS提要中每个条目的entry-> id和entry-> cap:parameter->值….下面是我正在使用的代码.它正确显示id,但它没有显示值字段….请帮忙.
$url = 'http://alerts.weather.gov/cap/us.php?x=1'; $cap = simplexml_load_file($url); foreach($cap->entry as $entry){ echo 'ID: ',$entry->id,"n"; echo 'VTEC: ',$entry->children('cap',true)->parameter->value,"n"; echo "<hr>"; } 我在这里先向您的帮助表示感谢. 解决方法
< value>元素与< cap:parameter>不在同一个
namespace中:
<cap:parameter> <valueName>VTEC</valueName> <value>/O.CON.KMPX.FL.W.0012.000000T0000Z-110517T1800Z/</value> </cap:parameter> 所以你必须再次调用children(). 代码(demo) $feed = simplexml_load_file('http://alerts.weather.gov/cap/us.php?x=1'); foreach ($feed->entry as $entry){ printf( "ID: %snVTEC: %sn<hr>",true)->parameter->children()->value ); } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |