[英]how to create rss content encode in c# with SyndicationItem
i want to generate an xml feed like below in which description and content need to be in tag like 我想生成一个如下所示的xml提要,其中的描述和内容需要在标记中,例如
List<SyndicationItem> myItems = new List<SyndicationItem>();
foreach (TestViewModel testViewModel in rssViewModel.Test)
{
SyndicationItem myItem = new SyndicationItem
{
Title = new TextSyndicationContent(testViewModel.TestTitle)
};
myItem.AddPermalink(new Uri(testViewModel.TestUrl));
myItem.Id = testViewModel.TestUrl;
myItem.ElementExtensions.Add(new XElement("pubDate", testViewModel.PublishedDate).CreateReader());
foreach (TestAuthorViewModel testAuthorViewModel in testViewModel.Authors)
{
myItem.ElementExtensions.Add(new XElement("author", testAuthorViewModel.FullName).CreateReader());
}
myItem.ElementExtensions.Add(new XElement("description", string.Format("<![CDATA[{0}]]>", testViewModel.Abstract)).CreateReader());
myItem.ElementExtensions.Add(new XElement("content", string.Format("<![CDATA[{0}]]>", testViewModel.Body)).CreateReader());
myItems.Add(myItem);
}
how will i do it 我该怎么做
If you need the CDATA node, the you can just add it using new XCData(content)
. 如果您需要CDATA节点,则可以使用new XCData(content)
添加它。
var xdoc = new XDocument(new XElement("Hello", new XCData("World")));
However, I am more concerned with the description:encoded
and content:encoded
tags. 但是,我更关注description:encoded
和content:encoded
标签。 You are misusing namespaces, which will probably give you serious problems when using conformant xml parsers. 您正在滥用名称空间,这可能会在使用一致的XML解析器时给您带来严重的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.