【发布时间】:2011-05-21 18:01:13
【问题描述】:
我很困惑如何使用我的 PHP 解析脚本从这段 XML 中的“链接”标签中提取“href”属性。如果它有帮助,我会尝试从 GetSatisfaction API 提要中提取特定帖子的 URL。
以下是 XML 文件中的一个节点示例:
<entry>
<link rel="something" href="http://...url_I_need" type="text/html"/>
<title type="html">...title here...</title>
<content type="html">
...content here...
</content>
</entry>
这是我的 PHP XML 解析脚本的数据收集部分:
$doc = new DOMDocument();
$doc->load('http://api.getsatisfaction.com/companies/issuetrak/topics?sort=recently_active&limit=7');
$arrFeeds = array();
foreach ($doc->getElementsByTagName('entry') as $node) {
$title = $node->getElementsByTagName('title')->item(0)->nodeValue;
//I need to just store the link->href value to $link below
//$link = ???;
}
关于如何提取“href”属性有什么建议吗?
谢谢!
【问题讨论】:
-
当您想要
<link>的属性时,为什么要使用getElementsByTagName('title')?
标签: php xml xml-parsing