【问题标题】:parsing application/atom+xml in html page在 html 页面中解析 application/atom+xml
【发布时间】:2009-11-30 20:15:18
【问题描述】:

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

<link rel="alternate" type="application/rss+xml" title="MyBlog RSS Feed" href="http://feeds.feedburner.com/MyBlog" />

但是你知道任何正则表达式可以从中获取 feedurl

<link rel="alternate" type="application/rss+xml" title="MyBlog RSS Feed" href="http://feeds.feedburner.com/MyBlog" />

【问题讨论】:

    标签: c# asp.net regex url feed


    【解决方案1】:

    使用这样的 XPath 查询:

    //link[@type='application/rss+xml']/@href
    

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

    XML 不规则,所以regex is the incorrect tool to parse it。

    【讨论】:

    • html不是有效的xml怎么办?
    猜你喜欢
    • 1970-01-01
    • 2012-01-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多