我有以下的XML:
<stories>
<story id="1234">
<title>This is a title</title>
<date>1/1/1980</date>
<article>
<![CDATA[<p>This is an article.</p>]]>
</article>
</story>
</stories>
以下是C#中使用Linq to XML的代码:
@{
XDocument xmlDoc = XDocument.Load("foo.xml");
var stories = from story in xmlDoc.Descendants("stories")
.Descendants("story")
.OrderByDescending(s => (string)s.Attribute("id"))
select new
{
title = story.Element("title").Value,
date = story.Element("date").Value,
article = story.Element("article").Value,
};
foreach (var story in stories)
{
<text><div class="news_item">
<span class="title">@story.title</span>
<span class="date">@story.date</span>
<div class="story">@story.article</div>
</div></text>
}
}
渲染后的HTML代码将输出到浏览器中,如下所示:
<div class="news_item">
<span class="title">This is a title</span>
<span class="date">1/1/1980</span>
<div class="story"><p>This is an article.</p></div>
</div>
我希望浏览器能够以HTML格式呈现
<p>
标签,而不是编码。我该如何实现这一点?