I'm parsing external RSS feed (for train times); main <Service> nodes sometimes contain <Platform> node and sometimes not. If there is one or more <Service> node without a <Platform> node there is an 'Error loading MacroEngine script' and expected results of macro don't display.
no worries.. ps the inbuilt library fucntion also accepts a parameter to cache.. in case that appeals (for not have 1000's of users hitting the rss constantly)
Not sure there is any documentation... I noticed it in the source when I was looking to addess an issue with GetXmlDocumentByUrl() passing a useragent of ie4.. so ending up with issues
/// <param name="CacheInSeconds">The cache in seconds (so 900 would be 15 minutes). This is independent of the global cache refreshing, as it doesn't gets flushed on publishing (like the macros do)</param>
Check if node exists in external RSS feed
I'm parsing external RSS feed (for train times); main <Service> nodes sometimes contain <Platform> node and sometimes not. If there is one or more <Service> node without a <Platform> node there is an 'Error loading MacroEngine script' and expected results of macro don't display.
How can I check if this node exists so that I don't try displaying non-existent nodes, which makes code fall over?
Thanks
Robin
How are you parsing?
You could use the umbraco.library:GetXmlDocumentByUrl('URL') [http://our.umbraco.org/wiki/reference/umbracolibrary/getxmldocumentbyurl]
And once it's xml then use xpath selectsinglenode to determine if the node exists..
alternatively can't you just wrap your try to display the missing node in a try {}catch{} construct...
I guess it all depends on the umbraco version and razor/xslt/usercontrol option that you are using,
I have this:
... but the "Platform" node doesn't always exist (usually, but not always). When it doesn't, the whole thing falls over.
Thanks
Sorted! This works…
Thanks for the pointers, Mike.
no worries.. ps the inbuilt library fucntion also accepts a parameter to cache.. in case that appeals (for not have 1000's of users hitting the rss constantly)
Actually that might be of interest: where would I read up on that?
Not sure there is any documentation... I noticed it in the source when I was looking to addess an issue with GetXmlDocumentByUrl() passing a useragent of ie4.. so ending up with issues
https://github.com/umbraco/Umbraco-CMS/blob/d1c5ddc03dfb79195e1c97eededcabc9dcaa1365/src/Umbraco.Web/umbraco.presentation/library.cs
is working on a reply...