RSS 提要 - 使用 WriteTo 更新现有的 TextSyndicationContent [英] RSS feed- Using WriteTo to update an existing TextSyndicationContent

查看:19
本文介绍了RSS 提要 - 使用 WriteTo 更新现有的 TextSyndicationContent的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在帮助

outerElementName 是title"吗?和外部元素命名空间组?如果是这样,我可以在 XMLWriter 中输入什么来更新 title 的值?

解决方案

Title 属性可以在项目上设置.

创建一个 TextSyndicationContent 的新实例并复制带有附加文本的标题.

//...string newTitleText = item.Title.Text +一些额外的文本内容";if (!string.IsNullOrWhiteSpace(item.Title.Type)) {字符串类型 = item.Title.Type ==文本";?明文": item.Title.Type;TextSyndicationContentKind textKind = (TextSyndicationContentKind)Enum.Parse(typeof(TextSyndicationContentKind), type, ignoreCase: true);item.Title = new TextSyndicationContent(newTitleText, textKind);} 别的 {item.Title = new TextSyndicationContent(newTitleText);}//...

I'm helping out with an open-source project. In it, we are getting a feed (open using Chrome) using var feed = new SyndicationFeed(...){...}; that contains different article titles along with their names.

After that I am able to iterate through the feed using foreach(var item in feed.Items){} and in there I can get the Title & Name string using item.Title.Text & item.Authors[0].Name.

The problem is that these properties are read-only, but I want to be able to add some text to the end of the Title property. So, the only way to update the Title (since it's of type TextSyndicationContent) seems to be by using item.Title.WriteTo()

How I can use the WriteTo to update the value of the existing Title without creating a new RSS Feed? Also, how can I get the outerElementName & outerElementNamespace?

I have added a screenshot of what the function requires me to put in.

Is the outerElementName "title" and outerElementNamespace "group? If so, what can I put in as XMLWriter to update the value of title?

解决方案

The Title property can be set on the item.

Create a new instance of TextSyndicationContent and copy over the title with the additional text.

//...

string newTitleText = item.Title.Text + "Some extra text content";

if (!string.IsNullOrWhiteSpace(item.Title.Type)) {
    string type = item.Title.Type == "text" ? "Plaintext" : item.Title.Type;
    TextSyndicationContentKind textKind = (TextSyndicationContentKind)
        Enum.Parse(typeof(TextSyndicationContentKind), type, ignoreCase: true);
    item.Title = new TextSyndicationContent(newTitleText, textKind);
} else {
    item.Title = new TextSyndicationContent(newTitleText);
}

//...

这篇关于RSS 提要 - 使用 WriteTo 更新现有的 TextSyndicationContent的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆