/tools/Ruby/lib/ruby/1.8/rexml/cdata.rb

http://github.com/agross/netopenspace · Ruby · 67 lines · 27 code · 6 blank · 34 comment · 0 complexity · f8a8d577ba28b9ed094ae7f9265a031c MD5 · raw file

  1. require "rexml/text"
  2. module REXML
  3. class CData < Text
  4. START = '<![CDATA['
  5. STOP = ']]>'
  6. ILLEGAL = /(\]\]>)/
  7. # Constructor. CData is data between <![CDATA[ ... ]]>
  8. #
  9. # _Examples_
  10. # CData.new( source )
  11. # CData.new( "Here is some CDATA" )
  12. # CData.new( "Some unprocessed data", respect_whitespace_TF, parent_element )
  13. def initialize( first, whitespace=true, parent=nil )
  14. super( first, whitespace, parent, true, true, ILLEGAL )
  15. end
  16. # Make a copy of this object
  17. #
  18. # _Examples_
  19. # c = CData.new( "Some text" )
  20. # d = c.clone
  21. # d.to_s # -> "Some text"
  22. def clone
  23. CData.new self
  24. end
  25. # Returns the content of this CData object
  26. #
  27. # _Examples_
  28. # c = CData.new( "Some text" )
  29. # c.to_s # -> "Some text"
  30. def to_s
  31. @string
  32. end
  33. def value
  34. @string
  35. end
  36. # == DEPRECATED
  37. # See the rexml/formatters package
  38. #
  39. # Generates XML output of this object
  40. #
  41. # output::
  42. # Where to write the string. Defaults to $stdout
  43. # indent::
  44. # The amount to indent this node by
  45. # transitive::
  46. # Ignored
  47. # ie_hack::
  48. # Ignored
  49. #
  50. # _Examples_
  51. # c = CData.new( " Some text " )
  52. # c.write( $stdout ) #-> <![CDATA[ Some text ]]>
  53. def write( output=$stdout, indent=-1, transitive=false, ie_hack=false )
  54. Kernel.warn( "#{self.class.name}.write is deprecated" )
  55. indent( output, indent )
  56. output << START
  57. output << @string
  58. output << STOP
  59. end
  60. end
  61. end