<!--- This example shows the use of CFWDDX --->
<HTML>
<HEAD>
<TITLE>CFWDDX Example</TITLE>
</HEAD>

<BASEFONT FACE="Arial, Helvetica" SIZE=2>
<BODY  bgcolor="#FFFFD5">

<H3>CFWDDX Example</H3>

<P>The CFWDDX tag can be used to serialize and de-serialize CFML data structures to the XML-based WDDX
format. It can also be used to generate JavaScript statements instantiating JavaScript objects equivalent to the
contents of a WDDX packet or some CFML data structures.

<P>The following example demonstrates the serialization/deserialization of CFML data structures. First a complex
CFML data structures is built. It consists of a one-dimensional array whose elements are of different types:
numbers, strings, booleans, date-time values, and even a query. 

The data structure is then serialized to create a WDDX packet in the variable wddxPacket. The packet is
outputted so that its contents can be inspected. This step demonstrates the serialization of CFML data structures
to the WDDX format.

To demonstrate the deserialization of CFML data structures, the WDDX packet is deserialized and the resulting
CFML data structure stored in the variable wddxResult. To verify the success of the deserialization, some of the
columns of the deserialized query are outputted.

<!--- Create a simple query  --->
<CFQUERY NAME='q' DATASOURCE="cfsnippets">
        SELECT Message_Id, Thread_id, Username, Posted FROM Messages
</CFQUERY>
 
<!--- Create a simple array --->
<CFSET a = ArrayNew(1)>
<CFLOOP INDEX=i from=1 to=5>
        <CFSET a[i] = 'This is array element ###i#'>
</CFLOOP>
 
<!--- Show polymorphic data storage --->
<CFSET a[6] = true>
<CFSET a[7] = -12.456>
<CFSET a[8] = CreateDateTime(1996, 8, 1, 2, 3, 4)>
<CFSET a[9] = q>
 
<!--- Serialize data to WDDX format --->
Serializing CFML data...<p>
<CFWDDX ACTION='cfml2wddx' INPUT=#a# OUTPUT='wddxText'>
 
<!--- Display WDDX XML packet --->
Resulting WDDX packet is:
<XMP><CFOUTPUT>#wddxText#</CFOUTPUT></XMP>
 
<!--- Deserialize to a variable named wddxResult --->
Deserializing WDDX packet...<p>
<CFWDDX ACTION='wddx2cfml' INPUT=#wddxText# OUTPUT='wddxResult'>
 
<!--- Extract the query at array position 9 and output some data --->
Message_ID, Thread_ID, and Username columns from the deserialized query recordset:<p>

<CFSET qnew = wddxResult[9]>

<CFOUTPUT QUERY=qnew>
     #Message_ID# #Thread_ID# #Username#<BR>
</CFOUTPUT>

</BODY>
</HTML>       
