best practice for retrieving external rss feed and displaying it in a template?
I was wondering if there are any packages anywhere, or tutorials for that matter, that show how i can retrieve an external rss feed, style & customize it and present it somewhere in a template? The search function doesn't immediatly return results...
Thanks Frederik & Sebastian, I need to do some filtering too though, only displaying items from the rss feed that have one specific category...
This is proving a challenge for my xslt knowledge (traversing through the xml structure in xslt), this is what i have not, but it's not managing to filter based on category (a rss item can have multiple ones)
any help with getting this filtering on category is more tha appreciated, it's the fact that an item has multiple ones that i'm having an issue with...
Cool, be aware though, that this will cause a request to a remote server with each page load, which might be slow (or fail) and could cost a lot of bandwith on both ends.
With Feed Cache, the content is being cached and only refreshed every so often. It still generate xml and can be filtered through XSLT. Something to consider..
Come to think of it, I don't exactly remember what it does out of the box! But I did something funky so I could get access to the cached XML, putting it in an xsl:variable so I could loop over it. This is how:
As soon as i have this set up i keep getting validation errors like these:
Error occured System.Xml.XmlException: An error occurred while parsing EntityName. Line 4, position 106.
at System.Xml.XmlTextReaderImpl.Throw(Exception e) at System.Xml.XmlTextReaderImpl.Throw(String res, String arg) at System.Xml.XmlTextReaderImpl.Throw(String res) at System.Xml.XmlTextReaderImpl.ParseEntityName() at System.Xml.XmlTextReaderImpl.ParseEntityReference() at System.Xml.XmlTextReaderImpl.Read() at System.Xml.XmlLoader.LoadNode(Boolean skipOverWhitespace) at System.Xml.XmlLoader.LoadDocSequence(XmlDocument parentDoc) at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace) at System.Xml.XmlDocument.Load(XmlReader reader) at System.Xml.XmlDocument.LoadXml(String xml) at umbraco.library.GetXmlDocumentByUrl(String Url)
And this error when i try to visualize the XSLT:
Error parsing the XSLT:
System.Xml.Xsl.XslTransformException: An error occurred during a call to extension function 'GetXmlDocumentByUrl'. See InnerException for a complete description of the error. ---> System.Xml.XmlException: An error occurred while parsing EntityName. Line 4, position 106. at System.Xml.XmlTextReaderImpl.Throw(Exception e) at System.Xml.XmlTextReaderImpl.Throw(String res, String arg) at System.Xml.XmlTextReaderImpl.Throw(String res) at System.Xml.XmlTextReaderImpl.ParseEntityName() at System.Xml.XmlTextReaderImpl.ParseEntityReference() at System.Xml.XmlTextReaderImpl.Read() at System.Xml.XmlLoader.LoadNode(Boolean skipOverWhitespace) at System.Xml.XmlLoader.LoadDocSequence(XmlDocument parentDoc) at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace) at System.Xml.XmlDocument.Load(XmlReader reader) at System.Xml.XmlDocument.LoadXml(String xml) at umbraco.library.GetXmlDocumentByUrl(String Url) --- End of inner exception stack trace --- at System.Xml.Xsl.Runtime.XmlExtensionFunction.Invoke(Object extObj, Object[] args) at System.Xml.Xsl.Runtime.XmlQueryContext.InvokeXsltLateBoundFunction(String name, String namespaceUri, IList`1[] args) at (XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime) at Root(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime) at Execute(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime) at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlSequenceWriter results) at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter writer, Boolean closeWriter) at System.Xml.Xsl.XmlILCommand.Execute(IXPathNavigable contextDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter results) at System.Xml.Xsl.XmlILCommand.Execute(IXPathNavigable contextDocument, XmlResolver dataSources, XsltArgumentList argumentList, TextWriter results) at System.Xml.Xsl.XslCompiledTransform.Transform(IXPathNavigable input, XsltArgumentList arguments, TextWriter results) at umbraco.macro.GetXsltTransformResult(XmlDocument macroXML, XslCompiledTransform xslt, Dictionary`2 parameters) at umbraco.presentation.umbraco.developer.Xslt.xsltVisualize.visualizeDo_Click(Object sender, EventArgs e)
The cached feed does render in a browser though, i've read here and there that this has to do with encoding of the xml content...
any news on this as it seems a client of us came back with this error too
it worked perfect begin february
but seems like the xslt now returns the same error as rik helsen has.
our feed is a feed from a flickr group
feed seems ok, but i have no clue as to what changed (defenatly nothing in the xslt, it seems to be a change in the feed that triggers this, as we didn't do any updates of the umbraco either )
Taking your XSLT from above, here's my take on it:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE xsl:stylesheet [
<!ENTITY nbsp " ">
]>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxml="urn:schemas-microsoft-com:xslt"
xmlns:umbraco.library="urn:umbraco.library"
xmlns:dc="http://purl.org/dc/elements/1.1/"
exclude-result-prefixes="msxml umbraco.library dc">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<!-- parameters source of the RSS feed and Filtertag -->
<xsl:variable name="url">http://www.orbitone.com/en/blog/rss.xml</xsl:variable>;
<xsl:variable name="tag">.NET</xsl:variable>
<xsl:template match="/">
<!-- check that the url isn't empty -->
<xsl:if test="string-length($url) > 0">
<!-- get the xml from the url (with the cache, in seconds) -->
<xsl:variable name="rss" select="umbraco.library:GetXmlDocumentByUrl($url, 3600)" />
<!-- test if the RSS feed has any items -->
<xsl:if test="count($rss/rss/channel/item[category = $tag]) > 0">
<ul id="rssblog">
<!-- apply the templates for the 'item' element, (which have a 'category' element containing the value of $tag -->
<xsl:apply-templates select="$rss/rss/channel/item[category = $tag]" />
</ul>
</xsl:if>
</xsl:if>
</xsl:template>
<xsl:template match="item">
<li class="rssBlogPost">
<a href="{link}" title="{title}" class="rssBlogLink">
<xsl:value-of select="title"/>
</a>
<span class="rssBlogDescription">
<xsl:value-of select="description" disable-output-escaping="yes" />
</span>
</li>
</xsl:template>
</xsl:stylesheet>
OK, here's what is different.
The "GetXmlDocumentByUrl" method has an overload to accept a cache expiry (in seconds), so that will give you some performance gains.
Once we get the RSS XML (in the $rss variable), we check if it has any <item> elements - coz if it doesn't then you'll get an empty <ul /> tag.
For the <xsl:apply-templates /> we add a conditional XPath to select only the <item> elements that have a <category> with the value of the $tag variable.
Then in the "match=item" template ... you can do whatever you need to in there!
I've been having this problem all damn day. Seems if you are using GetXmlDocumentByUrl in your templates and try to pass a variable through for the url it can choke. After 3 hours digging around I did a IIS restart out of desperation and its now cleared it. Something going on under the hood I'm just not sure what! So for anyone else who has it, try a IIS restart first to see if that clears it. More news as I have it.
best practice for retrieving external rss feed and displaying it in a template?
I was wondering if there are any packages anywhere, or tutorials for that matter, that show how i can retrieve an external rss feed, style & customize it and present it somewhere in a template? The search function doesn't immediatly return results...
All help is very much appreciated!
Kind regards,
Rik
this seems to be a pointer worth mentioning: http://old.kasperb.dk/2006/6/26/display-your-flickr-images-on-your-umbraco-driven-website.aspx (thanks Bart!)
Hello Rik!
I have some documentation on this, but it's on my private PC, If you don't make it until evening, I will dig it up when I get home :)
Have a great day,
Fredrik
I can recommend Darren Ferguson's Feed Cache package. It was pretty easy to install and use.
Thanks Frederik & Sebastian, I need to do some filtering too though, only displaying items from the rss feed that have one specific category...
This is proving a challenge for my xslt knowledge (traversing through the xml structure in xslt), this is what i have not, but it's not managing to filter based on category (a rss item can have multiple ones)
my current (not working) code:
any help with getting this filtering on category is more tha appreciated, it's the fact that an item has multiple ones that i'm having an issue with...
Got it, here's my current solution:
Cool, be aware though, that this will cause a request to a remote server with each page load, which might be slow (or fail) and could cost a lot of bandwith on both ends.
With Feed Cache, the content is being cached and only refreshed every so often. It still generate xml and can be filtered through XSLT. Something to consider..
Interesting, i'll give it a closer look!
bandwidth isn't really an issue in our case, but page speed is.
Come to think of it, I don't exactly remember what it does out of the box! But I did something funky so I could get access to the cached XML, putting it in an xsl:variable so I could loop over it. This is how:
As soon as i have this set up i keep getting validation errors like these:
And this error when i try to visualize the XSLT:
The cached feed does render in a browser though, i've read here and there that this has to do with encoding of the xml content...
This is the rss feed i'm working with:
http://oneoffice.orbitone.com/umbraco/plugins/FergusonMoriyama/FeedCache/OrbitOneBlog.xml
original:
http://www.orbitone.com/en/blog/rss.xml
any news on this as it seems a client of us came back with this error too
it worked perfect begin february
but seems like the xslt now returns the same error as rik helsen has.
our feed is a feed from a flickr group
feed seems ok, but i have no clue as to what changed (defenatly nothing in the xslt, it seems to be a change in the feed that triggers this, as we didn't do any updates of the umbraco either )
Hi Rik,
Taking your XSLT from above, here's my take on it:
OK, here's what is different.
Obviously tweak it as you see fit.
Good luck, Lee.
Hi Sander, if you can post your XSLT, we might be able to see what the problem is.
My guess would be that an XML namespace is missing from your XSLT - but that's a guess.
Thanks, Lee.
I've been having this problem all damn day. Seems if you are using GetXmlDocumentByUrl in your templates and try to pass a variable through for the url it can choke. After 3 hours digging around I did a IIS restart out of desperation and its now cleared it. Something going on under the hood I'm just not sure what! So for anyone else who has it, try a IIS restart first to see if that clears it. More news as I have it.
Cheers
Pete
is working on a reply...