Source for file Wddx.php
Documentation is available at Wddx.php
/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2004 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.02 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/2_02.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Alan Knowles <alan@akbkhome.com> |
// +----------------------------------------------------------------------+
* XML_Wddx : WDDX serializer and deserializer (works with or without the wddx extension)
* serialization is done by $string = XML_Wddx::serialize($data);
* deserialization is done by $data = XML_Wddx::deserialize($string);
* @version $Id: Wddx.php,v 1.6 2004/08/13 01:40:37 alan_k Exp $
require_once 'XML/Parser.php';
class XML_Wddx extends XML_Parser {
* echo XML_Wddx::serialize($array);
* @param mixed value to serialize
* @return string Serialize data.
function serialize ($value)
return "<wddxPacket version='1.0'><header/><data>\n".
$x->indent (1 ) . trim($x->_serializeValue ($value)) . "\n".
$x->indent (-1 ) . "</data></wddxPacket>\n";
* de-serialize a value (uses wddx_deserialize if it is built in..)
* echo XML_Wddx::deserialize($some_wddx_data);
* @param mixed value to serialize
* @return mixed deserialized data..
function deserialize ($data)
return $t->result ['data'];
* The core method.. that serializes data.
* @param mixed value to serialize
* @return string serialized value.
* @see see also methods.....
function _serializeValue ($value)
return " <number>$value</number>";
"\n". $this->indent (0 ). '<string><![CDATA['. $value. "]]></string>\n" :
" <string>$value</string>";
return " <number>$value</number>";
return sprintf("<boolean value='%s'/>",$value ? 'true': 'false');
$ret = "\n". $this->indent (). "<struct>\n".
$this->indent (1 ). "<var name='php_class_name'><string>". get_class($value). "</string></var>\n";
$ret .= $this->indent (0 ). sprintf("<var name='%s'>",$k);
$ret .= $this->_serializeValue ($v);
$ret .= ($ret{strlen($ret)-1 } == "\n") ? $this->indent () : '';
return $ret . $this->indent () . "</struct>\n";
$ret = "\n". $this->indent ();
$ret .= $is_struct ? "<struct>\n" : sprintf("<array length='%d'>",count($value)). "\n";
foreach($value as $k=> $v) {
$ret .= $this->indent (0 );
$ret .= $is_struct ? sprintf("<var name='%s'>",$k) : '<var>';
$ret .= $this->_serializeValue ($v) ;
$ret .= ($ret{strlen($ret)-1 } == "\n") ? $this->indent () : '';
$ret .= $this->indent (-1 );
$ret .= $is_struct ? '</struct>' : '</array>';
case 'resource': // BIG KLUDGE!!!!
echo "not handled " . gettype($value);
* @param int change (indent increment or decrement)
if ($add < 0 ) { // should not happen!!
* @see XML_Parser:startHandler
function startHandler ($xp, $element, $attribs)
// echo "S:";print_r(func_get_args());
if (isset ($attribs['CODE'])) {
$ent['name'] = @$attribs['NAME'];
break; // not handled yet...
//echo "STACK:";print_r($this->stack);
//echo "S:";print_r(func_get_args());
* @see XML_Parser:startHandler
function endHandler ($xp, $element)
//echo "E:";print_r(func_get_args());
if (!count($this->_stack)) {
$parent = $this->_stackTop ();
// if this is a struct + php_class_name is set...
if (($ent['type'] == 'struct') && isset ($ent['data']['php_class_name'])) {
$class = $ent['data']['php_class_name'];
unset ($ent['data']['php_class_name']);
foreach($ent['data'] as $k=> $v) {
if ($parent['type'] == 'var') {
$parent['data'] = $ent['data'];
if ($ent['type'] == 'var') {
if ($parent['type'] == 'struct') {
$parent['data'][$ent['name']] = $ent['data'];
$parent['data'][] = $ent['data'];
if ($parent['type'] == 'array') {
$parent['data'][] = $ent['data'];
$parent['data'] = $ent['data'];
$this->_stackTop ($parent);
// echo "STACK:";print_r($this->stack);
//echo "E:";print_r(func_get_args());
* @see XML_Parser:cdataHandler
function cdataHandler ($xp, $cdata)
//$ent = array('type'=>false);
if (!count($this->_stack)) {
$ent = $this->_stackTop ();
$ent['data'] = $cdata == 'true' ? true : false;
case 'datetime': // not really handled...
//echo "C:";print_r(func_get_args());
//echo "STACK: "; print_r($this->stack);
//echo "C:";print_r(func_get_args());
* @see XML_Parser::defaultHandler
function defaultHandler ($xp, $cdata)
//echo "D:";print_r(func_get_args());
* get/set top of stack values..
* @param array optional (array if it is to be changed..)
* @return array|none (empty parameter = get)
function _stackTop ($ent = null )
$this->_stack[count($this->_stack)-1 ] = $ent;
if (count($this->_stack)) {
return $this->_stack[count($this->_stack)-1 ];
'b' => "TESTING \n 123\n",
'd' => array('x','y','z')
print_r(XML_Wddx::serialize($ar));
echo wddx_serialize_value($ar);
Documentation generated on Mon, 11 Mar 2019 13:54:39 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|