/// <summary> /// Converts to RSS XML. /// </summary> /// <param name="reader">The reader.</param> /// <returns>Xml string in Rss Format</returns> public static string ConvertToRssXml(XmlReader reader) { if (reader == null) { throw new ArgumentNullException("reader"); } string rssXml = string.Empty; while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { DocumentType feedType = RssXmlHelper.GetDocumentType(reader.LocalName); string outerXml = reader.ReadOuterXml(); switch (feedType) { case DocumentType.Rss: rssXml = outerXml; break; case DocumentType.Opml: RssAggregator aggregator = new RssAggregator(); aggregator.Load(outerXml); rssXml = aggregator.RssXml; break; case DocumentType.Atom: rssXml = DoXslTransform(outerXml, GetStreamFromResource(Constants.AtomToRssXsl)); break; case DocumentType.Rdf: rssXml = DoXslTransform(outerXml, GetStreamFromResource(Constants.RdfToRssXsl)); break; } break; } } // fix namespaces if (reader.NameTable.Get("http://search.yahoo.com/mrss") != null) { rssXml = rssXml.Replace("http://search.yahoo.com/mrss", "http://search.yahoo.com/mrss/"); } return(rssXml); }
public static T LoadRssFromOpmlUrl <T>(string url) where T : RssDocumentBase { if (string.IsNullOrEmpty(url)) { throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "The argument '{0}' is Null or Empty", "url")); } // resolve app-relative URLs url = RssXmlHelper.ResolveAppRelativeLinkToUrl(url); RssAggregator aggregator = new RssAggregator(); aggregator.Load(new System.Uri(url)); string rssXml = aggregator.RssXml; return(RssXmlHelper.DeserializeFromXmlUsingStringReader <T>(rssXml)); }