.net読み取りRssをDataTableに変換
Rss DataTable
///
/// Rss DataTable
///
/// Rss
///
public static DataTable GetRss(string filePath)
{
DataTable dt = new DataTable();
WebClient wc = new WebClient();
Stream srContent = wc.OpenRead(filePath);
StreamReader sr = new StreamReader(srContent);
if (!sr.EndOfStream)
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(sr);
XmlNodeList xnl = xmlDoc.SelectNodes("rss/channel/item");
if (xnl.Count > 0)
{
{// dataTable
XmlNode xnColumn = xnl[0];
XmlNodeList columnsNode = xnColumn.ChildNodes;
foreach (XmlNode xn in columnsNode)
{
DataColumn dc = new DataColumn(xn.Name);
dt.Columns.Add(dc);
}
}// dataTable
{// DataTable
foreach (XmlNode xnDate in xnl)
{
DataRow dr = dt.NewRow();
for (int i = 0; i < dt.Columns.Count; i++)
{
XmlNode itemValue = xnDate.SelectSingleNode(dt.Columns[i].ColumnName);
dr[i] = itemValue.InnerText;
}
dt.Rows.Add(dr);
}
}// DataTable
}
}
return dt;
}