Anular a serialização de XML CDATA na variável de seqüência de caracteres com RestSharp
-
14-11-2019 - |
Pergunta
Eu estou a tentar fazer um feed RSS e desserializar-lo em uma lista de rssEntry objetos.
var Client = new RestClient("url here");
Request = new RestRequest { RequestFormat DataFormat.Xml };
var response = Client.Execute<Channel>(Request);
return response.Data.Item;
Isso preenche tudo, exceto de conteúdo que contém CDATA
O canal.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; }
}
O 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 Category { 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; }
}
Estou aberto para algo que não seja RestSharp, mas eu estava tentando com isso para esta esperando que ele seria uma boa solução fácil.
Atualmente qualquer campo com CDATA é retornado como null.
Solução
O problema era que eu ler o xml do feed RSS e eu chamei as variáveis nos elementos do conteúdo de classe.O real elemento de item no feed rss foi content:encoded.
A alteração desta variável Codificada fixa-lo, completamente a minha culpa.
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; }
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow