Reputation: 2408
I've this xml :
<?xml version="1.0"?>
<channel>
<item>
<title>Le joyeux médecin</title>
<description>
<p>test blague description</p>
</description>
<pubDate>Dimanche, 02/03/2014</pubDate>
</item>
</channel>
And the code to parse the xml :
private void Feed(object Sender, DownloadStringCompletedEventArgs e)
{
XElement _xml;
try
{
if (!e.Cancelled)
{
_xml = XElement.Parse(e.Result);
Results.Items.Clear();
foreach (XElement value in _xml.Elements("channel").Elements("item"))
{
_item = new Flux();
_item.Title = value.Element("title").Value;
_item.Description = Regex.Replace(value.Element("description").Value,
@"<(.|\n)*?>", String.Empty);
Results.Items.Add(_item);
break;
}
}
}
catch
{
MessageBox.Show(e.Error.Message);
}
}
_xml
contains the xml but the code into the foreach
doesn't execute and I don't know why... thanks for any help !
Upvotes: 0
Views: 50
Reputation: 116168
Change your loop as:
foreach (XElement value in _xml.Elements("item"))
{
}
Since _xml
is already channel
Upvotes: 3