I am using webclient to deserialize XML content from a webservice:
var serializer = new XmlSerializer(typeof(SearchArticles), new XmlRootAttribute("search_articles"));
var results = (SearchArticles)serializer.Deserialize(response.Content.ReadAsStreamAsync().Result);
The xml content is like:
<?xml version=\"1.0\" encoding=\"UTF-8\"?><search_articles><articles hits=\"10134\"><article><id>1763794</id>...
My Models look like:
public class SearchArticles
{
[XmlElement("articles")]
public ArticleHelper articles { get; set; }
}
public class ArticleHelper
{
[XmlAttribute("hits")]
public long hits { get; set; }
[XmlElement("article")]
public List<Article> articles { get; set; }
}
public class Article
{
public long id { get; set; }
public string partner { get; set; }
public string number { get; set; }
public long number_is_generated { get; set; }
public string status { get; set; }
public long company_id { get; set; }
}
This is working, but how can I avoid having the ArticleHelper ?
You can remove ArticleHelper by modifying
SearchArticlesandArticleas:However, you lose access the hits attribute value.