public static void ExportOpml(string filename, IEnumerable<Feed> feeds, string name) {
            var opml = new OpmlDocument();
            opml.Head.Title = String.Format("{0} Export", name); ;

            var categories = from f in feeds
                             group f by f.Category into c
                             select new {
                                 Name = c.Key,
                                 Feeds = c.ToList()
                             };

            foreach (var category in categories) {
                var outline = new OpmlOutline(category.Name);
                outline.Attributes.Add("title", category.Name);

                foreach (var feed in category.Feeds) {
                    var let = new OpmlOutline(feed.Title);
                    let.Attributes.Add("type", "rss");
                    let.Attributes.Add("title", feed.Title);
                    let.Attributes.Add("xmlUrl", feed.Url);
                    let.Attributes.Add("htmlUrl", feed.SiteUrl);
                    outline.Outlines.Add(let);
                }

                opml.AddOutline(outline);
            }

            using (var stream = File.Open(filename, FileMode.Create, FileAccess.Write, FileShare.None)) {
                opml.Save(stream);
            }
        }
示例#2
0
        //============================================================
        //    CLASS SUMMARY
        //============================================================
        /// <summary>
        /// Provides example code for the OpmlOutline class.
        /// </summary>
        public static void ClassExample()
        {
            #region OpmlOutline
            OpmlDocument document   = new OpmlDocument();

            document.Head.Title                 = "Example OPML List";
            document.Head.CreatedOn             = new DateTime(2005, 6, 18, 12, 11, 52);
            document.Head.ModifiedOn            = new DateTime(2005, 7, 2, 21, 42, 48);
            document.Head.Owner                 = new OpmlOwner("John Doe", "*****@*****.**");
            document.Head.VerticalScrollState   = 1;
            document.Head.Window                = new OpmlWindow(61, 304, 562, 842);

            // Create outline that contains child outlines
            OpmlOutline containerOutline    = new OpmlOutline("Feeds");
            containerOutline.Outlines.Add(OpmlOutline.CreateSubscriptionListOutline("Argotic", "rss", new Uri("http://www.codeplex.com/Argotic/Project/ProjectRss.aspx")));
            containerOutline.Outlines.Add(OpmlOutline.CreateSubscriptionListOutline("Google News", "feed", new Uri("http://news.google.com/?output=atom")));
            document.AddOutline(containerOutline);
            #endregion
        }