using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using System.IO; using System.Xml; using System.Xml.Xsl; namespace RSSClient { public partial class XMLDisplay : System.Web.UI.Page { /// /// The transformed HTML content /// protected string text = ""; protected void Page_Load(object sender, System.EventArgs e) { //retrieve sourceURL from session string sourceURL = Session["sourceURL"] as string; if (sourceURL != null) { string path = Request.Url.AbsoluteUri; int lastSlash = path.LastIndexOf("/"); string xsltURL = path.Substring(0, lastSlash) + "/rss.xsl"; //transform RSS to HTML text = RSSToHTML(sourceURL, xsltURL); } else text = "Please choose an RSS Feed"; } #region VS.NET generated code override protected void OnInit(EventArgs e) { InitializeComponent(); base.OnInit(e); } private void InitializeComponent() { } #endregion public static string RSSToHTML(string sourceURL, string xsltURL) { //source XmlTextReader reader = new XmlTextReader(sourceURL); XmlDataDocument document = new XmlDataDocument(); document.Load(reader); //target StringWriter stw = new StringWriter(); XmlTextWriter xmlTextWriter = new XmlTextWriter(stw); xmlTextWriter.Formatting = Formatting.Indented; //transformation XslTransform xslt = new XslTransform(); xslt.Load(xsltURL); xslt.Transform(document, null, xmlTextWriter, null); //return transformed result return stw.GetStringBuilder().ToString(); } } }