Yesterday I blogged about writing an interface to the kuler API. A user wrote me and mentioned he had tried to do the same, but ran into a problem with the XML. Kuler's feeds include XML that may look a bit odd. Consider this snippet:
<!-- theme title --> <title>Theme Title: my theme</title> <!-- url link to theme within the kuler application --> <link>http://kuler.adobe.com/index.cfm#themeID/11</link> <guid>http://kuler.adobe.com/index.cfm#themeID/69579</guid> <enclosure xmlns="http://www.solitude.dk/syndication/enclosures/"> <title>Perfect Fit</title> <link length="1" type="image/png"> <url>http://kuler.adobe.com/kuler/API/rss/png/generateThemePng.cfm?themeid=69579</url> </link> </enclosure> <!-- description content which includes theme png, artist, posted date, tags, and swatch hex colors --> <kuler:themeItem> <!-- themeID --> <kuler:themeID>11</kuler:themeID> <!-- theme title --> <kuler:themeTitle>my theme</kuler:themeTitle> <!-- url link to theme's png image --> <kuler:themeImage> http://kuler.adobe.com/kuler/API/rss/png/generateThemePng.cfm?themeid=11 </kuler:themeImage>
While it starts off rather simple, you may notice the tags towards the end have colons in them. The user who wrote me had trouble working with them because he was trying to use struct/array notation like so:
<cfset someval = somenode.item.kuler:themeitem.xmlText>
Obviously this threw an error since colons aren't legal in ColdFusion variables. What he forgot though is that when you treat XML like a struct, you can use any struct notation you want - even bracket notation. The line above could be rewritten like so:
<cfset someval = somenode.item["kuler:themeitem"].xmlText>
Notice how the 'funky' XML tag (kuler:themeitem) is used as a string inside the brackets.
This also applies to any structure of course.