Live Data from WDDX
October 6, 1998
How Different Programs Exchange Data
Software developers are finding out that XML can be used on many different levels for the representation of data structures used by programs written in different languages.
The WDDX proposal from Allaire, makers of the Cold Fusion application server, uses XML to define how different applications can exchange data structures. WDDX stands for Web Distributed Data eXchange. It is a non-RPC-based way to move complex data structures over HTTP between application servers and servers and browsers. Unlike XML RPC, WDDX does not rely on remote procedure calls, but it does seek to describe distributed objects using XML.
WDDX provides a means for creating structurally equivalent representations of application-level data in a language-independent manner. Creating this representation is a process called serialization, but it should not be thought of in exactly the same way as it is often understood by object-oriented programmers.
Instead of a traditional serialization, involving RPC calls and stubs, applications that utilize WDDX produce packets that can be distributed to other applications. The application receiving a packet uses a process called deserialization to get the data from each packet.
The WDDX technology consists of a DTD and a set of serialization/deserialization modules for different application environments. The modules serialize data into packets for transport and deserialize them on the receiving end. These modules act as a standard language-specific interfaces between different applications. Efforts to develop Perl serialization/deserialization modules for WDDX (WDDX and Perl) are underway while Java modules are still a twinkle in the eye of its developer.
A packet in WDDX is Allaire's term for the XML document. These packets, which can be validated using the WDDX DTD, describe the characteristics of data objects such as associative arrays, database record sets, or other high-level datatypes, in a generic manner.
WDDX can be thought of as a very-high level API built on top of the DOM. For all XML data not based on the WDDX DTD, DOM processing makes the most sense. WDDX was designed to work well with the kinds of data used in web application development languages: both proprietary languages such as CFML and ASP, and open technologies such as Perl and Java. Allaire has also added COM support so that other Windows-based applications can benefit from WDDX.
WDDX has uses in server-browser, browser-server, and server-server communications. The first two benefit Web application development and make some rather complex Web development tasks easy. WDDX supports the view that servers on the Web expose useful data for other servers, not just unstructured HTML for browser use.
WDDX in Action
The following is a WDDX packet that represents an associative array (a hash table) containing a variety of data types.
<!DOCTYPE wddxPacket SYSTEM "wddx.dtd"> <wddxPacket version='0.9'> <header/> <data> <struct> <var name='s'> <string>a string</string> </var> <var name='n'> <number>-12.456</number> </var> <var name='d'> <dateTime>1998-06-12T04:32:12</dateTime> </var> <var name='b'> <boolean value='true'/> </var> <var name='a'> <array length='2'> <number>10</number> <string>second element</string> </array> </var> <var name='obj'> <struct> <var name='s'> <string>a string</string> </var> <var name='n'> <number>-12.456</number> </var> </struct> </var> </struct>< </data> </wddxPacket>
It defines a root-level object that is a structure consisting of six properties:
- s which is the string a string,
- n which is the number -12.456,
- d which is the date-time value June 12, 1998 4:32:12am,
- b which is the boolean value true,
- a which is an array of two elements (10 and 'second element'), and
- obj which is a structure with two properties s and n
Allaire's WDDX system is significant because it makes use of XML's natural ability to work within any environment, be it client-server, server-server, or on an offline client. Your document packets could be circulated around the world without anyone even hitting your own server -- except for the occasional validation. Once you define your objects in XML, then you can have them running on machines in different environments all over the world.