AJAX
[ class tree: AJAX ] [ index: AJAX ] [ all elements ]

Source for file XML.php

Documentation is available at XML.php

  1. <?php
  2. // $Id: XML.php 583 2007-03-05 22:13:30Z jeichorn $
  3. /**
  4.  * XML Serializer - does NOT need a js serializer, use responseXML property in XmlHttpRequest
  5.  *
  6.  * @category   HTML
  7.  * @package    AJAX
  8.  * @author     Elizabeth Smith <auroraeosrose@gmail.com>
  9.  * @copyright  2005-2006 Elizabeth Smith
  10.  * @license    http://www.opensource.org/licenses/lgpl-license.php  LGPL
  11.  * @version    Release: 0.5.4
  12.  * @link       http://pear.php.net/package/PackageName
  13.  */
  14. {
  15.  
  16.     /**
  17.      * Serializes a domdocument into an xml string
  18.      *
  19.      * Uses dom or domxml to dump a string from a DomDocument instance
  20.      * remember dom is always the default and this will die horribly without
  21.      * a domdocument instance
  22.      *
  23.      * @access public
  24.      * @param  object $input instanceof DomDocument
  25.      * @return string xml string of DomDocument
  26.      */
  27.     function serialize($input
  28.     {
  29.         if(empty($input))
  30.         {
  31.             return $input;
  32.         }
  33.         // we check for the dom extension
  34.         elseif (extension_loaded('Dom'))
  35.         {
  36.             return $input->saveXml();
  37.         }
  38.         // then will check for domxml
  39.         elseif (extension_loaded('Domxml')) 
  40.     {
  41.             return $input->dump_mem();
  42.         }
  43.     // will throw an error
  44.     else {
  45.         $error = new HTML_AJAX_Serializer_Error();    
  46.         $this->serializerNewType 'Error';
  47.         return $error->serialize(array('errStr'=>"Missing PHP Dom extension direct XML won't work"));
  48.     }
  49.     }
  50.  
  51.     /**
  52.      * Unserializes the xml string sent from the document
  53.      *
  54.      * Uses dom or domxml to pump a string into a DomDocument instance
  55.      * remember dom is always the default and this will die horribly without
  56.      * one or the other, and will throw warnings if you have bad xml
  57.      *
  58.      * @access public
  59.      * @param  string $input   The input to serialize.
  60.      * @return object instanceofDomDocument 
  61.      */
  62.     function unserialize($input
  63.     {
  64.         if(empty($input))
  65.         {
  66.             return $input;
  67.         }
  68.         // we check for the dom extension
  69.         elseif (extension_loaded('Dom'))
  70.         {
  71.             $doc = new DOMDocument();
  72.             $doc->loadXML($input);
  73.             return $doc;
  74.         }
  75.         // then we check for the domxml extensions
  76.         elseif (extension_loaded('Domxml'))
  77.     {
  78.             return domxml_open_mem($input);
  79.     }
  80.     // we give up and just return the xml directly
  81.         else
  82.         {
  83.         return $input;
  84.         }
  85.     }
  86. }
  87. ?>

Documentation generated on Fri, 04 Apr 2008 18:30:28 -0400 by phpDocumentor 1.4.0. PEAR Logo Copyright © PHP Group 2004.