Note: This blog post is from 2006. Some content, links and indeed comments from others may be outdated--though not necessarily. Corrections are welcome, in the comments. I may revise the content if necessary.As I explore Spry, one of the first demos I tried to write from scratch--rather than use code from an existing demo--was an experience that taught me a couple of lessons I now want to share with others.
(As suggested in the entry's title, this is part of a series I'm doing on Spry. Be sure to check out the other entries.)
Make sure you understand your XML
I made a mistake of trying to eyeball an XML file's layout to determine the nesting needed to create the XPath value for the XMLDataset constructor. Oops.
[If you're new to Spry, I've likely just gotten way over your head! This entry is for those already checking it Spry. Newcomers should leave right now and go check out the "bolded" resources I point to in my Spry compendium for that sort of help....Go on. I'm serious! You won't appreciate the rest otherwise! :-)]
I was looking at an RSS stream that looked like this (abbreviated):
<title>Blog entry 1</title><br>
So I thought that the "rss" element was outermost and the rest, including my desired "title", were all children, so I set the xpath to be rss/title. And I got no generated output from Spry. Doh! It should have been rss/channel/title.
Here's a tip: open the desired XML file with some tool that shows you the XML in a nested tree structure. Perhaps easiest, you can just open the file using IE or Firefox (as of 1.5), which will show it using a special stylesheet that renders the XML in a nested structure.
Of course, if the destination you try to open doesn't respond with pure XML, you won't even be able to open it effectively with such tools, which will tell you that you have another problem (like forgetting to turn off debugging if generating XML from CFML, or forgetting to cause the CFML page to change the mime type to text/xml. More on both of those mistakes in a later entry).
Don't use spry:region on Table tag
Interested in creating an HTML table? OK, no noise please from the CSS crowd. Some of us old-timers are slow to the party or just don't gravitate to it for quick testing.
Anyway, I mistakenly assumed that if I wanted to create a table of multiple rows that I would just add the spry:region tag to the Table tag. I figured that since I would naturally want the spry:repeat on the TR tags, I should put the enclosing spry:region on the enclosing TABLE tag. Wrong! Should have RTFM.
Ok, I did. I just missed that. It clearly says in 2 of the key introductory articles that TABLE tags are one of many on which you are not to use spry:region. More important, the excellent Dynamic Table Tutorial also clearly shows how it's to be done.
You want to wrap the table, in a DIV for instance, and put the spry:region there. If you don't, you don't get an error. You just don't get any of the content you expected to be dynamically generated (which could appear to be a blank page or portion, depending on what you're doing).
Don't mistake spry:repeatchildren for spry:repeat
Similarly, I made another mistake when I copied a line of code to do the repeat, and I used code from an example that used spry:repeatchildren, rather than spry:repeat. Doh!
The Spry Data Set and Dynamic Region Overview says it best in describing the two:
One allows you to repeat an element and all of its content for each row in a given data set (spry:repeat), and another that allows you to repeat all of the children of a given element for each row in a given data set (spry:repeatchildren)
I have lots of other tasty tidbits to share, but they're more general than these related to me trying to write code from scratch.
For more like this: