我有这个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>
解析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
包含xml但是foreach
中的代码没有执行,我不知道为什么......感谢您的帮助!
答案 0 :(得分:3)
将您的循环更改为:
foreach (XElement value in _xml.Elements("item"))
{
}
由于_xml
已经channel