【发布时间】: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 标签时,它不起作用并且仍然抛出异常。
【问题讨论】: