WDDX

WDDX: Web Distributed Data Exchange, or WDDX, is a free, open XML-based technology that allows Web applications created with any platform to easily exchange data with one another over the Web.

For more info, See http://www.openwddx.org/ .

Are there any WDDX-parsers for TCL?


Example packet #1:

  <wddxPacket version='1.0'>
    <header comment='Example WDDX packet' />
    <data>
      <string>This is WDDX packet example</string>
    </data>
  </wddxPacket>

Example packet #2:

  <wddxPacket version='1.0'>
    <header comment='Another example' />
    <data>
      <struct>
        <var name='pi'>
          <number>3.1415926</number>
        </var>
        <var name='cities'>
          <array length='3'>
            <string>Austin</string>
            <string>Novato</string>
            <string>Seattle</string>
          </array>
        </var>
      </struct>
    </data>
  </wddxPacket>

LV Based on this example,WDDX appears to be a specific application of XML. There are a couple of XML extensions for Tcl - tdom and tclxml at the very least.

I'm uncertain what one would need to use with either of these to be considered a WDDX parser.


schlenk 2005-10-06 Based on the description of WDDX it seems like a serialization protocol for application data. As Tcl does not really have most of the types of for example Java or C one would have to create a mapping from WDDX to Tcl Data structures, probably something like struct::record or one of the OO packages. With tdom and some XPath expression it should be quite straightforward to do once you decide on a mapping.

NEM is slightly confused about that <array length='3'> bit. Surely the length is easily available by just counting the number of children nodes, which should be trivial with any XML parser. And what if the length specified and the number of child nodes differ? Too much C-coding leaking into the spec?

schlenk 2005-10-06 Removed my incorrect rant about the WDDX XML/UTF-8 handling, thanks to dkf for correcting me.


  package require tdom
  
  set wddxpacket {  <wddxPacket version='1.0'>
      <header comment='Another example' />
      <data>
        <struct>
          <var name='pi'>
            <number>3.1415926</number>
          </var>
          <var name='cities'>
            <array length='3'>
              <string>Austin</string>
              <string>Novato</string>
              <string>Seattle</string>
            </array>
          </var>
        </struct>
      </data>
    </wddxPacket>};
  
  proc getWDDXrootDOM {wddxPacket} {
    set doc [dom parse $wddxPacket];
    set root [$doc documentElement];
    return $root;
  }
  
  proc getWDDXdata {wddxPacket path} {
    set root [getWDDXrootDOM $wddxPacket];
    return [$root selectNodes $path];
  }
  
  set versionPath {string(@version)};
  set packetVersion [getWDDXdata $wddxpacket $versionPath];
  puts "Version is $packetVersion";
  
  set headerCommentPath {string(header/@comment)};
  set headerComment [getWDDXdata $wddxpacket $headerCommentPath];
  puts "Comment is $headerComment";
  
  set citiesCountPath {string(data/struct/var[@name='cities']/array/@length)};
  set citiesCount [getWDDXdata $wddxpacket $citiesCountPath];
  puts "number of cities is $citiesCount";
  
  for {set i 0} {$i < $citiesCount} {incr i} {
    set cityPath "string(data/struct/var\[@name='cities'\]/array/string\[[expr $i + 1]\])";
    set city [getWDDXdata $wddxpacket $cityPath];
    puts "city #$i is $city";
  }

Output:

  Version is 1.0
  Comment is Another example
  number of cities is 3
  city #0 is Austin
  city #1 is Novato
  city #2 is Seattle