1

I work with C# and this made in Visual Studio 2016.

I received an exercise from school. I received half an RSS-Reader and my task was to complete it. I completed the exercise but I'm not content. It only shows the first item from the RSS-Code which is bloody useless if you ask me. I want to make a button that displays the next and in the RSS-code.

When I told my teacher this he said it would be hard but I could probably do it (I only have class one day a week and started a month ago). He recommended me to make use of a while loop but I simply do not know where to start.

Here is my code:

namespace RSSReader
{
    public partial class RSSReaderForm : Form
    {
        public RSSReaderForm()
        {
            InitializeComponent();
        }

        private void toonRssCodeKnop_Click(object sender, EventArgs e)
        {
            //Aanmaken variabele+nieuw webclient object in de variabele stoppen
            WebClient client = new WebClient();

            //RSS code ophalen voor de meegegeven link
            MessageBox.Show(client.DownloadString(RSSTextBox.Text));
        }

        private void toonBerichtKnop_Click(object sender, EventArgs e)
        {
            //[DEEL 1 - ophalen RSS code]
            //Aanmaken variabele + nieuw webclient object in de variabele stoppen
            WebClient client = new WebClient();
            //RSS code ophalen voor de meegegeven link en in een nieuwe string variabele stoppen
            string rssCode = client.DownloadString(RSSTextBox.Text);

            //[DEEL 2 - Eerste bericht uitlezen, deze staat tussen <item> en </item> tekst]            
            int itemStartPositie = rssCode.IndexOf("<item>");  //Zoek de positie waarop de eerste <item> tekst staat.
            itemStartPositie = itemStartPositie + 6;           //Dit voorkomt dat de teskst <item> zelf wordt meegekopierd.
            int itemEindPositie = rssCode.IndexOf("</item>");  //Zoek de positie waarop de eerste </item> tekst staat.
            int itemLengte = itemEindPositie-itemStartPositie; //Bereken hoeveel posities er tussen begin- en eind-positie zitten

            //Kopieer vanaf positie itemStartPositie precies itemLengte letters
            string itemCode = rssCode.Substring(itemStartPositie, itemLengte);

            //[DEEL 3 - in itemCode de title en description opzoeken en deze in de labels plaatsen]
            //[VOEG HIER JE EIGEN CODE TOE]
            int titelStartPositie = rssCode.IndexOf("<title>");
            titelStartPositie = titelStartPositie + 7;
            int titelEindPositie = rssCode.IndexOf("</title>");
            int titelLengte = titelEindPositie - titelStartPositie;

            int descriptionStartPositie = rssCode.IndexOf("<description>");
            descriptionStartPositie = descriptionStartPositie + 13;
            int descriptionEindPositie = rssCode.IndexOf("</description>");
            int descriptionLengte = descriptionEindPositie - descriptionStartPositie;

            int linkStartPositie = rssCode.IndexOf("<link>");
            linkStartPositie = linkStartPositie + 6;
            int linkEindPositie = rssCode.IndexOf("</link>");
            int linkLengte = linkEindPositie - linkStartPositie;

            string titelCode = rssCode.Substring(titelStartPositie, titelLengte);
            string descriptionCode = rssCode.Substring(descriptionStartPositie, descriptionLengte);
            string linkCode = rssCode.Substring(linkStartPositie, linkLengte);

            titelLabel.Text = titelCode;
            descriptionLabel.Text = descriptionCode;
            linkLabel.Text = linkCode;
        }

        private void linkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            System.Diagnostics.Process.Start(linkLabel.Text);
        }

        private void volgendeBerichtKnop_Click(object sender, EventArgs e)
        {

        }
    }
}

I just don't know where to start and how to do it. Help would be awesome.

M. Adeel Khalid
  • 1,786
  • 2
  • 21
  • 24
  • Do you know what an rss is? Just use one for a bit and compare it with what you have – bichito Mar 20 '17 at 00:18
  • I know what an RSS is. But the ones I find online are way better then mine and have a news feed. They do not require me to actually click on a button and few the next and –  Mar 20 '17 at 00:27
  • Finding a news feed it is not the problem. Use one, and forget about the bells and whistles. Concentrate in the basic functionality behind the fanciness – bichito Mar 20 '17 at 01:22
  • 1
    Any school that makes you parse XML using `string.IndexOf` needs some good schooling... Hint: the code that reads the first feed item (DEEL 2) handles the first item, you could try and change that to make it read the second item. – Emond Mar 20 '17 at 07:01
  • Any reason to not use [`XmlSerialization`](http://stackoverflow.com/questions/364253/how-to-deserialize-xml-document)? – Christian Gollhardt Mar 20 '17 at 07:05

0 Answers0