ColdFusion 9.0 Resources |
Moving complex data across the web with WDDXWDDX is an XML vocabulary for describing a complex data structure, such as an array, associative array (such as a ColdFusion structure), or a recordset, in a generic fashion. It lets you use HTTP to move the data between different application server platforms and between application servers and browsers. Target platforms for WDDX include ColdFusion, Active Server Pages (ASP), JavaScript, Perl, Java, Python, COM, Flash, and PHP. The WDDX XML vocabulary consists of a document type definition (DTD) that describes the structure of standard data types and a set of components for each of the target platforms to do the following:
This vocabulary creates a way to move data, its associated data types, and descriptors that allow the data to be manipulated on a target system, between arbitrary application servers. Note: The WDDX DTD, which includes documentation,
is located at www.openwddx.org/downloads/dtd/wddx_dtd_10.txt.
WDDX is a valuable tool for ColdFusion developers, however, its usefulness is not limited to CFML. If you serialize a common programming data structure (such as an array, recordset, or structure) into WDDX format, you can use HTTP to transfer the data across a range of languages and platforms. Also, you can use WDDX to store complex data in a database, file, or even a client variable. WDDX has two features that make it useful for transferring data in a web environment:
WDDX was created in 1998, and many applications now expose WDDX capabilities. The best source of information about WDDX is www.openwddx.org. This site offers free downloads of the WDDX DTD and SDK and additional resources, including a WDDX FAQ, a developer forum, and links to additional sites that provide WDDX resources. Uses of WDDXWDDX is useful for transferring complex data between applications. For example, you can use it to exchange data between a CFML application and a CGI or PHP application. WDDX is also useful for transferring data between the server and client-side JavaScript. Exchanging data across application serversWDDX is useful for the transfer of complex, structured data seamlessly between different application server platforms. For example, an application based on ColdFusion at one business could cfwddx use to convert a purchase order structure to WDDX. It could then use cfhttp to send the WDDX to a supplier running a CGI-based system. The supplier could then deserialize the WDDX to its native data form, the extract information from the order, and pass it to a shipping company running an application based on ASP. Transferring data between the server and browserYou can use WDDX for server-to-browser and browser-to-server data exchanges. You can transfer server data to the browser in WDDX format and convert it to JavaScript objects on the browser. Similarly, your application pages can serialize JavaScript data generated on the browser into WDDX format and transfer the data to the application server. You then deserialize the WDDX XML into CFML data on the server. On the server, you use the cfwddx tag to serialize and deserialize WDDX data. On the browser, you use WddxSerializer and WddxRecordset JavaScript utility classes to serialize the JavaScript data to WDDX. (ColdFusion installs these utility classes on your server as webroot/CFIDE/scripts/wddx.js.) WDDX and web servicesWDDX does not compete with web services. It is a complementary technology focused on solving simple problems of application integration by sharing data on the web in a pragmatic, productive manner at low cost. WDDX offers the following advantages:
Applications that take advantage of WDDX can continue to do so if they start to use web services. These applications could also be converted to use web services standards exclusively; only the service and data interchange formats: not the application model, must change. How WDDX worksThe following example shows how WDDX works. A simple structure with two string variables could have the following form after it is serialized into a WDDX XML representation: <var name='x'> <struct> <var name='a'> <string>Property a</string> </var> <var name='b'> <string>Property b</string> </var> </struct> </var> When you deserialize this XML into CFML or JavaScript, the result is a structure that is created by either of the following scripts:
Conversely, when you serialize the variable x produced by either of these scripts into WDDX, you generate the XML listed in the preceding code. ColdFusion provides a tag and JavaScript objects that convert between CFML, WDDX, and JavaScript. Serializers and deserializers for other data formats are available on the web. For more information, see www.openwddx.org. Note: The cfwddx tag and the wddx.js
JavaScript functions use UTF-8 encoding to represent data. Any tools
that deserialize ColdFusion-generated WDDX must accept UTF-8 encoded
characters. UTF-8 encoding is identical to the ASCII and ISO 8859 single-byte
encodings for the standard 128 "7-bit" ASCII characters. However,
UTF-8 uses a two-byte representation for "high-ASCII" ISO 8859 characters
where the initial bit is 1.
WDDX data type supportThe following text describes the data types that WDDX supports. This information is a distillation of the description in the WDDX DTD. For more detailed information, see the DTD at www.openwddx.org. Basic data typesWDDX can represent the following basic data types:
Complex data typesWDDX can represent the following complex data types:
Data type comparisonsThe following table compares the basic WDDX data types with the data types to which they correspond in the languages and technologies commonly used on the web:
Time zone processingProducers and consumers of WDDX packets can be in geographically dispersed locations. Therefore, it is important to use time zone information when serializing and deserializing data, to ensure that date-time values are represented correctly. The cfwddx action=cfml2wddx tag useTimezoneInfo attribute specifies whether to use time zone information in serializing the date-time data. In the JavaScript implementation, useTimezoneInfo is a property of the WddxSerializer object. In both cases, the default useTimezoneInfo value is True. Date-time values in WDDX are represented using a subset of the ISO8601 format. Time zone information is represented as an hour/minute offset from universal time (UTC); for example, “2002-9-8T12:6:26-4:0”. When the cfwddx tag deserializes WDDX to CFML, it automatically uses available time zone information, and converts date-time values to local time. In this way, you need not worry about the details of time zone conversions. However, when the JavaScript objects supplied with ColdFusion deserialize WDDX to JavaScript expressions, they do not use time zone information, because in JavaScript it is difficult to determine the time zone of the browser. |