1 | require "rexml/text"
|
---|
2 |
|
---|
3 | module REXML
|
---|
4 | class CData < Text
|
---|
5 | START = '<![CDATA['
|
---|
6 | STOP = ']]>'
|
---|
7 | ILLEGAL = /(\]\]>)/
|
---|
8 |
|
---|
9 | # Constructor. CData is data between <![CDATA[ ... ]]>
|
---|
10 | #
|
---|
11 | # _Examples_
|
---|
12 | # CData.new( source )
|
---|
13 | # CData.new( "Here is some CDATA" )
|
---|
14 | # CData.new( "Some unprocessed data", respect_whitespace_TF, parent_element )
|
---|
15 | def initialize( first, whitespace=true, parent=nil )
|
---|
16 | super( first, whitespace, parent, true, true, ILLEGAL )
|
---|
17 | end
|
---|
18 |
|
---|
19 | # Make a copy of this object
|
---|
20 | #
|
---|
21 | # _Examples_
|
---|
22 | # c = CData.new( "Some text" )
|
---|
23 | # d = c.clone
|
---|
24 | # d.to_s # -> "Some text"
|
---|
25 | def clone
|
---|
26 | CData.new self
|
---|
27 | end
|
---|
28 |
|
---|
29 | # Returns the content of this CData object
|
---|
30 | #
|
---|
31 | # _Examples_
|
---|
32 | # c = CData.new( "Some text" )
|
---|
33 | # c.to_s # -> "Some text"
|
---|
34 | def to_s
|
---|
35 | @string
|
---|
36 | end
|
---|
37 |
|
---|
38 | def value
|
---|
39 | @string
|
---|
40 | end
|
---|
41 |
|
---|
42 | # Generates XML output of this object
|
---|
43 | #
|
---|
44 | # output::
|
---|
45 | # Where to write the string. Defaults to $stdout
|
---|
46 | # indent::
|
---|
47 | # An integer. If -1, no indenting will be used; otherwise, the
|
---|
48 | # indentation will be this number of spaces, and children will be
|
---|
49 | # indented an additional amount. Defaults to -1.
|
---|
50 | # transitive::
|
---|
51 | # If transitive is true and indent is >= 0, then the output will be
|
---|
52 | # pretty-printed in such a way that the added whitespace does not affect
|
---|
53 | # the absolute *value* of the document -- that is, it leaves the value
|
---|
54 | # and number of Text nodes in the document unchanged.
|
---|
55 | # ie_hack::
|
---|
56 | # Internet Explorer is the worst piece of crap to have ever been
|
---|
57 | # written, with the possible exception of Windows itself. Since IE is
|
---|
58 | # unable to parse proper XML, we have to provide a hack to generate XML
|
---|
59 | # that IE's limited abilities can handle. This hack inserts a space
|
---|
60 | # before the /> on empty tags.
|
---|
61 | #
|
---|
62 | # _Examples_
|
---|
63 | # c = CData.new( " Some text " )
|
---|
64 | # c.write( $stdout ) #-> <![CDATA[ Some text ]]>
|
---|
65 | def write( output=$stdout, indent=-1, transitive=false, ie_hack=false )
|
---|
66 | #indent( output, indent ) unless transitive
|
---|
67 | output << START
|
---|
68 | output << @string
|
---|
69 | output << STOP
|
---|
70 | end
|
---|
71 | end
|
---|
72 | end
|
---|