XmlWriter.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. * XML generator adapter based on XMLWriter
  28. */
  29. class Zend_XmlRpc_Generator_XmlWriter extends Zend_XmlRpc_Generator_GeneratorAbstract
  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. /**
  66. * End of an XML element
  67. *
  68. * Called to mark the end of an XML element
  69. *
  70. * @param string $name
  71. * @return Zend_XmlRpc_Generator_XmlWriter Fluent interface
  72. */
  73. public function endElement($name)
  74. {
  75. $this->_xmlWriter->endElement();
  76. return $this;
  77. }
  78. public function saveXml()
  79. {
  80. return $this->_xmlWriter->flush(false);
  81. }
  82. }