0

I am trying to write some syndication onto my page,

I use the .Net class to get the rss content into a list

<div>    
    <%
        var r = System.Xml.XmlReader.Create("http://www.huffingtonpost.com/feeds/verticals/small-business/index.xml");
        System.ServiceModel.Syndication.SyndicationFeed albums = System.ServiceModel.Syndication.SyndicationFeed.Load(r);
        r.Close(); 

        foreach (System.ServiceModel.Syndication.SyndicationItem album in albums.Items)
        {
            Response.Write(album.Title.Text);                        
        }                          
    %>
</div>

Well the foreach is only functioning as a forfirst here, because it only writes the first SyndicationItem in the list. As you can see, there are many items in that list. Where can be my mistake?

Just to make sure there is not only 1 item in my album list, I did a count on it.

<div>

        <%
            var r = System.Xml.XmlReader.Create("http://www.huffingtonpost.com/feeds/verticals/small-business/index.xml");
            System.ServiceModel.Syndication.SyndicationFeed albums = System.ServiceModel.Syndication.SyndicationFeed.Load(r);
            r.Close();
            int i = albums.Items.ToList().Count;

            Response.Write(i); 

          /*  foreach (System.ServiceModel.Syndication.SyndicationItem album in albums.Items)
            {
                Response.Write(album.Title.Text); 
            } */

         %>

    </div>

Result:

enter image description here

7
  • Is it writing only the first item in the list or only the last item in the list? Commented Jan 18, 2013 at 0:17
  • 1
    I have no doubt that it is writing all items in the list - in other words, there is only a single item in the list. Commented Jan 18, 2013 at 0:26
  • First, thought you might have been onto something there though. Commented Jan 18, 2013 at 0:28
  • @JohnSaunders huffingtonpost.com/feeds/verticals/small-business/index.xml Is there only one item in that list? Commented Jan 18, 2013 at 0:30
  • It doesn't matter what's in the XML. What matters is what's in memory when your code runs. Set a breakpoint before the foreach and see what's in there. Commented Jan 18, 2013 at 0:39

1 Answer 1

1

I am wondering if the title output your seeing is "small business on huffingtonpost.com". If it is, then it is working correctly. You have one item in the list with many entries. Do another iteration inside your current iteration and you should be good to go.

List of titles from huffingtonPost

Update I just pasted your code in a forms page and it came through with all 15 results.

Sign up to request clarification or add additional context in comments.

3 Comments

No, the title output I see is "John Mackey: The Future of Health Care and Free Enterprise CapitalismRestaurant Workers Deserve More Pay, ..... etc"
I updated my answer. I pasted your code into a new forms app and it seems to work as you would expect. You seem to be doing it correctly. What version of .net are you developing with?
It turns out it worked in chrome and explorer and not firefox. Might have been a caching issue or something, although I thought debugging automatically ignored caches. Oh well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.