如何使用php从xml提要中提取georss:point标记

问题描述 投票:1回答:1

我在这个网站上看到过很多链接。其中一个非常接近:parsing a georss namespace with simplexml

为了我的目的,我编辑了这样的代码:

<html>
	<head>
		<title>Testing</title>
	</head>
	<body>
	<?php
    $file = "http://www.ubalert.com/alerts.rss";
    $xml = simplexml_load_file($file);  
    $loc = $xml->channel->entry;  
    foreach ($loc->children('http://www.georss.org/georss') as $geo)
	{ 
        echo $geo;
    } 
	?>
	</body>
</html>

我想从给定的rss feed中提取georss:point tag值。我尝试了很多但失败了。运行上面的代码会给出致命的错误:

致命错误:在第10行的C:\ xampp \ htdocs \ phpproj \ Test2.php中调用null上的成员函数children()

任何帮助,将不胜感激。谢谢。

xml rss simplexml
1个回答
1
投票

我知道这是旧的,但这可能会帮助那些想要解析GeoRss Feeds或任何使用命名空间的xml的人。

$url = 'http://www.ubalert.com/alerts.rss';
$xml = simplexml_load_file($url); 
$namespaces = $xml;
foreach ($xml->entry as $entry) {
    //Use Namespace
    $geo = $entry->children($namespaces['georss']); 
    echo $geo->point;
    echo "\n";
}
© www.soinside.com 2019 - 2024. All rights reserved.