コード例 #1
0
        /// <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);
        }
コード例 #2
0
ファイル: RssXmlHelper.cs プロジェクト: alex765022/IBN
        /// <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:
                        throw new NotImplementedException();

                    //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;
                }
            }

            return(rssXml);
        }