DP_WDDX Library

Download | Revision History | Usage | Functions | Examples

The DP_WDDX library provides JavaScript support for the WDDX (Web Distributed Data Exchange) standard. This library (is an attempt to) provide updated WDDX support in the JavaScript environment. While the JavaScript libary support contained in the official WDDX SDK is functional it is quite old and does not take advantage of modern JavaScript capabilities and techniques.

  • All features of the WDDX specification are fully supported.
  • The library's deserialization routines are fully DOM-based.
  • The library has a very small footprint. Only the documented functions are added and nothing else (no properties, global variables or other suprises)

You can also find out more about the WDDX specification.

Download back to top

This component requires a JavaScript (ECMAScript) 1.3 (or better) development enviroment. All downloads and code are covered by our Source Code Policy.

DP_WDDX.zip, 5.41kb Zip-Format Archive

Revision History back to top

June 21, 2007

  • Fixed an embarassing but important bug in dataTime deserialization: the original component couldn't deserialize a date that it serialized. It now does. Thanks to Dan G. Switzer, II for pointing it out and contributing the fix.
  • Fixed a small bug. Two extraneous global variables ("SerializeChars" and "DeserializeChars") were being created. They are now function-local variables as intended.

October 03, 2005

  • Initial Release.

Usage back to top

The library consists of a single JavaScript file with a .JS extension.

Importing the Library

The library must be imported before it is used. To import the library use the <script> tag. For example: <script type="text/javascript" src="DP_WDDX.js"></script>.

Your path may vary depending on the location of the script on your server.

Using the Library

Once the library has been imported you may access any of the functions within it directly. For example:

var MyWDDX = dpWDDX("serialize", MyObject);

See the Functions section for more information.

Recommendations

There are many reason that WDDX processing may fail. Corrupt (or badly constructed) packets, unexpected data structures, human error, etc. For this reason it's suggested that you take advantage of modern JavaScript's error handling capacity and wrap all of your WDDX processing in a try {} catch() {} structure. You can then gracefully recover from parsing errors within the application.

WDDX is a purely aggregated dialect: there is no capacity to handle circular or recursive references. Passing objects with such references to dpWDDX will almost certainly (due to the endless loop being created) result in an application crash.

Functions back to top

There is only one function currently available in the library, the dpWDDX function:

dpWDDX()

Function Signature

dpWDDX(Action, Input)

Arguments

  • Action: String, Required. The action to perform. Can be either "serialize" (convert a native object to a WDDX packet) or "deserialize" (convert a WDDX packet to a native object).
  • Input: Object or String. Required. If Action is "serialize" this argument is the native object to be converted. If Action is "deserialize" this argument is the WDDX packet to be converted.

Return

Object or String. If Action is "serialize" returns a WDDX XML packet. If Action is "deserialize" returns the native object constructed from the packet.

Examples back to top

For examples of WDDX and information about how to use it see the WDDX Information available.

Serialization

To serialize a native JavaScript object to WDDX you might do this:

var MyWDDX = dpWDDX("serialize", MyObject);

Deserialization

To deseerialize a WDDX packet into a native JavaScript object you might do this:

var MyObject = dpWDDX("deserialize", MyWDDX);

785 Current Sessions; Time: 04:24:38 11-03-2010; Tick: 172