Sam Farmer

Growing up I never imagined I would play bass guitar for the Dave Matthews Band. And indeed it never happened.

But I have become passionate about making software.

Two ColdFusion 8 Features Make My Day a Little Easier

September 21, 2007

At work I have recently used two of the less sexy but still solid new features of ColdFusion 8.

cfloop file="" index=""
This will take a file, loop over it line by line and put each line in the variable assigned in index. Now this used to be possible by using cffile and then looping over it as if it where a list. The advantages of the new way are a) the less code to write and b) ColdFusion now reads the file line by line and does not place it in memory (as it does with the cffile tag) meaning its possible to parse huge files without seeing your memory jump. I parsed a 140 MB file with no memory increase (thanks server monitor!).

cffeed source="" query=""
Next up I had the need to process some RSS feeds so enter the cffeed tag. The cffeed tag takes a source and returns it in several ways. My favorite being as a query. I've worked with queries for 10 years so am much more comfortable processing that than having to loop over some XML.

The cffeed tag has multiple return formats; if you want the XML use the xmlVar attribute, just the properties of the feed with the properties attribute, the XML parsed into an array and structure use name or to save it as a file with the outputFile attribute. In fact any combination of the above will work. cffeed can also create RSS feeds. Read the full documentation here

A few other notes from using RSS:
1) Wordpress seems to return better information in its atom feeds. Just add atom/ to the end of a feed, it seems to be an undocumented feature (or one I could not find).
2) Atom feeds return datetime with a T between the date and time. ColdFusion will not read this as a datetime. A workaround? Simply replace the T with a space before calling any date or time functions.

Both of these new features made my day a little easier which is a big reason for using ColdFusion in the first place.


No Comments

Some comments have been lost over the years due to moving hosts.

More


More blog entries that I have written.

Code coloring by PRISM.