Copied to clipboard

Flag this post as spam?

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


  • Steve 472 posts 1216 karma points
    Mar 19, 2015 @ 21:48
    Steve
    0

    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:

    @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>
  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Mar 20, 2015 @ 11:43
    Jan Skovgaard
    0

    Hi Steve

    I think you should be able to simply use @node["title].InnerText.ToLower() !='normal'

    Does that work?

    /Jan

  • Steve 472 posts 1216 karma points
    Mar 20, 2015 @ 13:25
    Steve
    0

    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". 

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Mar 20, 2015 @ 16:59
    Jan Skovgaard
    100

    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

  • Steve 472 posts 1216 karma points
    Mar 20, 2015 @ 21:08
    Steve
    0

    That works. I just had to add !@node["title].InnerText.Contains("normal") for my purpose. Thanks Jan!

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Mar 20, 2015 @ 21:11
    Jan Skovgaard
    0

    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

  • Steve 472 posts 1216 karma points
    Mar 20, 2015 @ 21:13
    Steve
    0

    One more thing Jan, how would I change the time inbetween RSS feed updates? 

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Mar 20, 2015 @ 21:18
    Jan Skovgaard
    0

    Hi Steve

    How would you like to change the time? Is it the format displayed or?

    /Jan

  • Steve 472 posts 1216 karma points
    Mar 20, 2015 @ 21:21
    Steve
    0

    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?

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Mar 20, 2015 @ 21:23
    Jan Skovgaard
    0

    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

  • Steve 472 posts 1216 karma points
    Mar 20, 2015 @ 21:30
    Steve
    0

    I guess I need some way to reload the webpage or just the RSS feed to see if the feed has been updated.

  • Steve 472 posts 1216 karma points
    Mar 20, 2015 @ 22:01
    Steve
    0

    Yeah, that's what I thought. Thanks for your help.

Please Sign in or register to post replies

Write your reply to:

Draft