locked
XML - Use variable RRS feed

  • General discussion

  • -- XML REMOTO C# --

            
    private WebClient wc = null;
    
            // Constructor
            public MainPage()
            {
                InitializeComponent();
    
                wc = new WebClient();
                wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(wc_DownloadStringCompleted);
                wc.DownloadStringAsync(new Uri("http://localhost/datos.xml"));
    
            }
    
            void wc_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
            {
    
                if (e.Error != null) return;
    
                XDocument xdoc = XDocument.Parse(e.Result);
                var regs = from agenda in xdoc.Descendants("entrada")
                           orderby (string) agenda.Element("Nombre").Value
                           select new Agenda()
                            {
                              Nombre = (String) agenda.Element("Nombre").Value,
                              Telefono = (String) agenda.Element("Telefono").Value,
                              Email = (String) agenda.Element("Email").Value
                            };
    
                lstLista.ItemsSource=regs;
            }
    
            private void lstLista_SelectionChanged(object sender, SelectionChangedEventArgs e)
            {
                NavigationService.Navigate(new Uri("/Detalle.xaml", UriKind.Relative));
            }
    
            protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
            {
                base.OnNavigatedFrom(e);
    
                Detalle pag = e.Content as Detalle;
                if (pag != null)
                    pag.DataContext = lstLista.SelectedItem;
            }


    -- RSS C# --

          private WebClient remoteXml;
            
            // Constructor
            public MainPage()
            {
                InitializeComponent();
    
                remoteXml = new WebClient();
                remoteXml.DownloadStringCompleted += new DownloadStringCompletedEventHandler(remoteXml_DownloadStringCompleted);
    
                remoteXml.DownloadStringAsync(new Uri("http://www.leonoticias.com/rss/", UriKind.Absolute));
    
            }
    
            void remoteXml_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
            {
                if (e.Error != null) return;
                XDocument xdoc = XDocument.Parse(e.Result);
    
                var datos = from item in xdoc.Descendants("item")
                            select new RssFeed()
                            {
                                Title = item.Element("title").Value,
                                Content = item.Element("description").Value,
                                link = new Uri(item.Element("link").Value, UriKind.Absolute),
                                FechaPublicacion = DateTime.Parse((String)item.Element("pubDate").Value)
                            };
                lstItems.ItemsSource = datos;
            }

    -- XAML --

    <ListBox.ItempTemplate>

    <DataTemplate>

    <StackPanel>


    • Changed type Eric Fleck Monday, February 10, 2014 6:08 PM samples are not questions.
    Monday, February 10, 2014 11:14 AM

All replies

  • This sample would be more helpful if you could provide some explanation of your code.


    -Eric.

    Monday, February 10, 2014 6:08 PM