Here is the code to read RSS feed. Hope this helps someone who is writng a code to read RSS feeds.
The final content will be stored in two arraylists.
ArrayList rawvalueList = new ArrayList();
XmlReaderSettings settings = new XmlReaderSettings();
settings.ConformanceLevel = ConformanceLevel.Fragment;
settings.IgnoreWhitespace = true;
settings.IgnoreComments = true;
XmlReader reader = XmlReader.Create(RSSfeed, settings);
while (reader.Read())
{
if (reader.IsStartElement())
{
if (reader.IsEmptyElement)
{
string emptyElementName = reader.Name;
}
else
{
string nameElement = reader.Name;
string nestedElementName = "";
string textContent = "";
reader.Read(); // Read the start tag.
if (reader.IsStartElement()) // Handle nested elements.
{
nestedElementName = reader.Name;
}
textContent = reader.ReadString();
rawkeyList.Add(nestedElementName.ToUpper() + ":" + nameElement.ToUpper());
rawvalueList.Add(textContent);
} // if IsEmptyElement
} // if IsStartElement
} // while
The final content will be stored in two arraylists.
string RSSfeed = "http://rss.cnn.com/rss/cnn_topstories.rss" ;
ArrayList rawkeyList = new ArrayList();ArrayList rawvalueList = new ArrayList();
XmlReaderSettings settings = new XmlReaderSettings();
settings.ConformanceLevel = ConformanceLevel.Fragment;
settings.IgnoreWhitespace = true;
settings.IgnoreComments = true;
XmlReader reader = XmlReader.Create(RSSfeed, settings);
while (reader.Read())
{
if (reader.IsStartElement())
{
if (reader.IsEmptyElement)
{
string emptyElementName = reader.Name;
}
else
{
string nameElement = reader.Name;
string nestedElementName = "";
string textContent = "";
reader.Read(); // Read the start tag.
if (reader.IsStartElement()) // Handle nested elements.
{
nestedElementName = reader.Name;
}
textContent = reader.ReadString();
rawkeyList.Add(nestedElementName.ToUpper() + ":" + nameElement.ToUpper());
rawvalueList.Add(textContent);
} // if IsEmptyElement
} // if IsStartElement
} // while