【问题标题】:How to get a list of links to the xml? [duplicate]如何获取到 xml 的链接列表? [复制]
【发布时间】:2013-02-24 02:01:04
【问题描述】:

XML 文件:

<urlset>
    <url>
         <loc>http://example.com/.../</loc>
         <lastmod>0000-00-00</lastmod>
         <priority>0</priority>
    </url>
    <url>
         <loc>http://example.com/...</loc>
         <lastmod>0000-00-00</lastmod>
         <priority>0</priority>
    </url>
</urlset>

如何获取到 xml 的链接列表? (谷歌翻译)

foreach ($html->find('?????') as $element) {
    echo $element->src;
}   

【问题讨论】:

标签: php html dom xml-parsing


【解决方案1】:

我假设您想要一个所有“loc”元素的列表。

$simpleObj = simplexml_load_string($xml);
$loc = $simpleObj->xpath('//loc');

foreach($loc as $url){
    echo $url;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多