I was just reading over on Truths and Lies a post by Christ Scott about using Meta Data in ColdFusion. I have used meta data before and it is pretty sweet-ass. But what was very interesting to me about this post was a comment by Scott Arbeitman who states that you could use XML style name space attribute notation (as in "cs:" for Cold Spring) in ColdFusion. This is pretty interesting. To test this out, I did a little demo for myself:
<!--- Define a standard ColdFusion user defined function but add some "kinky" name space attributes to the declaration. ---> <cffunction name="Test" access="public" returntype="string" output="false" hint="Returns a string" <!--- Add custon attributes for kinky name space. ---> kinky:author="Ben Nadel" kinky:datecreated="2007/01/30" > <cfreturn "This is a test for XML style attributes" /> </cffunction>
Notice that the Author and DateCreated attributes are for the "kinky" name space only. Now, if I dump out the function object:
<!--- Dump out the UDF. ---> <cfdump var="#VARIABLES.Test#" label="Test() UDF" />
... you will see that nothing has changed:
However, if you dump out the meta data for the UDF:
<!--- Dump out meta data. ---> <cfdump var="#GetMetaData( VARIABLES.Test )#" label="Test() UDF Meta Data" />
... you will see that the XML style attributes are keys in the meta data structure:
Very interesting. Once it is in the meta data object, it is very easy to access as a structure key:
<!--- Get the UDF meta data. ---> <cfset objMetaData = GetMetaData( VARIABLES.Test ) /> <!--- Get the author. ---> <cfset strAuthor = objMetaData[ "kinky:author" ] />
Now, I know ZERO about name spaces (and not much more about XML) and in fact, I just wrote a blog entry about stripping them out, so I don't know what this would be used for. But I do like the idea of being able to have attributes that don't get confused with the inherent ColdFusion attributes (which I guess might be the whole idea behind name spaces).
Want to use code from this post? Check out the license.