Example #1
0
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        protected XDocument CreateDocument(RssFeed rssFeed)
        {
            var doc = new XDocument(new XDeclaration("1.0", "utf-8", null));

            return doc.AddElement(
                new XElement("rss")
                    .AddAttribute("version", "0.91")
                    .AddElement(rssFeed.Channel.CreateElement("")
                        .AddXmlObject("", rssFeed.Image)
                        .AddXmlObject("", rssFeed.Items)
                        .AddXmlObject("", rssFeed.TextInput)));
        }
Example #2
0
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        protected XDocument CreateDocument(RssFeed rssFeed)
        {
            var doc = new XDocument(new XDeclaration("1.0", "utf-8", null));

            var ns = RssNamespace._1_0;
            var rdf = RssNamespace.RDF;

            return doc.AddElement(new XElement(rdf + "RDF")
                .AddAttribute("xmlns", ns)
                .AddAttribute(XNamespace.Xmlns + "rdf", rdf)
                .AddXmlObject(ns, rssFeed.Channel, rssFeed.Image)
                .AddXmlObject(ns, rssFeed.Items)
                .AddXmlObject(ns, rssFeed.TextInput));
        }
Example #3
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="xml"></param>
        /// <returns></returns>
        public RssFeed Parse(String xml)
        {
            var feed = new RssFeed();
            feed.Version = this.Version;
            var doc = XDocument.Parse(xml);
            var element = doc.Root;

            feed.Channel = this.CreateRssChannel(element.ElementByNamespace("channel"));

            var image = element.ElementByNamespace("image");
            if (image == null)
            {
                var channel = element.ElementByNamespace("channel");
                if (channel != null)
                {
                    image = channel.ElementByNamespace("image");
                }
            }
            feed.Image = this.CreateRssImage(image);

            var items = element.ElementsByNamespace("item");
            if (!items.Any())
            {
                var channel = element.ElementByNamespace("channel");
                if (channel != null)
                {
                    items = channel.ElementsByNamespace("item");
                }
            }
            feed.Items.AddRange(items.Select(el => this.CreateRssItem(el)));

            var textInput = element.ElementByNamespace("textinput");
            if (textInput == null)
            {
                var channel = element.ElementByNamespace("channel");
                if (channel != null)
                {
                    textInput = channel.ElementByNamespace("textinput");
                }
            }
            feed.TextInput = this.CreateRssTextInput(image);

            return feed;
        }
Example #4
0
        public RssFeed Parse(String xml)
        {
            var feed = new RssFeed();
            var doc = XDocument.Parse(xml);
            var element = doc.Root;

            feed.Channel = new RssChannel_Atom(element);

            var image = element.ElementByNamespace("image");
            if (image == null)
            {
                var channel = element.ElementByNamespace("channel");
                if (channel != null)
                {
                    image = channel.ElementByNamespace("image");
                }
            }
            feed.Image = new RssImage_Atom(image);

            foreach (var item in element.ElementsByNamespace("entry"))
            {
                feed.Items.Add(new RssItem_Atom(item));
            }

            var textInput = element.ElementByNamespace("textinput");
            if (textInput == null)
            {
                var channel = element.ElementByNamespace("channel");
                if (channel != null)
                {
                    textInput = channel.ElementByNamespace("textinput");
                }
            }
            feed.TextInput = new RssTextInput_Atom(textInput);

            return feed;
        }
Example #5
0
 /// <summary>
 /// 
 /// </summary>
 /// <returns></returns>
 public override string Write(RssFeed rssFeed)
 {
     var doc = CreateDocument(rssFeed);
     return String.Format("{0}{1}{2}", doc.Declaration, Environment.NewLine, doc);
 }
Example #6
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="rssFeed"></param>
 /// <returns></returns>
 public string Write(RssFeed rssFeed)
 {
     var writer = RssWriter.Create(rssFeed.Version);
     return writer.Write(rssFeed);
 }
Example #7
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="rssFeed"></param>
 /// <returns></returns>
 public abstract string Write(RssFeed rssFeed);