XML.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  3. /**
  4. * XML renderer.
  5. *
  6. * Based on the HTML renderer by Andrey Demenev.
  7. *
  8. * LICENSE: This source file is subject to version 3.0 of the PHP license
  9. * that is available through the world-wide-web at the following URI:
  10. * http://www.php.net/license/3_0.txt. If you did not receive a copy of
  11. * the PHP License and are unable to obtain it through the web, please
  12. * send a note to license@php.net so we can mail you a copy immediately.
  13. *
  14. * @category Text
  15. * @package Text_Highlighter
  16. * @author Stoyan Stefanov <ssttoo@gmail.com>
  17. * @copyright 2006 Stoyan Stefanov
  18. * @license http://www.php.net/license/3_0.txt PHP License
  19. * @version CVS: $Id: XML.php,v 1.1 2007/06/03 02:37:09 ssttoo Exp $
  20. * @link http://pear.php.net/package/Text_Highlighter
  21. */
  22. /**
  23. * @ignore
  24. */
  25. require_once dirname(__FILE__).'/../Renderer.php';
  26. require_once dirname(__FILE__).'/../Renderer/Array.php';
  27. /**
  28. * XML renderer, based on Andrey Demenev's HTML renderer.
  29. *
  30. * @author Stoyan Stefanov <ssttoo@gmail.com>
  31. * @category Text
  32. * @package Text_Highlighter
  33. * @copyright 2006 Stoyan Stefanov
  34. * @license http://www.php.net/license/3_0.txt PHP License
  35. * @version Release: 0.5.0
  36. * @link http://pear.php.net/package/Text_Highlighter
  37. */
  38. class Text_Highlighter_Renderer_XML extends Text_Highlighter_Renderer_Array
  39. {
  40. /**
  41. * Options for XML_Serializer
  42. *
  43. * @access private
  44. * @var array
  45. */
  46. var $_serializer_options = array();
  47. /**
  48. * Resets renderer state
  49. *
  50. * Descendents of Text_Highlighter call this method from the constructor,
  51. * passing $options they get as parameter.
  52. *
  53. * @access protected
  54. */
  55. function reset()
  56. {
  57. parent::reset();
  58. if (isset($this->_options['xml_serializer'])) {
  59. $this->_serializer_options = $this->_options['xml_serializer'];
  60. }
  61. }
  62. /**
  63. * Signals that no more tokens are available
  64. *
  65. * @abstract
  66. * @access public
  67. */
  68. function finalize()
  69. {
  70. // call parent's finalize(), then serialize array into XML
  71. parent::finalize();
  72. $output = parent::getOutput();
  73. $serializer = new XML_Serializer($this->_serializer_options);
  74. $result = $serializer->serialize($output);
  75. if ($result === true) {
  76. $this->_output = $serializer->getSerializedData();
  77. }
  78. }
  79. }
  80. /*
  81. * Local variables:
  82. * tab-width: 4
  83. * c-basic-offset: 4
  84. * c-hanging-comment-ender-p: nil
  85. * End:
  86. */
  87. ?>