簡體   English   中英

從RSS feed元素中刪除HTML標簽

[英]Remove Html tags from RSS feed element

我正在閱讀有時在元素包含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日期格式問題,它運行良好。 當我使用它解決html標簽時,它不起作用,仍然會引發異常。

使用HTML Agility Pack解析Feed

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM