web/lib/Zend/XmlRpc/Generator/DomDocument.php
changeset 64 162c1de6545a
parent 19 1c2f13fd785c
child 68 ecaf28ffe26e
equal deleted inserted replaced
63:5b37998e522e 64:162c1de6545a
       
     1 <?php
       
     2 /**
       
     3  * Zend Framework
       
     4  *
       
     5  * LICENSE
       
     6  *
       
     7  * This source file is subject to the new BSD license that is bundled
       
     8  * with this package in the file LICENSE.txt.
       
     9  * It is also available through the world-wide-web at this URL:
       
    10  * http://framework.zend.com/license/new-bsd
       
    11  * If you did not receive a copy of the license and are unable to
       
    12  * obtain it through the world-wide-web, please send an email
       
    13  * to license@zend.com so we can send you a copy immediately.
       
    14  *
       
    15  * @category   Zend
       
    16  * @package    Zend_XmlRpc
       
    17  * @subpackage Generator
       
    18  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    20  * @version    $Id: DomDocument.php 20785 2010-01-31 09:43:03Z mikaelkael $
       
    21  */
       
    22 
       
    23 /**
       
    24  * @var Zend_XmlRpc_Generator_GeneratorAbstract
       
    25  */
       
    26 require_once 'Zend/XmlRpc/Generator/GeneratorAbstract.php';
       
    27 
       
    28 /**
       
    29  * DOMDocument based implementation of a XML/RPC generator
       
    30  */
       
    31 class Zend_XmlRpc_Generator_DomDocument extends Zend_XmlRpc_Generator_GeneratorAbstract
       
    32 {
       
    33     /**
       
    34      * @var DOMDocument
       
    35      */
       
    36     protected $_dom;
       
    37 
       
    38     /**
       
    39      * @var DOMNode
       
    40      */
       
    41     protected $_currentElement;
       
    42 
       
    43     /**
       
    44      * Start XML element
       
    45      *
       
    46      * @param string $name
       
    47      * @return void
       
    48      */
       
    49     protected function _openElement($name)
       
    50     {
       
    51         $newElement = $this->_dom->createElement($name);
       
    52 
       
    53         $this->_currentElement = $this->_currentElement->appendChild($newElement);
       
    54     }
       
    55 
       
    56     /**
       
    57      * Write XML text data into the currently opened XML element
       
    58      *
       
    59      * @param string $text
       
    60      */
       
    61     protected function _writeTextData($text)
       
    62     {
       
    63         $this->_currentElement->appendChild($this->_dom->createTextNode($text));
       
    64     }
       
    65 
       
    66     /**
       
    67      * Close an previously opened XML element
       
    68      *
       
    69      * Resets $_currentElement to the next parent node in the hierarchy
       
    70      *
       
    71      * @param string $name
       
    72      * @return void
       
    73      */
       
    74     protected function _closeElement($name)
       
    75     {
       
    76         if (isset($this->_currentElement->parentNode)) {
       
    77             $this->_currentElement = $this->_currentElement->parentNode;
       
    78         }
       
    79     }
       
    80 
       
    81     /**
       
    82      * Save XML as a string
       
    83      *
       
    84      * @return string
       
    85      */
       
    86     public function saveXml()
       
    87     {
       
    88         return $this->_dom->saveXml();
       
    89     }
       
    90 
       
    91     /**
       
    92      * Initializes internal objects
       
    93      *
       
    94      * @return void
       
    95      */
       
    96     protected function _init()
       
    97     {
       
    98         $this->_dom = new DOMDocument('1.0', $this->_encoding);
       
    99         $this->_currentElement = $this->_dom;
       
   100     }
       
   101 }