DomDocument.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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-2009 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id: Client.php 17752 2009-08-22 15:49:54Z lars $
  21. */
  22. /**
  23. * @var Zend_XmlRpc_Generator_GeneratorAbstract
  24. */
  25. require_once 'Zend/XmlRpc/Generator/GeneratorAbstract.php';
  26. /**
  27. * DOMDocument based implementation of a XML/RPC generator
  28. */
  29. class Zend_XmlRpc_Generator_DomDocument extends Zend_XmlRpc_Generator_GeneratorAbstract
  30. {
  31. /**
  32. * @var DOMDocument
  33. */
  34. protected $_dom;
  35. /**
  36. * @var DOMNode
  37. */
  38. protected $_currentElement;
  39. /**
  40. * Start XML element
  41. *
  42. * Creates a new XML element and appends it to the document tree
  43. *
  44. * @param string $name
  45. * @param string $value
  46. * @return Zend_XmlRpc_Generator_DomDocument Fluent interface
  47. */
  48. public function startElement($name, $value = null)
  49. {
  50. $newElement = $this->_dom->createElement($name);
  51. $this->_currentElement = $this->_currentElement->appendChild($newElement);
  52. if ($value !== null) {
  53. $this->_currentElement->appendChild($this->_dom->createTextNode($value));
  54. }
  55. return $this;
  56. }
  57. /**
  58. * End of an XML element
  59. *
  60. * Resets $_currentElement to the next parent node in the hierarchy
  61. *
  62. * @param string $name
  63. * @return Zend_XmlRpc_Generator_DomDocument Fluent interface
  64. */
  65. public function endElement($name)
  66. {
  67. if (isset($this->_currentElement->parentNode)) {
  68. $this->_currentElement = $this->_currentElement->parentNode;
  69. }
  70. return $this;
  71. }
  72. /**
  73. * Save XML as a string
  74. *
  75. * @return string
  76. */
  77. public function saveXml()
  78. {
  79. return $this->_dom->saveXml();
  80. }
  81. /**
  82. * Initializes internal objects
  83. *
  84. * @return void
  85. */
  86. protected function _init()
  87. {
  88. $this->_dom = new DOMDocument('1.0', $this->_encoding);
  89. $this->_currentElement = $this->_dom;
  90. }
  91. }