Click here to Skip to main content
15,892,674 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
the code is given below

C#
string rssUri = "https://finance.yahoo.com/news/rss";
                          var docf = XDocument.Load(rssUri);
                          
                          foreach (var el in docf.Elements("rss").Elements("channel").Elements("item"))
                          {
                             
                              var tit = el.Element("title").Value;
              var dec = el.Element("description").Value;
               var dat =Convert.ToDateTime( el.Element("pubDate").Value);
                              
                              
            }



Thanks in Advance...
Posted
Updated 5-Oct-15 20:23pm
v2

The following code shoud do.

C#
var firstTwo = docf.Elements("rss").Elements("channel").Elements("item").Take(2)


Don't forget to use "System.Linq"
 
Share this answer
 
Comments
aarif moh shaikh 6-Oct-15 3:03am    
hhhmmm
Athul MS 6-Oct-15 3:24am    
its working thanks thanks alot
Use a counter to count till 2 and then break the loop.
 
Share this answer
 
Instead of foreach use for loop

C#
for(int i=0; i <2; i++)
{
   //do your stuff
}
 
Share this answer
 
Use for loop instead.
C#
for(int i=0; i< docf.Elements("rss").Elements("channel").Elements("item").Count(); i++)
{
    if(i != 2)
    {
        var tit = el.Element("title").Value;
        var dec = el.Element("description").Value;
        var dat =Convert.ToDateTime( el.Element("pubDate").Value);
    }
}


-KR
 
Share this answer
 
Comments
cgorakh 6-Oct-15 3:14am    
This solution will not provide first 2 rows from the collection. if condition can be modified as if (i < 2) { --- write your logic here } else break;
Athul MS 6-Oct-15 5:21am    
how to bind the title,description and pubDate

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900