XMLWriter.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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_Abstract
  24. */
  25. require_once 'Zend/XmlRpc/Generator/Abstract.php';
  26. /**
  27. * XML generator adapter based on XMLWriter
  28. */
  29. class Zend_XmlRpc_Generator_XMLWriter extends Zend_XmlRpc_Generator_Abstract
  30. {
  31. /**
  32. * XMLWriter instance
  33. *
  34. * @var XMLWriter
  35. */
  36. protected $_xmlWriter;
  37. /**
  38. * Initialized XMLWriter instance
  39. *
  40. * @return void
  41. */
  42. protected function _init()
  43. {
  44. $this->_xmlWriter = new XMLWriter();
  45. $this->_xmlWriter->openMemory();
  46. $this->_xmlWriter->startDocument('1.0', $this->_encoding);
  47. }
  48. /**
  49. * Start XML element
  50. *
  51. * Method opens a new XML element with an element name and an optional value
  52. *
  53. * @param string $name
  54. * @param string $value
  55. * @return Zend_XmlRpc_Generator_XMLWriter Fluent interface
  56. */
  57. public function startElement($name, $value = null)
  58. {
  59. $this->_xmlWriter->startElement($name);
  60. if ($value !== null) {
  61. $this->_xmlWriter->text($value);
  62. }
  63. return $this;
  64. }
  65. public function endElement($name)
  66. {
  67. $this->_xmlWriter->endElement();
  68. return $this;
  69. }
  70. public function saveXml()
  71. {
  72. return $this->_xmlWriter->flush(false);
  73. }
  74. }