Transform RSS feed to HTML using XSLT stylesheet

This code reads the RSS feed and transform it to HTML using XSLT

(Based on VFP code from Calvin Hsia’s WebLog)

Download XSLT stylesheet

 

try
{
    string rssUrl = "http://blogs.msdn.com/MainFeed.aspx";
    string pathname = @"D:\result.html";
 
    XPathDocument myXPathDoc = new XPathDocument(rssUrl);
    XslTransform myXslTrans = new XslTransform();
 
    // load XSLT stylesheet
    myXslTrans.Load(@"D:\pr.xslt");
    XmlTextWriter myWriter = new XmlTextWriter(pathname, null);
    myXslTrans.Transform(myXPathDoc, null, myWriter, null);
    myWriter.Close();
 
    // read html file after XSL transform
    TextReader textReader = File.OpenText(pathname);
    string content = textReader.ReadToEnd();
    textReader.Close();
 
    // convert html file that has been HTML encoded
    StreamWriter streamWriter = new StreamWriter(pathname, false);
    streamWriter.Write(HttpUtility.HtmlDecode(content));
    streamWriter.Close();
}
catch (Exception e)
{
    Console.Write(e);
}
 


 
 
 

Leave a Reply