Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I am bringing in an RSS feed using the razor below. I need 2 things though: to be able to sort by a node <event-date> and to only list the 5 most recient items in the feed. Any help would be appreciated. Thanks!
@using System.Xml.XPath;@using System.Xml;@using umbraco.MacroEngines@inherits umbraco.MacroEngines.DynamicNodeContext
@{
XmlTextReader udBrudRSS = new XmlTextReader("http://rosehulman.imodules.com/controls/cms_v2/components/rss/rss.aspx?sid=1554&gid=1&calcid=1110&page_id=402");XmlDocument doc = new XmlDocument();doc.Load(udBrudRSS);XmlNodeList rssItems = doc.SelectNodes("//item");
}
<ul class="rss-feed">
foreach (XmlNode node in rssItems) { <li> <div class="date">@node["event-date"].InnerText</div> <a href="@node["link"].InnerText">@node["title"].InnerText</a> </li> } }
</ul>
Hi Steve
From the above I'm asuming you're using Macroscript Razor (Not MVC Razor).
If So I think you should be able to use "OrderBy" as described in this post http://umbraco.com/follow-us/blog-archive/2011/3/1/umbraco-razor-feature-walkthrough-%E2%80%93-part-4.aspx
Does this help?
/Jan
I can't seem to use any objects with the "rssItems" as it is is a XmlNodelist variable. Is there another way to do this?
not sure this is possible on an xmlNodeList directly... however as you have you xmlDicument you can use an XPathNavigator to manipulate..
Something like this...(ps untested and you might have to parse you event-date if it's not UTC format...
XPathNavigator nav = doc.CreateNavigator(); XPathExpression exp = nav.Compile("//item"); exp.AddSort("event-date",XmlSortOrder.Ascending,XmlCaseOrder.None,"",XmlDataType.DateTime); XPathNodeIterator iter = nav.Select(exp); while(iter.MoveNext()) { string res = iter.Current.Value; }
Is there a way to limit the number of items coming into the feed?
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Sorting a RSS Feed by Date
I am bringing in an RSS feed using the razor below. I need 2 things though: to be able to sort by a node <event-date> and to only list the 5 most recient items in the feed. Any help would be appreciated. Thanks!
@using System.Xml.XPath;
@using System.Xml;
@using umbraco.MacroEngines
@inherits umbraco.MacroEngines.DynamicNodeContext
@{
XmlTextReader udBrudRSS = new XmlTextReader("http://rosehulman.imodules.com/controls/cms_v2/components/rss/rss.aspx?sid=1554&gid=1&calcid=1110&page_id=402");
XmlDocument doc = new XmlDocument();
doc.Load(udBrudRSS);
XmlNodeList rssItems = doc.SelectNodes("//item");
}
<ul class="rss-feed">
@{
foreach (XmlNode node in rssItems) {
<li>
<div class="date">@node["event-date"].InnerText</div>
<a href="@node["link"].InnerText">@node["title"].InnerText</a>
</li>
}
}
</ul>
Hi Steve
From the above I'm asuming you're using Macroscript Razor (Not MVC Razor).
If So I think you should be able to use "OrderBy" as described in this post http://umbraco.com/follow-us/blog-archive/2011/3/1/umbraco-razor-feature-walkthrough-%E2%80%93-part-4.aspx
Does this help?
/Jan
I can't seem to use any objects with the "rssItems" as it is is a XmlNodelist variable. Is there another way to do this?
not sure this is possible on an xmlNodeList directly... however as you have you xmlDicument you can use an XPathNavigator to manipulate..
Something like this...(ps untested and you might have to parse you event-date if it's not UTC format...
Is there a way to limit the number of items coming into the feed?
is working on a reply...