在html页面中解析application/atom + xml

0 c# regex asp.net url feed

我们知道所有博客都显示他的博客的RSS源码

<link rel="alternate" type="application/rss+xml" title="MyBlog RSS Feed" href="http://feeds.feedburner.com/MyBlog" />
Run Code Online (Sandbox Code Playgroud)

但是你知道任何正则表达式可以从中得到它

<link rel="alternate" type="application/rss+xml" title="MyBlog RSS Feed" href="http://feeds.feedburner.com/MyBlog" />
Run Code Online (Sandbox Code Playgroud)

Wel*_*bog 6

使用像这样的XPath查询:

//link[@type='application/rss+xml']/@href
Run Code Online (Sandbox Code Playgroud)

它会为您提取任何RSS提要URL.永远不要用正则表达式解析XML或HTML. XPath专门为您轻松查询XML和HTML.它几乎可用于所有技术堆栈,包括.NET.

XML不是常规的,因此正则表达式是解析它的错误工具.