Menu

Live Data from WDDX

October 6, 1998

Lisa Rein

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

A WDDX.JS package, distributed with Cold Fusion, is available freely from Allaire. This package provides two objects. The first object is for serializing existing JavaScript objects into WDDX. Once serialized, a developer can use the XML packet however they wish, but most likely it will be posted to the server as a hidden form field or URL token. The second object provides a set of methods for using record sets in JavaScript. These record sets will transparently work with WDDX.

The client-side parser could be written in Java, ActiveX, Perl, or any other programming language as long as it can interface with the client application. For this reason JavaScript is preferable because support is already included in most browsers. One client-side parser already exists.

Allaire collaborated with Nate Weiss to use Jeremie Miller's JavaScript-based XML parser to develop a JS-native WDDX deserialization module. Using this module one can consume WDDX data on the browser and deserialize it there. This becomes very useful for making HTTP requests for data using a hidden frame: another useful means of using JavaScript for passing state.

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

 

The example above is a demonstration of JavaScript object instantiation on the client. However, by expressing the characteristics of objects in XML, these objects can be instantiated on the client or the server, in whatever programming language environment is available. The point is to begin thinking about representing objects in a language-independent manner. WDDX's packets accomplish this goal. WDDX packets are very simple, but the concepts could be extended to describe much more complex data structures.

Conclusion

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.