【问题标题】:Remove Html tags from RSS feed element从 RSS 提要元素中删除 Html 标签
【发布时间】:2013-01-14 22:56:14
【问题描述】:

当元素包含 html 标签时,我正在阅读有时会损坏的新闻提要。 它抛出这个异常:

[ 意外的节点类型元素。 ReadElementString 方法只能是 调用具有简单或空内容的元素。]

XML 示例

<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
  <channel>
    <title>test xml feed</title>
    <atom:link href="http://www.newssite.com" rel="self" type="application/rss+xml"/>
    <description>test</description>
    <item>
      <title>
        Title followed by html tags
        <br/>
      </title>
      <link>
        http://www.newssite.com
      </link>
      <description>
        Description Data
      </description>
      <pubDate>Mon, 14 Jan 2013 21:20:00 +0400</pubDate>
      <category>Cat1</category>
    </item>
  </channel>
</rss>  

代码示例

static void Main(string[] args)
        {
            XmlReader reader = new XmlTextReader(@"d:\test.xml");
            SyndicationFeed feed = SyndicationFeed.Load(reader);
        }
    }    

我为另一个 xml 日期格式问题尝试了这个 Answer,它运行良好。 当我使用它解决 html 标签时,它不起作用并且仍然抛出异常。

【问题讨论】:

    标签: c# rss xmlreader


    【解决方案1】:

    使用 Html Agility Pack 解析提要

    在 codeplex 上:http://htmlagilitypack.codeplex.com/

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-07-24
    • 1970-01-01
    • 1970-01-01
    • 2013-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多