Riccardo Fanetti, sviluppo software
  Home   About   Prodotti   Download   Accedi
Skip Navigation Links
Chiedi pure.
Web Site Design
.NET Developer
.PHP Developer
OnLine Application
Client Application
Server Maintenance
Business Intelligence Application
Captcha image
Show another codeShow another code
Invia!


Leggere i feed RSS ed inserirli in un db (C#)
[C# ]

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Xml;
using System.Xml.XPath;
public DataTable ReadFlickr(string rssPath, int Count)
{
int i = 0;
// creare una nuova datatable.
DataTable dt=new DataTable();
// Aggiunge colonne alla datatable
dt.Columns.Add("title");
dt.Columns.Add("link");
dt.Columns.Add("pubDate");
dt.Columns.Add("guid");
dt.Columns.Add("description");
dt.Columns.Add("thumbnail");
dt.Columns.Add("picture");
dt.Columns.Add("author");
// carica il feed RSS di Flickr e crea un documento XML
XmlDocument doc=new XmlDocument();
doc.Load(rssPath);
// aggiunge il namespace media
XmlNamespaceManager expr = new XmlNamespaceManager(doc.NameTable);
expr.AddNamespace("media","http://search.yahoo.com/mrss");
// Crea il nodo radice e da questo genera una lista XML
XmlNode root = doc.SelectSingleNode( "//rss/channel/item", expr) ;
XmlNodeList nodeList;
nodeList=root.SelectNodes("//rss/channel/item");
// un loop che attraversa ogni nodo e lo aggiunge alla datatable
foreach(XmlNode chileNode in nodeList)
{
object[] values=new object[8];
XmlNode node=chileNode.SelectSingleNode("title");
values[0]=node.InnerText;
node=chileNode.SelectSingleNode("link");
values[1]=node.InnerText;
node=chileNode.SelectSingleNode("pubDate");
values[2]=node.InnerText;
node=chileNode.SelectSingleNode("guid");
values[3]=node.InnerText;
node=chileNode.SelectSingleNode("description");
values[4]=node.InnerText;
node=chileNode.SelectSingleNode("media:thumbnail", expr);
XmlAttributeCollection ac = node.Attributes;
values[5] = ac["url"].InnerText;
node=chileNode.SelectSingleNode("media:content", expr);
ac = node.Attributes;
values[6] = ac["url"].InnerText;
node=chileNode.SelectSingleNode("media:credit", expr);
values[7]=node.InnerText;
dt.Rows.Add(values);
if (i == Count) {break;}
i++;
}
return dt;

Copyright © 2010 Riccardo Fanetti. Tutti i diritti riservati
Powered by Riccardo Fanetti www.netconfig.it