Skip to main content
Known Participant
June 6, 2008
Question

SQL to XML for AJAX

  • June 6, 2008
  • 3 replies
  • 706 views
Greetings,

I have been a CFer for a while and am dipping my toe into the Spry/AJAX world. What I am attempting to do is not only learn Spry/AJAX to develop RIAs, but go down the AIR path. I do nto know if this is the right place to ask this, but here goes...

I hav a SQL database that contains the data for my app. If I were simply developing a CF app, I would just use a basic cfquery statement. In order to get an XML file out of the SQL database for my Spry/AJAX app, I built a file using the cfxml tag. It worked great, but my only concern is the refreshing of the XML file from the SQL database. What is the standard best practive to get this done? Do I call a CFschedule tag? Call the cfxml tag to run or what? I want to make sure my end users have the most upto date XML data as possible.

Any guidance would be appreciated.

Thanks in advanced.

~Clay
This topic has been closed for replies.

3 replies

fs22Author
Known Participant
June 6, 2008
Allow me to explain some more. I can generate the XML with CF. What my question is...how do I have the CF code generate the XML when the app is instantiated using Spry? I want to make sure the XML is as up to date from the SQL database as possible.
Inspiring
June 9, 2008
You call a cfc to populate your spry dataset, eg see attached code

The cfc would use cfquery as per usual, but you just create your xml on the fly, see attached code

Then parse and convert the xml to a string, then return the xml string, see attached code

Thus you now have a spry dataset

Ken

Participating Frequently
June 6, 2008
Don't have any thing to share. You start coding, if you stumble get back with your issue.

Your page would be pretty simple and straightforward:

<cfcontent type="text/xml" reset="yes" />
<?xml version="1.0" encoding="utf-8"?>
<root>
<writeanyxmlhere />
</root>
<cfabort />

Use of <cfabort> would be "required" if your application has footers.

Sam
Adobe Certified Flash and
Advanced ColdFusion Developer
Participating Frequently
June 6, 2008
Hi,

I would suggest you to use your .CFM file to output xml data dynamically to clients. You can use use <cfcontent type="text/xml" reset="yes"> to specify the content type of your .CFM file as XML. This way your xml is a dynamic one, as opposed to a static xml.

Do not use <cfsavecontent> to write it to disk - disks operations are always slower. Simply, send the data back to client. For caching purpose, consider using cachedWithin attribute of <cfquery> tag - this will take care of your page's performance.

Sam
Adobe Certified Flash and
Advanced ColdFusion Developer
fs22Author
Known Participant
June 6, 2008
That sounds like a good idea. Do you have any examples that I can see please?
Inspiring
June 6, 2008