示例#1
0
        /// <summary>
        /// 把RSS项转为xml节点
        /// </summary>
        /// <param name="item">RSS项信息</param>
        /// <returns></returns>
        protected XmlNode CreateRssItem(RssItem item, IO.XmlHelper xmlwr, XmlNode parent)
        {
            var xn = xmlwr.CreateNewNode(parent, XmlNodeType.Element, "item");

            CreateNode("title", item.Title, xmlwr, xn);
            CreateNode("link", item.Link, xmlwr, xn);
            CreateNode("description", item.Description, xmlwr, xn);
            CreateNode("pubDate", item.PubDate.ToString("yyyy/MM/dd HH:mm:ss"), xmlwr, xn);
            CreateNode("category", item.Cagtegory, xmlwr, xn);
            CreateNode("author", item.Author, xmlwr, xn);
            CreateNode("guid", item.Guid, xmlwr, xn);
            return(xn);
        }
示例#2
0
        /// <summary>
        /// 通过RSS内容获取整个信息
        /// </summary>
        /// <param name="rssContent">内容</param>
        /// <returns></returns>
        protected void FromRss(string rssContent)
        {
            var xmlwr = new IO.XmlHelper();//读取器

            xmlwr.LoadXmlString(rssContent);

            this.Title       = GetNodeValue("title", "channel", xmlwr);
            this.Description = GetNodeValue("description", "channel", xmlwr);
            this.Docs        = GetNodeValue("docs", "channel", xmlwr);
            this.Generator   = GetNodeValue("generator", "channel", xmlwr);
            this.Language    = GetNodeValue("language", "channel", xmlwr);

            this.Link           = GetNodeValue("link", "channel", xmlwr);
            this.ManagingEditor = GetNodeValue("managingeditor", "channel", xmlwr);
            this.WebMaster      = GetNodeValue("WebMaster", "channel", xmlwr);

            //获取子项
            var nodes = xmlwr.GetNodeListByDelegate(delegate(XmlNode xn)
            {
                return(xn.Name.Equals("item", StringComparison.CurrentCultureIgnoreCase));
            });

            Items.Clear();
            foreach (var xn in nodes)
            {
                if (xn.ChildNodes != null)
                {
                    var item = new RssItem();
                    foreach (XmlNode chn in xn.ChildNodes)
                    {
                        switch (chn.Name.ToLower())
                        {
                        case "title":
                        {
                            item.Title = chn.InnerText;
                            break;
                        }

                        case "link":
                        {
                            item.Link = chn.InnerText;
                            break;
                        }

                        case "description":
                        {
                            item.Description = chn.InnerText;
                            break;
                        }

                        case "author":
                        {
                            item.Author = chn.InnerText;
                            break;
                        }

                        case "comments":
                        {
                            item.Comments = chn.InnerText;
                            break;
                        }

                        case "pubdate":
                        {
                            DateTime dt;
                            if (DateTime.TryParse(chn.InnerText, out dt))
                            {
                                item.PubDate = dt;
                            }
                            break;
                        }

                        case "category":
                        {
                            item.Cagtegory = chn.InnerText;
                            break;
                        }

                        case "guid":
                        {
                            item.Guid = chn.InnerText;
                            break;
                        }
                        }
                    }

                    Items.Add(item);
                }
            }
        }
示例#3
0
 /// <summary>
 /// 添加子项
 /// </summary>
 /// <param name="item">RSS子项</param>
 public void Add(RssItem item)
 {
     Items.Add(item);
 }