本文介绍了simplexml_load_file解析[@attributes] =>大批的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试解析此xml提要
I am trying to parse this xml feed
[0] => SimpleXMLElement Object
(
[title] => Johannesburg in November
[link] => SimpleXMLElement Object
(
[@attributes] => Array
(
[rel] => alternate
[type] => text/html
[href] => http://www.tompeters.com/dispatches/012120.php?rss=1
)
)
[id] => tag:www.tompeters.com,2011://2.12120
[published] => 2011-09-08T14:03:23Z
[updated] => 2011-09-08T14:11:49Z
[summary] => Tom will be giving a day-long presentation in November in Johannesburg, South Africa. Our friends at the Business Results Group...
[author] => SimpleXMLElement Object
(
[name] => Shelley Dolley
)
[category] => SimpleXMLElement Object
(
[@attributes] => Array
(
[term] => Announcements
[scheme] => http://www.sixapart.com/ns/types#category
)
)
[content] => SimpleXMLElement Object
(
[@attributes] => Array
(
[type] => html
)
)
)
我这样做的PHP代码是
my PHP code to do so is
$url = 'http://www.tompeters.com/atom.xml';
$xml = simplexml_load_file($url);
echo '<pre>';
foreach($xml->entry as $entry){
echo $entry->title;
echo "<br />";
foreach ($entry->link->@attributes as $attr){
echo $attr->href;
echo "<br />";
}
}
问题在于@attributes
位会破坏代码.
the problem is that the @attributes
bit breaks the code..
我如何获得该href链接?
How do i get that href link?
推荐答案
,所以
foreach ($entry->link->attributes() ...
您似乎对SimpleXML有所怀疑(基于您过去的问题),
可能值得阅读SimplXML文档以获得更好的理解.
It seems you have some doubts over SimpleXML (based on your past question),
it might worth to read the SimplXML documentation for better understanding.
SO标签- https://stackoverflow.com/questions/tagged/simplexml?sort=votes
这篇关于simplexml_load_file解析[@attributes] =>大批的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!