home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / php / PEAR / HTML / AJAX / Serializer / XML.php < prev   
Encoding:
PHP Script  |  2008-07-02  |  2.5 KB  |  89 lines

  1. <?php
  2. // $Id: XML.php 620 2008-05-07 22:33:32Z 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.6
  12.  * @link       http://pear.php.net/package/PackageName
  13.  */
  14. class HTML_AJAX_Serializer_XML
  15. {
  16.  
  17.     /**
  18.      * Serializes a domdocument into an xml string
  19.      *
  20.      * Uses dom or domxml to dump a string from a DomDocument instance
  21.      * remember dom is always the default and this will die horribly without
  22.      * a domdocument instance
  23.      *
  24.      * @access public
  25.      * @param  object $input instanceof DomDocument
  26.      * @return string xml string of DomDocument
  27.      */
  28.     function serialize($input) 
  29.     {
  30.         if(empty($input))
  31.         {
  32.             return $input;
  33.         }
  34.         // we check for the dom extension
  35.         elseif (extension_loaded('Dom'))
  36.         {
  37.             return $input->saveXml();
  38.         }
  39.         // then will check for domxml
  40.         elseif (extension_loaded('Domxml')) 
  41.     {
  42.             return $input->dump_mem();
  43.         }
  44.     // will throw an error
  45.     else {
  46.         $error = new HTML_AJAX_Serializer_Error();    
  47.         $this->serializerNewType = 'Error';
  48.         return $error->serialize(array('errStr'=>"Missing PHP Dom extension direct XML won't work"));
  49.     }
  50.     }
  51.  
  52.     /**
  53.      * Unserializes the xml string sent from the document
  54.      *
  55.      * Uses dom or domxml to pump a string into a DomDocument instance
  56.      * remember dom is always the default and this will die horribly without
  57.      * one or the other, and will throw warnings if you have bad xml
  58.      *
  59.      * @access public
  60.      * @param  string $input   The input to serialize.
  61.      * @return object instanceofDomDocument
  62.      */
  63.     function unserialize($input) 
  64.     {
  65.         if(empty($input))
  66.         {
  67.             return $input;
  68.         }
  69.         // we check for the dom extension
  70.         elseif (extension_loaded('Dom'))
  71.         {
  72.             $doc = new DOMDocument();
  73.             $doc->loadXML($input);
  74.             return $doc;
  75.         }
  76.         // then we check for the domxml extensions
  77.         elseif (extension_loaded('Domxml'))
  78.     {
  79.             return domxml_open_mem($input);
  80.     }
  81.     // we give up and just return the xml directly
  82.         else
  83.         {
  84.         return $input;
  85.         }
  86.     }
  87. }
  88. ?>
  89.