Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xml 如何使用Xpath获取RSS URL_Xml_Xpath_Rss - Fatal编程技术网

Xml 如何使用Xpath获取RSS URL

Xml 如何使用Xpath获取RSS URL,xml,xpath,rss,Xml,Xpath,Rss,示例代码: <link rel="alternate" type="application/rss+xml" title="Fit Living Lifestyle &raquo; Feed" href="http://www.fitlivinglifestyle.com/feed/" /> 但似乎并不完全如此。您正在寻找的XPath是: link[@type="application/rss+xml"]/@href 这将使用type=“application/rss+x

示例代码:

<link rel="alternate" type="application/rss+xml" title="Fit Living Lifestyle &raquo; Feed" href="http://www.fitlivinglifestyle.com/feed/" />

但似乎并不完全如此。

您正在寻找的XPath是:

link[@type="application/rss+xml"]/@href
这将使用
type=“application/rss+xml”
选择所有
link
元素,并返回
href
属性。要返回
标题
属性,请使用:

link[@type="application/rss+xml"]/@title

那很有效,谢谢。我想知道如何改进结果,使其仅在如下情况下返回URL:,因为目前有些页面有3个URL,其中也包含类似的内容。可能不是最优雅的解决方案,但这很有效:
link[@type=“application/rss+xml”和@href=”http://www.fitlivinglifestyle.com/feed“]/@href
是,但是我不知道我正在查看的根网站的名称,当然,这将在100个未知URL上运行,因此我无法指定URL(fitliving)。你能更具体地说明你正在查找的确切URL吗?可能有一种使用XPath的解决方案,但使用XPath选择所有URL,然后使用正则表达式缩小搜索范围可能更容易。如果您使用XPath 2.0,则可以使用
函数结尾:
链接[@type=“application/rss+xml”,以(@href,“feed”)]/@href
结尾。如果您使用的是XPath 1.0,那么可以使用
contains
函数查看“提要”是否是
@href
值的子字符串:
链接[@type=“application/rss+xml”和contains(@href,“提要”)]/@href
link[@type="application/rss+xml"]/@title