0

I'm having troubling squaring away the parsing of NASA RSS feeds. I've researched all I can and there seems to be one part I'm missing, or for all I know right now it might be more. But I'm only getting one error in VS and I've tried everything. Thanks in advance for any help.

private void UpdateFeedList(string feedXML)
    {


        StringReader stringReader = new StringReader(feedXML);
        XmlReader xmlReader = XmlReader.Create(stringReader);
        XElement XDocument = XElement.Load(xmlReader);

        Deployment.Current.Dispatcher.BeginInvoke(() =>
        {
            listBox.ItemsSource = XDocument.Items;
        });
    }

The error I'm currently getting in VS is in the last line '.items' . VS is telling me that XElement does not contain a definition for Items.

4

1 回答 1

0

VS 告诉我 XElement 不包含 Items 的定义。

这是绝对正确的 - 请参阅文档。目前尚不清楚您期望它做什么,但您需要从中提取相关信息XElement,例如

Deployment.Current.Dispatcher.BeginInvoke(() =>
{
    listBox.ItemsSource = XDocument.Elements("SomeElementName");
});

顺便说一句,使用变量名XDocument已经足够糟糕了,但是当这甚至不是变量的类型时,这是一个可怕的想法。这就像声明:

int String = 10; // Just don't do it!

此外,您的前三行可以大大简化:

XElement element = XElement.Parse(feedXml);

但是您确实需要考虑您希望项目集合实际上是什么......也许您想将提要转换为您自己创建的某种类型的对象集合?

于 2013-07-13T22:38:09.453 回答