.NET 4.x Как исправить ошибку в коде RSS-парсера - C#
Формулировка задачи:
Доброго всем времени суток . Дали задание написать парсер для rss . Но всё да былобы , но выдаёт ошибку "Имя MyResponse и decriptionTextBox отсутствует в текущем контексте " в System.IO.Stream rssStream = MyResponse.GetResponseStream(); 26 строчка и decriptionTextBox.Text = rssData[titlesComboBox.SelectedIndex, 1]; 94 строчка.
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace rssPars { public partial class Form1 : Form { public Form1() { InitializeComponent(); } String[,] rssData = null; private String[,] getRssData(String channel) { System.Net.WebRequest myRequest = System.Net.WebRequest.Create(channel); System.Net.WebResponse myResponse = myRequest.GetResponse(); System.IO.Stream rssStream = MyResponse.GetResponseStream(); System.Xml.XmlDocument rssDoc = new System.Xml.XmlDocument(); rssDoc.Load(rssStream); System.Xml.XmlNodeList rssItems = rssDoc.SelectNodes("rss/channel/item"); String[,] tempRssData = new String[100, 3]; for (int i = 0; i < rssItems.Count; i++) { System.Xml.XmlNode rssNode; rssNode = rssItems.Item(i).SelectSingleNode("title"); if (rssNode != null) { tempRssData[i,0] = rssNode.InnerText; } else { tempRssData[i,0] = ""; } rssNode = rssItems.Item(i).SelectSingleNode("discription"); if (rssNode != null) { tempRssData[i, 1] = rssNode.InnerText; } else { tempRssData[i, 1] = ""; } rssNode = rssItems.Item(i).SelectSingleNode("link"); if (rssNode != null) { tempRssData[i,2] = rssNode.InnerText; } else { tempRssData[i,2] = ""; } } return tempRssData; } private void refreshButton_Click(object sender, EventArgs e) { titlesComboBox.Items.Clear(); rssData = getRssData(ChannelTextBox.Text); for (int i = 0; i < rssData.GetLength(0); i++) { if (rssData[i, 0] != null) { titlesComboBox.Items.Add(rssData[i, 0]); } titlesComboBox.SelectedIndex = 0; } } private void titlesComboBox_SelectedIndexChanged(object sender, EventArgs e) { if (rssData[titlesComboBox.SelectedIndex, 1] != null) decriptionTextBox.Text = rssData[titlesComboBox.SelectedIndex, 1]; if (rssData[titlesComboBox.SelectedIndex, 2] != null) linkLabel1.Text = "GoTo: " + rssData[titlesComboBox.SelectedIndex, 0]; } private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { if (rssData[titlesComboBox.SelectedIndex, 2] != null) System.Diagnostics.Process.Start(rssData[titlesComboBox.SelectedIndex, 2]); } } }
Решение задачи: «.NET 4.x Как исправить ошибку в коде RSS-парсера»
textual
Листинг программы
descriptionTextBox.Text = rssData[titlesComboBox.SelectedIndex, 1];
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д