Friday, January 5, 2007

Using Conditional CSS Selectors

The CSS I use in my applications is pretty straightforward. I stick with the basics, assigning styles based on element id, classes, and pseudo-classes.

When situations arise that require similar page elements to utilize differnet styles, I use ColdFusion or JavaScript code to evaluate the condition and assign the appropriate CSS class.

This article I found today is an excellent description about how to use CSS selectors to act only on page elements that meet a certain description--no JavaScript or server-side coding required:

Showing Hyperlink Cues with CSS

Since he makes a point of saying these selectors will work in IE 7, I can only assume that they won`t work (or at least not well) in IE 6, so you may not want to use these selectors unless you have a backup plan for mimicking the end-result using another method or you know your audience has upgraded to IE 7. Still, something worth knowing and a feature to look forward to as IE 6 rides off into the sunset.

Thursday, January 4, 2007

Catching Errors When Consuming RSS Feeds

Yesterday, Ben Forta blogged about an article by Ben Cortese on Consuming RSS Feeds with ColdFusion.

The article does a great job of providing simple, straightforward code for accessing an RSS feed and displaying it to the user. However, a few more lines of code would shield the user from errors caused by the feed not being available or by the malformed content within the feed.

As the article pointed out, you can retrieve the RSS feed from the remote site through the use of the tag, and then you can convert the XML in the feed to an XML object using the xmlParse function. If you enclose each of these steps within a block, you can intercept the errors and give your user a simple error message that explains there`s a problem with the feed.

For example, say you wanted to consume the main news feed from Digg.com (http://www.digg.com/rss/index.xml). Here`s how you would retrieve the feed and then convert it to an XML object with error-handling:

It`s a good idea to include this kind of error-handling whenever your application relies on external data in order to function properly so that the user knows that the problem lies with the source of the data rather than the application itself. And in the case of RSS feeds, the problem with the feed could be resolved within the next few minutes or so: the server providing the feed could come back up, or the problem entry in the feed could be removed (this is especially true of Web 2.0 user-driven sites where the feed content is updated frequently).