Countdown timer

Social Share Toolbar

I recently found myself in need of a countdown timer. Out of laziness I Googled around a bit but found nothing I wanted to use so I relented and threw this together. Enter a number of seconds and the countdown timer will count down to zero from that time. Download the source here.

-rG

Output ColdFusion Query Results to XML

Social Share Toolbar

I don’t claim to be a ColdFusion expert by any stretch of the imagination, but recently I found myself in need of coming up with a way to output query results to an XML file. My example below is based on an absolutely hideous article I stumbled across on the ColdFusion Developer Center. The example they provide has several errors in syntax: unclosed tags, unclosed quotes, unOPENED pounds, etc. It also only outputs one record!

After about an hour of playing with it I was able to get the code working properly and I thought I’d share a very basic example. The following code queries a database for names and phone numbers then outputs them all to a file name phonelist.xml in the current path:

<cfquery name="qGetPhoneList" datasource="datasource">
select first_name,last_name,phone from employees
</cfquery>

<!—Create a temporary variable "tempxml" to hold our XML document—>

<cfset tempxml = "<?xml version =""1.0""?>
<!DOCTYPE phonelist [
<!ELEMENT phonelist (firstname,lastname,phone)>
]>
<phonelist>">
<cfloop query="qGetPhoneList">
<cfset tempxml = "#tempxml#
<cid>#Trim("#XMLFormat(first_name)#")#</cid>
<s>#Trim("#XMLFormat(last_name)#")#</s>
<r>#Trim("#XMLFormat(phone)#")#</r>
">
</cfloop>
<cfset tempxml = "
#tempxml#
</phonelist>">

<!—show the XML in the HTML output —>
<P>This is a simple XML document that’s been generated by the ColdFusion code. </P>
<cfoutput>
<xmp>
#tempxml#
</xmp>
</cfoutput>

<!—write out the XML—>
<cfset writePath=#ExpandPath("phonelist.xml")#>
<cfoutput>
#writePath#<br />
<cffile action = "Write" file="#writePath#" output="#tempxml#">
</cfoutput>

-rG