.NET reads RSS Convert to DataTable

Use .NET to read Rss data and convert it to DataTable to return. The method is very simple, take a look at the code below. Recently need to use asp.net (c#) to receive an Rss. Rss is the data of its own forum, and Rss is another sub-item added to the Item. So I wrote a general code to read Rss, and then add or delete the sub-items in Items immediately, this code is also identifiable. Hmm…post the code and record it. The code is as follows: Read Rss and return DataTable ///

/// Obtain Rss and convert to DataTable and return /// Rss address

/ Public static DataTable GetRss(string filePath) {DataTable dt = new DataTable(); WebClient Streamer = new WebClient(); StreamReader = new WebClient(); StreamReader = new WebClient(); StreamReader(stream); newContentr Stream; ); if (sr.EndOfStream) {XmlDocument xmlDoc = new XmlDocument ();! xmlDoc.Load (sr); XmlNodeList xnl = xmlDoc.SelectNodes ( “rss / channel / item”); if (xnl.Count> 0) { {// add the column identified as dataTable start XmlNode xnColumn = xnl [0]; XmlNodeList columnsNode = xnColumn.ChildNodes; foreach (XmlNode xn in columnsNode) {DataColumn dc = ne w DataColumn (xn.Name); dt.Columns.Add (dc);}} // end to dataTable {// add the column identified line data as a DataTable foreach (XmlNode xnDate in xnl) {DataRow dr = dt.NewRow ( ); for (int i = 0; i

Leave a Comment

Your email address will not be published.