I am pulling in a RSS feed that will have emergency crisis information that I want to appear only when the "title" node doesn't contain the word "normal". I would like it to be able to match "normal" and "NORMAL" or any interation of it "nORmaL". Is there a way to check this? Regular expression maybe? Here is what I have so far:
@using System.Xml.XPath;
@using System.Xml;
@using umbraco.MacroEngines;
@inherits umbraco.MacroEngines.DynamicNodeContext
@{
//Fetch RSS XML
XmlTextReader udBrudRSS = new XmlTextReader("http://www.getrave.com/rss/emporia/channel1");
//Create new XML document
XmlDocument doc = new XmlDocument();
//Load in our remote XML into our XML document
doc.Load(udBrudRSS);
//Select our nodes we want with some xPath
XmlNodeList rssItems = doc.SelectNodes("//item");
}
<ul class="rss-feed">
@{ //For each item node we can then ouput what we want
var i = 0;
foreach (XmlNode node in rssItems)
{
if(@node["title"].InnerText != "normal" ) {
<li>
<a href="@node["link"].InnerText">@node["title"].InnerText</a>
<p class="description">@Html.Raw(@node["description"].InnerText)</p>
<div class="date">@Html.Raw(@node["pubDate"].InnerText)</div>
</li>
}
i++;
if (i == 5){ break; }
}
}
</ul>
Thanks Jan, that sould work. Do you know of a way to check for if any of the inner text contanins the word normal? eg "Condition normal" or "normal status".
Hmm..I think you should be able to use something Contains() somehow. Perhaps something like @node["title].InnerText.Contains("normal") - Have not tested though but there should be an option to use "Contains".
I am sorry, I meant the time that it refreshes the rss feed on the page. I need the message on the page to change shortly after the feed is changed. is that possible without a page reload?
I think that's another topic - But you can probably use some ajax stuff in order to have the feed update whenever new items that should go into the feed are published. But otherwise it will require a page reload yes :)
RSS Script that Checks InnerText
I am pulling in a RSS feed that will have emergency crisis information that I want to appear only when the "title" node doesn't contain the word "normal". I would like it to be able to match "normal" and "NORMAL" or any interation of it "nORmaL". Is there a way to check this? Regular expression maybe? Here is what I have so far:
Hi Steve
I think you should be able to simply use @node["title].InnerText.ToLower() !='normal'
Does that work?
/Jan
Thanks Jan, that sould work. Do you know of a way to check for if any of the inner text contanins the word normal? eg "Condition normal" or "normal status".
Hi Steve
Hmm..I think you should be able to use something Contains() somehow. Perhaps something like @node["title].InnerText.Contains("normal") - Have not tested though but there should be an option to use "Contains".
/Jan
That works. I just had to add !@node["title].InnerText.Contains("normal") for my purpose. Thanks Jan!
Hi Steve
Very happy to hear that :) - Remember to mark the post as solved so others can benefit if they come across the same issue some day.
Happy weekend!
/Jan
One more thing Jan, how would I change the time inbetween RSS feed updates?
Hi Steve
How would you like to change the time? Is it the format displayed or?
/Jan
I am sorry, I meant the time that it refreshes the rss feed on the page. I need the message on the page to change shortly after the feed is changed. is that possible without a page reload?
Hi Steve
I think that's another topic - But you can probably use some ajax stuff in order to have the feed update whenever new items that should go into the feed are published. But otherwise it will require a page reload yes :)
/Jan
I guess I need some way to reload the webpage or just the RSS feed to see if the feed has been updated.
Yeah, that's what I thought. Thanks for your help.
is working on a reply...