XML and WDDX


XML is used to describe data. For XML to work, both sender and recipient must agree on an XML language, and all data must be well formed according to that language. WDDX is Macromedia's contribution to the XML community. It is an open-source XML DTD (Document Type Definition) that defines generic data types such as strings, arrays, structures, and recordsets. WDDX is an XML language that defines datanot any specific implementation, but raw data itself. This can make data sharing via XML quick and painless (it doesn't require that an XML language be agreed upon).

XML was reviewed in Chapter 34, "XML."


The following example shows a two-dimensional array:

 <cfscript>  products=ArrayNew(2);  products[1][1]="33-2112";  products[1][2]="10";  products[1][3]="S";  products[2][1]="29-3564";  products[2][2]="8";  products[2][3]="M";  products[3][1]="21-1153";  products[3][2]="10";  products[3][3]="L"; </cfscript> 

If you then convert this data into WDDX, you see the following:

 <wddxPacket version='1.0'><header/><data><array length='3'> <array length='3'><string>33-2112</string><string>10</string> <string>S</string></array><array length='3'> <string>29-3564</string><string>8</string><string>M</string> </array><array length='3'><string>21-1153</string><string>10</string> <string>L</string></array></array></data></wddxPacket 

NOTE

Converting data into a WDDX packet is called serialization; converting it from WDDX back to native data is called deserialization.


Notice that the packet doesn't give the data a name as it did in the earlier example (like SKU or Quantity); rather, it defines the data generically as strings and arrays.

If you pass this packet to an ASP program or Perl script that understands the WDDX DTD, those programs will convert the data back into variables that are understood by their own systems.

The real power of WDDX is that it allows you to use a simplified implementation of XML without having to worry about learning XML or DTDs. The WDDX DTD is interpreted either by ColdFusion or by the other system that understands WDDX. The user never has to get his hands dirty.

NOTE

To learn more about WDDX, go to http://www.openwddx.org/.




Macromedia ColdFusion MX 7 Certified Developer Study Guide
Macromedia ColdFusion MX 7 Certified Developer Study Guide
ISBN: 0321330110
EAN: 2147483647
Year: 2004
Pages: 389
Authors: Ben Forta

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net