Reputation: 25
i want to generate an xml feed like below in which description and content need to be in tag like
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
Upvotes: 0
Views: 484
Reputation: 1809
If you need the CDATA node, the you can just add it using 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. You are misusing namespaces, which will probably give you serious problems when using conformant xml parsers.
Upvotes: 1