2013-01-14 42 views
1

我正在阅读元素包含html标签时有时会损坏的新闻提要。 它抛出此异常:从RSS提要元素中删除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); 
     } 
    }  

我想这Answer为另一个XML日期格式问题,它是完美的工作。 当我使用它解决html标记它不起作用,仍然抛出异常。

回答

0

解析与HTML敏捷性包

饲料CodePlex上:http://htmlagilitypack.codeplex.com/

+0

HAP读取只有文件系统的文件。我需要通过互联网阅读XML。 – user968159

+0

如果您看看名为StackOveflow @ http://htmlagilitypack.codeplex.com/SourceControl/changeset/view/99964#1096647的测试。它从webrequest中读取... – lboshuizen