Quick Note: XmlAttributes

I have to use xml fairly often. Mostly for connecting to different web services. I haven't dealt with to many web services that return attributes within the XML like this:

<day d="0" t="Monday" dt="May 12">
<hi>73</hi>
<low>52</low>
<sunr>6:17 AM</sunr>
<suns>8:08 PM</suns>
<part p="d">
<icon>30</icon>
<t>Partly Cloudy</t>
<wind>
<s>17</s>
<gust>N/A</gust>
<d>291</d>
<t>WNW</t>
</wind>
<bt>P Cloudy</bt>
<ppcp>10</ppcp>
<hmid>39</hmid>
</part>
<part p="n">
<icon>31</icon>
<t>Clear</t>
<wind>
<s>16</s>
<gust>N/A</gust>
<d>337</d>
<t>NNW</t>
</wind>
<bt>Clear</bt>
<ppcp>10</ppcp>
<hmid>61</hmid>
</part>
</day>

I seem to always forget how to access the attributes. The attributes in above example are d="0" t="Monday" dt = "May 12" as well as p="d" and p = "n".

I have decided to blog about it so I remember next time.

To access the above attributes use XmlAttributes. If the variable containing the above XML was called XMLVar then you would use the following code to access the attributes:

Day of Week: #XMLVar.day.XmlAttributes.t#
Date: #XMLVar.d.XmlAttributes.dt#

Nothing to it really.

Want to see Coldfusion Support for the Google App Engine?

I think it would be great if the Google App Engine supported CFML.

If you feel the same show your support by visiting the link below and give it a star and a comment.

http://code.google.com/p/googleappengine/issues/detail?id=73

BlogCFC was created by Raymond Camden. This blog is running version 5.7.