Recently, you need to use asp.net (c #) to receive an Rss feed. Rss is the data of your forum, and Rss adds a subitem to the Item. Therefore, I wrote a general code to read Rss and immediately add or delete the subitem in Items. This Code is also recognizable.
Hmm ...... Paste the code and record it.
Copy codeThe Code is as follows:
Read Rss and return DataTable
/// <Summary>
/// Get Rss and convert it to DataTable.
/// </Summary>
/// <Param name = "filePath"> Rss address </param>
/// <Returns> </returns>
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)
{
{// Add a column ID for the dataTable
XmlNode xnColumn = xnl [0];
XmlNodeList columnsNode = xnColumn. ChildNodes;
Foreach (XmlNode xn in columnsNode)
{
DataColumn dc = new DataColumn (xn. Name );
Dt. Columns. Add (dc );
}
} // The end of adding a column ID for the dataTable
{// Add row data for the 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 );
}
} // Add column data for the DataTable
}
}
Return dt;
}