no = $no; $this->name = $name; $this->role = $role; } function __toString() { return sprintf('[%d,%s,%s]', $this->no, $this->name, $this->role); } } class Employees { public $list; public function __construct() { $this->list = array(); } function __toString() { return '{' . implode(',', $this->list) . '}'; } } // create employees $employees = new Employees(); $employees->list[] = new Employee(1, 'Alan A', 'Manager'); $employees->list[] = new Employee(2, 'Brian B', 'Engineer'); $employees->list[] = new Employee(3, 'Chris C', 'Sales rep'); $employees->list[] = new Employee(4, 'Dave D', 'Intern'); // write out $serializer = new XML_Serializer(array('indent' => ' ', 'typeHints' => true)); $serializer->serialize($employees); $xml = $serializer->getSerializedData(); echo $xml; // read in $unserializer = new XML_Unserializer(array()); $unserializer->unserialize($xml); $o = $unserializer->getUnserializedData(); echo $o; ?>