Storing WDDX Packets

So far, in this chapter, we have covered all sorts of techniques for serializing and deserializing WDDX packets. All our examples have shown the serialization and deserialization process occurring on the same page. While great for illustrative purposes, the examples have little practical application. After all, why would you want to serialize and then deserialize a packet on the same page? This leads us to the topic for this section—storing your WDDX packets so that you can refer to them later. There are two ways you can store WDDX packets: in a text file or in a database (including LDAP directories). The next two sections discuss these two methods and provide examples of both storing and retrieving packets.

Storing Packets in a Text File

One of the most interesting things about WDDX is you can use it to store for data without having to write the data to a database. For example, record-set data stored in a WDDX packet is much more useful than it is when it’s stored in a delimited text file. Example 20-8 takes a query object and serializes it to a WDDX packet. The resulting WDDX pack is then written to a text file using the CFFILE tag.

Example 20-8. Storing a WDDX Packet Containing a Record Set in a Text File

<!--- get all employee records ---> <CFQUERY NAME="GetEmployeeInfo" DATASOURCE="ProgrammingCF" DBTYPE="ODBC"> SELECT * From EmployeeDirectory </CFQUERY> <!--- serialize the employee records to a wddx packet ---> <CFWDDX ACTION="CFML2WDDX" INPUT="#GetEmployeeInfo#" ...

Get Programming ColdFusion now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.