コード例 #1
0
        public RssFeed(String Url)
        {
            Items = new RssItems();
            XmlTextReader xmlTextReader = new XmlTextReader(Url);
            XmlDocument   xmlDoc        = new XmlDocument();

            try
            {
                xmlDoc.Load(xmlTextReader);
                xmlTextReader.Close();
                XmlNode channelXmlNode = xmlDoc.GetElementsByTagName("channel")[0];
                if (channelXmlNode != null)
                {
                    foreach (XmlNode channelNode in channelXmlNode)
                    {
                        switch (channelNode.Name)
                        {
                        case "title":
                        {
                            Title = channelNode.InnerText;
                            break;
                        }

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

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

                        case "item":
                        {
                            RssItem channelItem = new RssItem(channelNode);
                            Items.Add(channelItem);
                            break;
                        }

                        case "pubDate":
                        {
                            pubDate = channelNode.InnerText;
                            break;
                        }
                        }
                    }
                }
                else
                {
                    throw new Exception("Error in XML, channel description not found!");
                }
            }

            catch (System.Net.WebException ex)
            {
                if (ex.Status == System.Net.WebExceptionStatus.NameResolutionFailure)
                {
                    throw new Exception("Impossible to connect with source.\r\n" + Url);
                }
                else
                {
                    throw
                        ex;
                }
            }

            catch (System.IO.FileNotFoundException)
            {
                throw new Exception("File" + Url + "not found");
            }

            catch (Exception ex)
            {
                throw ex;
            }

            finally
            {
                xmlTextReader.Close();
            }
        }
コード例 #2
0
ファイル: RssFeed.cs プロジェクト: kolokolov95/KOD
        public RssFeed(String Url)
        {
            Items = new RssItems();
            XmlTextReader xmlTextReader = new XmlTextReader(Url);
            XmlDocument xmlDoc = new XmlDocument();

            try
            {
                xmlDoc.Load(xmlTextReader);
                xmlTextReader.Close();
                XmlNode channelXmlNode = xmlDoc.GetElementsByTagName("channel")[0];
                if (channelXmlNode != null)
                {
                    foreach (XmlNode channelNode in channelXmlNode)
                    {
                        switch (channelNode.Name)
                        {
                            case "title":
                                {
                                    Title = channelNode.InnerText;
                                    break;
                                }
                            case "description":
                                {
                                    Description = channelNode.InnerText;
                                    break;
                                }
                            case "link":
                                {
                                    Link = channelNode.InnerText;
                                    break;
                                }
                            case "item":
                                {
                                    RssItem channelItem = new RssItem(channelNode);
                                    Items.Add(channelItem);
                                    break;
                                }
                            case "pubDate":
                                {
                                    pubDate = channelNode.InnerText;
                                    break;
                                }
                        }
                    }
                }
                else
                {
                    throw new Exception("Error in XML, channel description not found!");
                }
            }

            catch (System.Net.WebException ex)
            {
                if (ex.Status == System.Net.WebExceptionStatus.NameResolutionFailure)
                    throw new Exception("Impossible to connect with source.\r\n" + Url);
                else
                    throw
                       ex;
            }

            catch (System.IO.FileNotFoundException)
            {
                throw new Exception("File" + Url + "not found");
            }

            catch (Exception ex)
            {
                throw ex;
            }

            finally
            {
                xmlTextReader.Close();
            }

            }