Skip to content

Instantly share code, notes, and snippets.

@jokecamp
Last active December 13, 2015 21:48
Show Gist options
  • Save jokecamp/4979703 to your computer and use it in GitHub Desktop.
Save jokecamp/4979703 to your computer and use it in GitHub Desktop.
RSS Example Output
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using ServiceStack.Text;
using System.Runtime.Serialization;
using System.Xml;
[assembly: ContractNamespace("", ClrNamespace = "ServiceStackTester")]
namespace ServiceStackTester
{
class Program
{
static void Main(string[] args)
{
string str = "http://static.cricinfo.com/rss/livescores.xml";
WebClient w = new WebClient();
string xml = w.DownloadString(str);
//To change rss Element to Response as in Exception
xml = xml.Replace("<rss version=\"2.0\">", "<Response><rss version=\"2.0\">");
//For closing tag
xml = xml.Replace("</rss>", "</rss></Response>");
var rss = xml.FromXml<Response>();
Console.WriteLine(rss.rss.channel.title);
Console.Read();
}
}
public class Response
{
public rss rss { get; set; }
}
public class rss
{
public string version { get; set; }
public ChannelClass channel { get; set; }
}
public class ChannelClass
{
public string title { get; set; }
public string ttl { get; set; }
public string description { get; set; }
public string link { get; set; }
public string copyright { get; set; }
public string language { get; set; }
public string pubDate { get; set; }
public List<ItemClass> item { get; set; }
}
public class ItemClass
{
public string title { get; set; }
public string link { get; set; }
public string description { get; set; }
public string guid { get; set; }
}
}
<?xml version="1.0" encoding="utf-8"?>
<Response xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<rss>
<Version>2</Version>
<channel>
<copyright i:nil="true" />
<description>description</description>
<item>
<ItemClass>
<description i:nil="true" />
<guid i:nil="true" />
<link i:nil="true" />
<title>title</title>
</ItemClass>
<ItemClass>
<description i:nil="true" />
<guid i:nil="true" />
<link i:nil="true" />
<title>title</title>
</ItemClass>
</item>
<language i:nil="true" />
<link i:nil="true" />
<pubDate i:nil="true" />
<title>title</title>
<ttl i:nil="true" />
</channel>
</rss>
</Response>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment