Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Clare 37 posts 117 karma points
    Feb 27, 2014 @ 15:24
    Clare
    0

    RSS feed not working

    Hi, I'm trying to produce an rss feed of the news item on our website but it isn't working.The page just doesn't load when I apply the RSS template to my URL.

    I followed the video tutorial but must be missing something...

    This is the code in my rss.cshtml file:

    @using umbraco.MacroEngines
    @inherits DynamicNodeContext
    @{
        //Change mime type
        umbraco.library.ChangeContentType("text/xml");  
       
        //Get the domain
        var siteURL = "http://" + Request.Url.Host;
       
        //Get the news area node (only one of these per site)
        var newsAreaNode = Model.Newslists.First();
       
        //Get the latest createDate of all news items to use as the RSS feed updateDate
        var RSSFeedPubDate = newsAreaNode.Children.Where("Visible").OrderBy("NewsDate desc").First();
    }
    <?xml version="1.0" encoding="UTF-8"?>
    <rss version="2.0"
        xmlns:content="http://purl.org/rss/1.0/modules/content/"
        xmlns:wfw="http://wellformedweb.org/CommentAPI/"
        xmlns:dc="http://purl.org/dc/elements/1.1/"
        xmlns:rssdatehelper="urn:rssdatehelper">
            <channel>
                <title>News rss</title>
                <pubDate>@RSSFeedPubDate.UpdateDate.ToString("r")</pubDate>
                <generator>umbraco</generator>
                <description>Add your description here</description>
                <language>en</language>
                @{
                    foreach (var item in newsAreaNode.Children.Where("Visible"))
                    {
                        <item>
                            <title>@item.Name</title>
                            <pubDate>@item.UpdateDate.ToString("r")</pubDate>
                            <guid>@item.Url</guid>
                            <content:encoded><![CDATA[@item.Summary]]></content:encoded>
                        </item>
                    }
                }
            </channel>
    </rss>

    and this is the code in the rss template file:

    <%@ Master Language="C#" MasterPageFile="~/umbraco/masterpages/default.master" AutoEventWireup="true" %>
       
    <asp:Content ContentPlaceHolderID="ContentPlaceHolderDefault" runat="server"><umbraco:Macro Alias="RSS" runat="server"></umbraco:Macro></asp:Content>
  • Damian Green 452 posts 1433 karma points
    Feb 27, 2014 @ 17:31
    Damian Green
    0

    What do you get?  A blank page or an error?

     

  • Clare 37 posts 117 karma points
    Feb 27, 2014 @ 17:37
    Clare
    0

    The page just doesn't load... it's here if that helps: http://regents.ac.uk/rss

     

    thanks

  • Damian Green 452 posts 1433 karma points
    Feb 27, 2014 @ 17:49
    Damian Green
    0

    Seems to be looping and then doing nothing.

    Comment out sections of code and see if you can isolate whats going it. Infact first thing id try is comment the lot out and just put a h1 saying test in the rss macro file to prove its getting called and then add bits back in.

    @*
                    foreach (var item in newsAreaNode.Children.Where("Visible"))
                    {
                        <item>
                            <title>@item.Name</
    title>
                           
    <pubDate>@item.UpdateDate.ToString("r")</pubDate>
                           
    <guid>@item.Url</guid>
                            <content:encoded><![CDATA[@item.Summary]]></
    content:encoded>
                       
    </item>
                    }
                } *@
  • Clare 37 posts 117 karma points
    Feb 28, 2014 @ 09:29
    Clare
    0

    Thanks for the tip Damian, I'll try it

  • Damian Green 452 posts 1433 karma points
    Feb 28, 2014 @ 11:20
    Damian Green
    0

    Any luck?

  • Clare 37 posts 117 karma points
    Feb 28, 2014 @ 11:43
    Clare
    0

    Not yet I'm afraid although I think it is the <pubDate> that is causing it to loop and do nothing. When I remove that line from under <channel> the page at least loads...

    @using umbraco.MacroEngines
    @inherits DynamicNodeContext
    @{
    var newsAreaNode = Model.Descendants("Newslist").First();
    var RSSFeedPubDate = newsAreaNode.Children.OrderBy("newsDate desc").First();
        }
    <?xml version="1.0" encoding="UTF-8"?>
    <rss version="2.0">
    <channel>
      <title>RUL news rss</title>
      <link>http://regents.ac.uk</link>;
      <pubDate>@RSSFeedPubDate.newsDate.ToString("r")</pubDate>
      <description>RUL news</description>
          @{
             foreach (var item in newsAreaNode.Children.Where("Visible"))
             {
                <item>
                <h3>@item.Name</h3>   
                </item>
              }
            }     
    </item>
    </channel>
    </rss>
  • Clare 37 posts 117 karma points
    Feb 28, 2014 @ 12:09
    Clare
    0

    hi again, I'm now getting this error on the page after it loads:

    XML Parsing Error: XML or text declaration not at start of entity
    Location: http://www.regents.ac.uk/rss
    Line Number 2, Column 1:<?xml version="1.0" encoding="UTF-8"?>
    ^

    This is my latest .cshtml (for now I'm leaving out the <pubDate> from under channel

    @using umbraco.MacroEngines
    @inherits DynamicNodeContext
    @{
    umbraco.library.ChangeContentType("text/xml");    
    var newsAreaNode = Model.Descendants("Newslist").First();
    var RSSFeedPubDate = newsAreaNode.Children.OrderBy("newsDate desc").First();
        }
    <?xml version="1.0" encoding="UTF-8"?>
    <rss version="2.0">
        xmlns:content="http://purl.org/rss/1.0/modules/content/"
        xmlns:wfw="http://wellformedweb.org/CommentAPI/"
        xmlns:dc="http://purl.org/dc/elements/1.1/"
        xmlns:rssdatehelper="urn:rssdatehelper">
    <channel>
      <title>RUL news rss</title>
      <link>http://regents.ac.uk</link>;
      <generator>umbraco</generator> 
      <description>RUL news</description>
      <language>en</language>
          @{
             foreach (var item in newsAreaNode.Children.Where("Visible"))
             {
                <item>
                <title>@item.Name</title>   
                <description>@item.Summary</description>
                <guid>@item.Url</guid>
                <content:encoded><![CDATA[@item.Summary]]></content:encoded>
                </item>
              }
            }     
    </channel>
    </rss>
  • Damian Green 452 posts 1433 karma points
    Feb 28, 2014 @ 17:43
    Damian Green
    0

    Make sure in your template / masterpage that you call the macro right after the content area declaration (i,e don't put a carriage return in or anything)

    so right after the %><umbraco:Macro in a masterpage or right after the @{}@Umbraco.Macro

    You understand what i mean?

     

  • Clare 37 posts 117 karma points
    Mar 03, 2014 @ 17:22
    Clare
    0

    Thanks for getting back to me Daminan. There aren't any breaks in my template, it's just:

    <%@ Master Language="C#" MasterPageFile="~/umbraco/masterpages/default.master" AutoEventWireup="true" %>
    <asp:Content ContentPlaceHolderID="ContentPlaceHolderDefault" runat="server"><umbraco:Macro Alias="RSS" runat="server"></umbraco:Macro></asp:Content>
  • Bjarne Fyrstenborg 1285 posts 4039 karma points MVP 8x c-trib
    Mar 03, 2014 @ 17:45
    Bjarne Fyrstenborg
    0

    Hi Clare

    Could you try to exclude <?xml version="1.0" encoding="UTF-8"?> from your rss.cshtml file and place it here:

    <%@MasterLanguage="C#"MasterPageFile="~/umbraco/masterpages/default.master"AutoEventWireup="true" %>
    <asp:Content ContentPlaceHolderID="ContentPlaceHolderDefault"runat="server"><?xml version="1.0" encoding="UTF-8"?><umbraco:Macro Alias="RSS"runat="server"></umbraco:Macro></asp:Content>

    I think I had an issue once, where it worked when I placed the xml declaration directly in the template instead..

    /Bjarne

  • Clare 37 posts 117 karma points
    Mar 04, 2014 @ 16:22
    Clare
    0

    Thanks for the suggestion Bjarne, unfortunately I just got a server error when I tried that.

  • Damian Green 452 posts 1433 karma points
    Mar 04, 2014 @ 23:55
    Damian Green
    0

    What about in the macro code itself?

    Make sure your xml declaration is the first line in the code file.

    Move the xml declaration above this line so it is rifght at the top:

    @using umbraco.MacroEngines

     

  • Clare 37 posts 117 karma points
    Mar 06, 2014 @ 15:44
    Clare
    0

    Thanks very much Damian that was it! I now have an rss feed working except for the pubdate field. If I remove this field from everything it works fine but when I add it in anywhere I get the original looping problem. This is my current cshtml:

    <?xml version="1.0" encoding="UTF-8"?>
    @using umbraco.MacroEngines
    @inherits DynamicNodeContext
    @{
    umbraco.library.ChangeContentType("text/xml");    
    var root = Model.AncestorOrSelf();
    var newsAreaNode = root.Descendants("Newslist").First();
        }
    <rss version="2.0">
    <channel>
      <title>RUL news rss</title>
      <link>http://regents.ac.uk</link>;
      <generator>umbraco</generator> 
      <description>RUL news</description> 
      <language>en</language>
          @{
             foreach (var item in newsAreaNode.Children.Where("Visible").OrderBy("NewsDate desc"))
             {
                <item>
                <title>@item.Name</title>
                @Html.Raw("<link>")http://regents.ac.uk/@item.Url()@Html.Raw("</link>")   
                <guid>@item.Url</guid>
                <description>@item.Summary</description>
                  </item>
              }
            }     
    </channel>
    </rss>
  • Damian Green 452 posts 1433 karma points
    Mar 07, 2014 @ 11:38
    Damian Green
    0

    The thing id try next is to add pubdate but just type some text in.

    If that works then look at the actual data thats going in the field. It may have some characters xml doesnt like.

    I have this in my feed but look ssimilar to yours:

    @RSSFeedPubDate.UpdateDate.ToString("r")

     

Please Sign in or register to post replies

Write your reply to:

Draft