locked
Can't read xml Correctly RRS feed

  • Question

  • I'm trying to download XML-file from web, read it and show it in Listbox

    that's my Listbox XAML-code

    <ListBox x:Name="lbFeed" Grid.Column="1" Margin="10">
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <StackPanel Margin="10">
                                <TextBlock x:Name="tblText" Text="{Binding text}" Style="{StaticResource ItemTextStyle}"/>
                            </StackPanel>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>

    that is how I'm trying to retrieve XML-file and to read it

    private async Task<XDocument> FeedDownload() { ApplicationDataContainer roamingSettings = ApplicationData.Current.RoamingSettings; Uri feedUri = new Uri("https://api.vk.com/method/newsfeed.get.xml?filters=post&source_ids=" + roamingSettings.Values["user_id"].ToString() + "&access_token=" + roamingSettings.Values["access_token"]);

    var client = new HttpClient(); // Add: using System.Net.Http; var response = await client.GetAsync(feedUri); var result = await response.Content.ReadAsStringAsync(); return XDocument.Parse(result); } private void readFeeds(XDocument xDoc) { var data = from query in xDoc.Descendants("Item") select new Feeds { text = query.Element("text").ToString() + "2" //src = new Uri(query.Element("attachment").Element("photo").Element("src").ToString()) }; lbFeed.ItemsSource = data; }

    but for some reason nothing appears in Listbox

    Here is an example of XML-file I'm downloading

    Help someone =(

    Saturday, August 10, 2013 4:12 PM

Answers

  • Where is the error? Does the file download successfully? If so, does it parse successfully? If so, are there any Items in it and are they found successfully? What does data end up set to?
    Saturday, August 10, 2013 4:26 PM
    Moderator

All replies

  • Where is the error? Does the file download successfully? If so, does it parse successfully? If so, are there any Items in it and are they found successfully? What does data end up set to?
    Saturday, August 10, 2013 4:26 PM
    Moderator
  • XML-file download successfully, parses successfully too.

    The error is in the readFeeds() method. But I can't understand where.

    'data' should be the source of info for the lbFeed listbox, but unfortunately I think there's no items in 'data'. And I want to understand why

    Saturday, August 10, 2013 6:14 PM
  • Everything works fine. Sorry everyone
    Saturday, August 10, 2013 7:11 PM