Hi,
I was trying to get image from description tag of rss feed.Ihave tried in many ways but unable to get it.
</description>
My Code to parse is
using System;
using Microsoft.Phone.Controls;
using System.Windows;
using System.Net;
using System.Xml.Serialization;
using System.Xml.Linq;
using System.Windows.Controls;
namespace Recipes
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
// is there network connection available
if (!System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable())
{
MessageBox.Show("No network connection available!");
return;
}
// start loading XML-data
WebClient downloader = new WebClient();
Uri uri = new Uri("http://teluguone.com/recipes/feeds/recipefeeds/rice-4.rss", UriKind.Absolute);
downloader.DownloadStringCompleted += new DownloadStringCompletedEventHandler(ChannelDownloaded);
downloader.DownloadStringAsync(uri);
}
void ChannelDownloaded(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Result == null || e.Error != null)
{
MessageBox.Show("There was an error downloading the XML-file!");
}
else
{
// Deserialize if download succeeds
XmlSerializer serializer = new XmlSerializer(typeof(Channel));
XDocument document = XDocument.Parse(e.Result);
Channel channel = (Channel)serializer.Deserialize(document.CreateReader());
string s =
"<description><p style=\"text-align: center;\"><span style=\"color: rgb(128, 0, 0);\"><strong><span style=\"font-size: medium;\">Peas Masala
Rice Recipe <br /> </span></strong></span></p> <p style=\"text-align: center;\"><span style=\"color: rgb(128, 0, 0);\"><strong><span style=\"font-size: medium;\"><img width=\"300\"
vspace=\"3\" hspace=\"1\" height=\"250\" border=\"1\" align=\"middle\" src=\"/recipeuserfiles/Peas Masala Rice Recipe.jpg\" alt=\"\" /></span></strong></span></p><p><strong>Ingredients <br /> </strong></p> <p>* 1 cup Rice</p> <p>* 1/2 Coconut</p> <p>* 2 Green Chillies</p> <p>* 1 small Ginger</p> <p>* 1/2 cup Green Peas</p> <p>*
2 tsp Oil</p> <p>* 2 Cardamoms</p> <p>* 4 Cloves</p> <p>* 1 Cinnamon</p> <p>* Salt to taste</p> <p>* Coriander leaves</p> <p>* Mustard seeds</p> <p>nbsp;</p> <p><strong>Preparation<br /> </strong></p> <p>* First grind coconut (grated), ginger, cinnamon, cloves, green chillies, cardamom to a smooth paste by adding little water.</p> <p>* In a pressure pan, add oil and add mustard seeds to the ground
masala and saute well.</p> <p>* Clean the rice in running water and add to the masala.</p> <p>* Stir well for two minutes.</p> <p>* Add the green peas, 2 1/4 cup water and salt.</p> <p>* Close the pressure pan.
Keep for 2 or 3 sounds.</p> <p>* Remove from fire.</p> <p>* When the pressure becomes normal, transfer the bath in a bowl and stir it.</p> <p>* Garnish with coriander leaves.</p></description>";
XDocument doc = XDocument.Parse(s);
if (doc.Descendants("img").Any())
{
var imgTag = doc.Descendants("img").First();
var width = imgTag.Attribute("width").Value;
}
itemList.ItemsSource = channel.Collection;
}
}
}
}
I was gettung following errors
'System.Collections.Generic.IEnumerable<System.Xml.Linq.XElement>' does not contain a definition for 'First' and no extension method 'First' accepting a first argument of type 'System.Collections.Generic.IEnumerable<System.Xml.Linq.XElement>' could be found (are you missing a using directive or an assembly reference?)
'System.Collections.Generic.IEnumerable<System.Xml.Linq.XElement>' does not contain a definition for 'Any' and no extension method 'Any' accepting a first argument of type 'System.Collections.Generic.IEnumerable<System.Xml.Linq.XElement>' could be found (are you missing a using directive or an assembly reference?)
plzz help me.Thanks in advance.