开发者

Deserializing XML CDATA into string variable with RestSharp

I'm trying to take an RSS feed and deserialize it into a list of rssEntry objects.

var Client = new RestClient("url here");
Request = new RestRequest { RequestFormat DataFormat.Xml };
var response = Client.Execute<Channel>(Request);
return response.Data.Item;

This fills everything in except content which contains CDATA

Channel.cs

 public class Channel
 {
    public string Title { get; set; }
    public string Link { get; set; }
    public string AtomLink { get; set; }
    public string Description { get; set; }
    public DateTime LastBuildDate { get; set; }
    public string Generator { get; set; }
    public string Language { get; set; }
    public string UpdatePeriod { get; set; }
    public int UpdateFrequency { get; set; }
    public RssItems Item { get; set; }
}

Item.cs

public class Item 
{
        public string Title { get; set; }
        public string Link { get; set; }
        public string Comments { get; set; }
        public DateTime PubDate { get; set; }
        public string Creator { get; set; }
        public string C开发者_如何学运维ategory { get; set; }
        public string Description { get; set; }
        public string Content { get; set; }
        public string Guid { get; set; }
        public string CommentRss { get; set; }
        public int SlashComments { get; set; }
  }

I'm open to using something other than RestSharp, but I was trying it out for this hoping it would be a nice easy solution.

Currently any field with CDATA is returned as null.


The problem was that I read through the xml in the RSS feed and I named the variables in the items class content. The actual item element in the rss feed was content:encoded.

Changing this variable to Encoded fixed it, completely my own fault.

public class Item 
{
        public string Title { get; set; }
        public string Link { get; set; }
        public string Comments { get; set; }
        public DateTime PubDate { get; set; }
        public string Creator { get; set; }
        public string Category { get; set; }
        public string Description { get; set; }
        public string Encoded { get; set; }
        public string Guid { get; set; }
        public string CommentRss { get; set; }
        public int SlashComments { get; set; }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜