Пример #1
0
            public static List <Notices> GetNotices(Context c, XDocument xdoc)
            {
                List <Notices> notices = new List <Notices>();
                XmlDocument    doc     = new XmlDocument();

                doc.LoadXml(xdoc.Document.ToString());

                UpdateLastUpdateDate(c, doc.GetElementsByTagName("lastBuildDate")[0].InnerText);

                XmlNodeList nodes = doc.GetElementsByTagName("item");

                foreach (XmlNode nod in nodes)
                {
                    Notices n = new Notices();

                    foreach (XmlNode node in nod.ChildNodes)
                    {
                        if (node.Name == "title")
                        {
                            n.Title = node.InnerText;
                        }

                        if (node.Name == "link")
                        {
                            n.PageLink = new Uri(node.InnerText);
                        }

                        if (node.Name == "pubDate")
                        {
                            n.PublishDate = node.InnerText;
                        }

                        if (node.Name == "content:encoded" || node.Name == "content")
                        {
                            HtmlDocument docHtml = new HtmlDocument();
                            docHtml.LoadHtml("<html>" + node.InnerText + "</html>");

                            Uri url = HtmlManager.ExtractImage(docHtml);

                            if (url != null)
                            {
                                n.HasImage = true;
                            }
                            else
                            {
                                n.HasImage = false;
                            }

                            n.ImageLink = url;

                            url = HtmlManager.ExtractFile(docHtml);

                            if (url != null)
                            {
                                n.HasDocument = true;
                            }
                            else
                            {
                                n.HasDocument = false;
                            }

                            n.FileLink = url;
                        }
                    }

                    notices.Add(n);
                }

                return(notices);
            }