/// <summary> /// RSS 1.0の読み込みを行います。 /// </summary> /// <param name="uri">フィードのURL</param> /// <returns>フィード</returns> private FeedInfo ReadRSS1(Uri uri) { FeedInfo info = new FeedInfo(); info.Url = uri; XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(uri.ToString()); List<FeedItem> ret = new List<FeedItem>(); XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlDoc.NameTable); nsmgr.AddNamespace("rss", "http://purl.org/rss/1.0/"); nsmgr.AddNamespace("content", "http://purl.org/rss/1.0/modules/content/"); nsmgr.AddNamespace("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#"); nsmgr.AddNamespace("dc", "http://purl.org/dc/elements/1.1/"); XmlNodeList linodes = xmlDoc.SelectNodes("/rdf:RDF/rss:channel/rss:items/rdf:Seq/rdf:li", nsmgr); foreach (XmlNode node in linodes) { string strResource = node.Attributes["resource", "http://www.w3.org/1999/02/22-rdf-syntax-ns#"].Value; XmlNode aboutItem = xmlDoc.SelectSingleNode("/rdf:RDF/rss:item[@rdf:about='" + strResource + "']", nsmgr); if (aboutItem != null) { XmlNode titleNode = aboutItem.SelectSingleNode("rss:title", nsmgr); XmlNode contentNode = aboutItem.SelectSingleNode("content:encoded", nsmgr); XmlNode linkUrkNode = aboutItem.SelectSingleNode("rss:link", nsmgr); XmlNode dateNode = aboutItem.SelectSingleNode("dc:date", nsmgr); string title = string.Empty; string content = string.Empty; string link = string.Empty; string date = string.Empty; if (titleNode != null) { title = titleNode.InnerText; } if (linkUrkNode != null) { link = linkUrkNode.InnerText; } if (contentNode != null) { content = contentNode.InnerText; } if (dateNode != null) { date = dateNode.InnerText; } FeedItem rssItem = new FeedItem(); rssItem.Title = title; rssItem.Content = content; rssItem.Date = stringToDateTime(date); rssItem.Link = new Uri(link); ret.Add(rssItem); } } info.Items = ret.ToArray(); info.Title = xmlDoc.SelectSingleNode("/rdf:RDF/rss:channel/rss:title", nsmgr).InnerText; return info; }
/// <summary> /// RSS 1.0の読み込みを行います。 /// </summary> /// <param name="uri">フィードのURL</param> /// <param name="rssXml">読み込み済みのXMLドキュメント</param> /// <returns>フィード</returns> private FeedInfo ReadRSS1(Uri uri, XmlDocument rssXml) { FeedInfo info = new FeedInfo(); info.Url = uri; List <FeedItem> ret = new List <FeedItem>(); XmlNamespaceManager nsmgr = new XmlNamespaceManager(rssXml.NameTable); nsmgr.AddNamespace("rss", "http://purl.org/rss/1.0/"); nsmgr.AddNamespace("content", "http://purl.org/rss/1.0/modules/content/"); nsmgr.AddNamespace("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#"); nsmgr.AddNamespace("dc", "http://purl.org/dc/elements/1.1/"); XmlNodeList linodes = rssXml.SelectNodes("/rdf:RDF/rss:channel/rss:items/rdf:Seq/rdf:li", nsmgr); foreach (XmlNode node in linodes) { string strResource = node.Attributes["resource", "http://www.w3.org/1999/02/22-rdf-syntax-ns#"].Value; XmlNode aboutItem = rssXml.SelectSingleNode("/rdf:RDF/rss:item[@rdf:about='" + strResource + "']", nsmgr); if (aboutItem != null) { XmlNode titleNode = aboutItem.SelectSingleNode("rss:title", nsmgr); XmlNode contentNode = aboutItem.SelectSingleNode("content:encoded", nsmgr); XmlNode linkUrkNode = aboutItem.SelectSingleNode("rss:link", nsmgr); XmlNode dateNode = aboutItem.SelectSingleNode("dc:date", nsmgr); string title = string.Empty; string content = string.Empty; string link = string.Empty; string date = string.Empty; if (titleNode != null) { title = titleNode.InnerText; } if (linkUrkNode != null) { link = linkUrkNode.InnerText; } if (contentNode != null) { content = contentNode.InnerText; } if (dateNode != null) { date = dateNode.InnerText; } FeedItem rssItem = new FeedItem(); rssItem.Title = title; rssItem.Content = content; rssItem.Date = stringToDateTime(date); rssItem.Link = new Uri(link); ret.Add(rssItem); } } info.Items = ret.ToArray(); info.Title = rssXml.SelectSingleNode("/rdf:RDF/rss:channel/rss:title", nsmgr).InnerText; return(info); }