Razor fetch RSS XML


/ Published in: C#
Save to your folder(s)

Razor snippet that fetch external RSS feed in Umbraco.


Copy this code and paste it in your HTML
  1. @using System.Xml.XPath;
  2. @using System.Xml;
  3.  
  4. @{
  5. //Fetch RSS XML
  6. XmlTextReader udBrudRSS = new XmlTextReader("http://myblog.com/rss");
  7.  
  8. //Create new XML document
  9. XmlDocument doc = new XmlDocument();
  10.  
  11. //Load in our remote XML into our XML document
  12. doc.Load(udBrudRSS);
  13.  
  14. //Select our nodes we want with some xPath
  15. XmlNodeList rssItems = doc.SelectNodes("//item");
  16.  
  17. }
  18. <ul>
  19. @{
  20. //For each item node we can then ouput what we want
  21. foreach (XmlNode node in rssItems)
  22. {
  23.  
  24.  
  25.  
  26. <li>
  27. <div class="date">@node["pubDate"].InnerText</div>
  28. <a href="@node["link"].InnerText">@node["title"].InnerText<span></span></a>
  29. </li>
  30. }
  31. }
  32. </ul>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.