rubysl-rexml 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (179) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/.travis.yml +8 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE +25 -0
  6. data/README.md +29 -0
  7. data/Rakefile +1 -0
  8. data/lib/rexml/attlistdecl.rb +62 -0
  9. data/lib/rexml/attribute.rb +185 -0
  10. data/lib/rexml/cdata.rb +67 -0
  11. data/lib/rexml/child.rb +96 -0
  12. data/lib/rexml/comment.rb +80 -0
  13. data/lib/rexml/doctype.rb +271 -0
  14. data/lib/rexml/document.rb +230 -0
  15. data/lib/rexml/dtd/attlistdecl.rb +10 -0
  16. data/lib/rexml/dtd/dtd.rb +51 -0
  17. data/lib/rexml/dtd/elementdecl.rb +17 -0
  18. data/lib/rexml/dtd/entitydecl.rb +56 -0
  19. data/lib/rexml/dtd/notationdecl.rb +39 -0
  20. data/lib/rexml/element.rb +1227 -0
  21. data/lib/rexml/encoding.rb +71 -0
  22. data/lib/rexml/encodings/CP-1252.rb +103 -0
  23. data/lib/rexml/encodings/EUC-JP.rb +35 -0
  24. data/lib/rexml/encodings/ICONV.rb +22 -0
  25. data/lib/rexml/encodings/ISO-8859-1.rb +7 -0
  26. data/lib/rexml/encodings/ISO-8859-15.rb +72 -0
  27. data/lib/rexml/encodings/SHIFT-JIS.rb +37 -0
  28. data/lib/rexml/encodings/SHIFT_JIS.rb +1 -0
  29. data/lib/rexml/encodings/UNILE.rb +34 -0
  30. data/lib/rexml/encodings/US-ASCII.rb +30 -0
  31. data/lib/rexml/encodings/UTF-16.rb +35 -0
  32. data/lib/rexml/encodings/UTF-8.rb +18 -0
  33. data/lib/rexml/entity.rb +166 -0
  34. data/lib/rexml/formatters/default.rb +109 -0
  35. data/lib/rexml/formatters/pretty.rb +138 -0
  36. data/lib/rexml/formatters/transitive.rb +56 -0
  37. data/lib/rexml/functions.rb +382 -0
  38. data/lib/rexml/instruction.rb +70 -0
  39. data/lib/rexml/light/node.rb +196 -0
  40. data/lib/rexml/namespace.rb +47 -0
  41. data/lib/rexml/node.rb +75 -0
  42. data/lib/rexml/output.rb +24 -0
  43. data/lib/rexml/parent.rb +166 -0
  44. data/lib/rexml/parseexception.rb +51 -0
  45. data/lib/rexml/parsers/baseparser.rb +503 -0
  46. data/lib/rexml/parsers/lightparser.rb +60 -0
  47. data/lib/rexml/parsers/pullparser.rb +196 -0
  48. data/lib/rexml/parsers/sax2parser.rb +238 -0
  49. data/lib/rexml/parsers/streamparser.rb +46 -0
  50. data/lib/rexml/parsers/treeparser.rb +97 -0
  51. data/lib/rexml/parsers/ultralightparser.rb +56 -0
  52. data/lib/rexml/parsers/xpathparser.rb +698 -0
  53. data/lib/rexml/quickpath.rb +266 -0
  54. data/lib/rexml/rexml.rb +32 -0
  55. data/lib/rexml/sax2listener.rb +97 -0
  56. data/lib/rexml/source.rb +251 -0
  57. data/lib/rexml/streamlistener.rb +92 -0
  58. data/lib/rexml/syncenumerator.rb +33 -0
  59. data/lib/rexml/text.rb +344 -0
  60. data/lib/rexml/undefinednamespaceexception.rb +8 -0
  61. data/lib/rexml/validation/relaxng.rb +559 -0
  62. data/lib/rexml/validation/validation.rb +155 -0
  63. data/lib/rexml/validation/validationexception.rb +9 -0
  64. data/lib/rexml/xmldecl.rb +119 -0
  65. data/lib/rexml/xmltokens.rb +18 -0
  66. data/lib/rexml/xpath.rb +66 -0
  67. data/lib/rexml/xpath_parser.rb +792 -0
  68. data/lib/rubysl/rexml.rb +1 -0
  69. data/lib/rubysl/rexml/version.rb +5 -0
  70. data/rubysl-rexml.gemspec +23 -0
  71. data/spec/attribute/clone_spec.rb +10 -0
  72. data/spec/attribute/element_spec.rb +22 -0
  73. data/spec/attribute/equal_value_spec.rb +17 -0
  74. data/spec/attribute/hash_spec.rb +12 -0
  75. data/spec/attribute/initialize_spec.rb +28 -0
  76. data/spec/attribute/inspect_spec.rb +19 -0
  77. data/spec/attribute/namespace_spec.rb +23 -0
  78. data/spec/attribute/node_type_spec.rb +9 -0
  79. data/spec/attribute/prefix_spec.rb +17 -0
  80. data/spec/attribute/remove_spec.rb +19 -0
  81. data/spec/attribute/to_s_spec.rb +13 -0
  82. data/spec/attribute/to_string_spec.rb +14 -0
  83. data/spec/attribute/value_spec.rb +14 -0
  84. data/spec/attribute/write_spec.rb +22 -0
  85. data/spec/attribute/xpath_spec.rb +19 -0
  86. data/spec/attributes/add_spec.rb +6 -0
  87. data/spec/attributes/append_spec.rb +6 -0
  88. data/spec/attributes/delete_all_spec.rb +30 -0
  89. data/spec/attributes/delete_spec.rb +26 -0
  90. data/spec/attributes/each_attribute_spec.rb +24 -0
  91. data/spec/attributes/each_spec.rb +24 -0
  92. data/spec/attributes/element_reference_spec.rb +18 -0
  93. data/spec/attributes/element_set_spec.rb +25 -0
  94. data/spec/attributes/get_attribute_ns_spec.rb +13 -0
  95. data/spec/attributes/get_attribute_spec.rb +28 -0
  96. data/spec/attributes/initialize_spec.rb +18 -0
  97. data/spec/attributes/length_spec.rb +6 -0
  98. data/spec/attributes/namespaces_spec.rb +5 -0
  99. data/spec/attributes/prefixes_spec.rb +23 -0
  100. data/spec/attributes/shared/add.rb +17 -0
  101. data/spec/attributes/shared/length.rb +12 -0
  102. data/spec/attributes/size_spec.rb +6 -0
  103. data/spec/attributes/to_a_spec.rb +20 -0
  104. data/spec/cdata/clone_spec.rb +9 -0
  105. data/spec/cdata/initialize_spec.rb +24 -0
  106. data/spec/cdata/shared/to_s.rb +11 -0
  107. data/spec/cdata/to_s_spec.rb +6 -0
  108. data/spec/cdata/value_spec.rb +6 -0
  109. data/spec/document/add_element_spec.rb +30 -0
  110. data/spec/document/add_spec.rb +60 -0
  111. data/spec/document/clone_spec.rb +19 -0
  112. data/spec/document/doctype_spec.rb +14 -0
  113. data/spec/document/encoding_spec.rb +21 -0
  114. data/spec/document/expanded_name_spec.rb +15 -0
  115. data/spec/document/new_spec.rb +37 -0
  116. data/spec/document/node_type_spec.rb +7 -0
  117. data/spec/document/root_spec.rb +11 -0
  118. data/spec/document/stand_alone_spec.rb +18 -0
  119. data/spec/document/version_spec.rb +13 -0
  120. data/spec/document/write_spec.rb +38 -0
  121. data/spec/document/xml_decl_spec.rb +14 -0
  122. data/spec/element/add_attribute_spec.rb +40 -0
  123. data/spec/element/add_attributes_spec.rb +21 -0
  124. data/spec/element/add_element_spec.rb +38 -0
  125. data/spec/element/add_namespace_spec.rb +23 -0
  126. data/spec/element/add_text_spec.rb +23 -0
  127. data/spec/element/attribute_spec.rb +16 -0
  128. data/spec/element/attributes_spec.rb +18 -0
  129. data/spec/element/cdatas_spec.rb +23 -0
  130. data/spec/element/clone_spec.rb +28 -0
  131. data/spec/element/comments_spec.rb +20 -0
  132. data/spec/element/delete_attribute_spec.rb +38 -0
  133. data/spec/element/delete_element_spec.rb +50 -0
  134. data/spec/element/delete_namespace_spec.rb +24 -0
  135. data/spec/element/document_spec.rb +17 -0
  136. data/spec/element/each_element_with_attribute_spec.rb +34 -0
  137. data/spec/element/each_element_with_text_spec.rb +30 -0
  138. data/spec/element/get_text_spec.rb +17 -0
  139. data/spec/element/has_attributes_spec.rb +16 -0
  140. data/spec/element/has_elements_spec.rb +17 -0
  141. data/spec/element/has_text_spec.rb +15 -0
  142. data/spec/element/inspect_spec.rb +26 -0
  143. data/spec/element/instructions_spec.rb +20 -0
  144. data/spec/element/namespace_spec.rb +26 -0
  145. data/spec/element/namespaces_spec.rb +31 -0
  146. data/spec/element/new_spec.rb +34 -0
  147. data/spec/element/next_element_spec.rb +18 -0
  148. data/spec/element/node_type_spec.rb +7 -0
  149. data/spec/element/prefixes_spec.rb +22 -0
  150. data/spec/element/previous_element_spec.rb +19 -0
  151. data/spec/element/raw_spec.rb +23 -0
  152. data/spec/element/root_spec.rb +27 -0
  153. data/spec/element/text_spec.rb +45 -0
  154. data/spec/element/texts_spec.rb +15 -0
  155. data/spec/element/whitespace_spec.rb +22 -0
  156. data/spec/node/each_recursive_spec.rb +20 -0
  157. data/spec/node/find_first_recursive_spec.rb +24 -0
  158. data/spec/node/index_in_parent_spec.rb +14 -0
  159. data/spec/node/next_sibling_node_spec.rb +20 -0
  160. data/spec/node/parent_spec.rb +20 -0
  161. data/spec/node/previous_sibling_node_spec.rb +20 -0
  162. data/spec/shared/each_element.rb +35 -0
  163. data/spec/shared/elements_to_a.rb +35 -0
  164. data/spec/text/append_spec.rb +9 -0
  165. data/spec/text/clone_spec.rb +9 -0
  166. data/spec/text/comparison_spec.rb +24 -0
  167. data/spec/text/empty_spec.rb +11 -0
  168. data/spec/text/indent_text_spec.rb +23 -0
  169. data/spec/text/inspect_spec.rb +7 -0
  170. data/spec/text/new_spec.rb +48 -0
  171. data/spec/text/node_type_spec.rb +7 -0
  172. data/spec/text/normalize_spec.rb +7 -0
  173. data/spec/text/read_with_substitution_spec.rb +12 -0
  174. data/spec/text/to_s_spec.rb +17 -0
  175. data/spec/text/unnormalize_spec.rb +7 -0
  176. data/spec/text/value_spec.rb +36 -0
  177. data/spec/text/wrap_spec.rb +20 -0
  178. data/spec/text/write_with_substitution_spec.rb +32 -0
  179. metadata +385 -0
@@ -0,0 +1,382 @@
1
+ module REXML
2
+ # If you add a method, keep in mind two things:
3
+ # (1) the first argument will always be a list of nodes from which to
4
+ # filter. In the case of context methods (such as position), the function
5
+ # should return an array with a value for each child in the array.
6
+ # (2) all method calls from XML will have "-" replaced with "_".
7
+ # Therefore, in XML, "local-name()" is identical (and actually becomes)
8
+ # "local_name()"
9
+ module Functions
10
+ @@context = nil
11
+ @@namespace_context = {}
12
+ @@variables = {}
13
+
14
+ def Functions::namespace_context=(x) ; @@namespace_context=x ; end
15
+ def Functions::variables=(x) ; @@variables=x ; end
16
+ def Functions::namespace_context ; @@namespace_context ; end
17
+ def Functions::variables ; @@variables ; end
18
+
19
+ def Functions::context=(value); @@context = value; end
20
+
21
+ def Functions::text( )
22
+ if @@context[:node].node_type == :element
23
+ return @@context[:node].find_all{|n| n.node_type == :text}.collect{|n| n.value}
24
+ elsif @@context[:node].node_type == :text
25
+ return @@context[:node].value
26
+ else
27
+ return false
28
+ end
29
+ end
30
+
31
+ def Functions::last( )
32
+ @@context[:size]
33
+ end
34
+
35
+ def Functions::position( )
36
+ @@context[:index]
37
+ end
38
+
39
+ def Functions::count( node_set )
40
+ node_set.size
41
+ end
42
+
43
+ # Since REXML is non-validating, this method is not implemented as it
44
+ # requires a DTD
45
+ def Functions::id( object )
46
+ end
47
+
48
+ # UNTESTED
49
+ def Functions::local_name( node_set=nil )
50
+ get_namespace( node_set ) do |node|
51
+ return node.local_name
52
+ end
53
+ end
54
+
55
+ def Functions::namespace_uri( node_set=nil )
56
+ get_namespace( node_set ) {|node| node.namespace}
57
+ end
58
+
59
+ def Functions::name( node_set=nil )
60
+ get_namespace( node_set ) do |node|
61
+ node.expanded_name
62
+ end
63
+ end
64
+
65
+ # Helper method.
66
+ def Functions::get_namespace( node_set = nil )
67
+ if node_set == nil
68
+ yield @@context[:node] if defined? @@context[:node].namespace
69
+ else
70
+ if node_set.respond_to? :each
71
+ node_set.each { |node| yield node if defined? node.namespace }
72
+ elsif node_set.respond_to? :namespace
73
+ yield node_set
74
+ end
75
+ end
76
+ end
77
+
78
+ # A node-set is converted to a string by returning the string-value of the
79
+ # node in the node-set that is first in document order. If the node-set is
80
+ # empty, an empty string is returned.
81
+ #
82
+ # A number is converted to a string as follows
83
+ #
84
+ # NaN is converted to the string NaN
85
+ #
86
+ # positive zero is converted to the string 0
87
+ #
88
+ # negative zero is converted to the string 0
89
+ #
90
+ # positive infinity is converted to the string Infinity
91
+ #
92
+ # negative infinity is converted to the string -Infinity
93
+ #
94
+ # if the number is an integer, the number is represented in decimal form
95
+ # as a Number with no decimal point and no leading zeros, preceded by a
96
+ # minus sign (-) if the number is negative
97
+ #
98
+ # otherwise, the number is represented in decimal form as a Number
99
+ # including a decimal point with at least one digit before the decimal
100
+ # point and at least one digit after the decimal point, preceded by a
101
+ # minus sign (-) if the number is negative; there must be no leading zeros
102
+ # before the decimal point apart possibly from the one required digit
103
+ # immediately before the decimal point; beyond the one required digit
104
+ # after the decimal point there must be as many, but only as many, more
105
+ # digits as are needed to uniquely distinguish the number from all other
106
+ # IEEE 754 numeric values.
107
+ #
108
+ # The boolean false value is converted to the string false. The boolean
109
+ # true value is converted to the string true.
110
+ #
111
+ # An object of a type other than the four basic types is converted to a
112
+ # string in a way that is dependent on that type.
113
+ def Functions::string( object=nil )
114
+ #object = @context unless object
115
+ if object.instance_of? Array
116
+ string( object[0] )
117
+ elsif defined? object.node_type
118
+ if object.node_type == :attribute
119
+ object.value
120
+ elsif object.node_type == :element || object.node_type == :document
121
+ string_value(object)
122
+ else
123
+ object.to_s
124
+ end
125
+ elsif object.nil?
126
+ return ""
127
+ else
128
+ object.to_s
129
+ end
130
+ end
131
+
132
+ def Functions::string_value( o )
133
+ rv = ""
134
+ o.children.each { |e|
135
+ if e.node_type == :text
136
+ rv << e.to_s
137
+ elsif e.node_type == :element
138
+ rv << string_value( e )
139
+ end
140
+ }
141
+ rv
142
+ end
143
+
144
+ # UNTESTED
145
+ def Functions::concat( *objects )
146
+ objects.join
147
+ end
148
+
149
+ # Fixed by Mike Stok
150
+ def Functions::starts_with( string, test )
151
+ string(string).index(string(test)) == 0
152
+ end
153
+
154
+ # Fixed by Mike Stok
155
+ def Functions::contains( string, test )
156
+ string(string).include?(string(test))
157
+ end
158
+
159
+ # Kouhei fixed this
160
+ def Functions::substring_before( string, test )
161
+ ruby_string = string(string)
162
+ ruby_index = ruby_string.index(string(test))
163
+ if ruby_index.nil?
164
+ ""
165
+ else
166
+ ruby_string[ 0...ruby_index ]
167
+ end
168
+ end
169
+
170
+ # Kouhei fixed this too
171
+ def Functions::substring_after( string, test )
172
+ ruby_string = string(string)
173
+ test_string = string(test)
174
+ return $1 if ruby_string =~ /#{test}(.*)/
175
+ ""
176
+ end
177
+
178
+ # Take equal portions of Mike Stok and Sean Russell; mix
179
+ # vigorously, and pour into a tall, chilled glass. Serves 10,000.
180
+ def Functions::substring( string, start, length=nil )
181
+ ruby_string = string(string)
182
+ ruby_length = if length.nil?
183
+ ruby_string.length.to_f
184
+ else
185
+ number(length)
186
+ end
187
+ ruby_start = number(start)
188
+
189
+ # Handle the special cases
190
+ return '' if (
191
+ ruby_length.nan? or
192
+ ruby_start.nan? or
193
+ ruby_start.infinite?
194
+ )
195
+
196
+ infinite_length = ruby_length.infinite? == 1
197
+ ruby_length = ruby_string.length if infinite_length
198
+
199
+ # Now, get the bounds. The XPath bounds are 1..length; the ruby bounds
200
+ # are 0..length. Therefore, we have to offset the bounds by one.
201
+ ruby_start = ruby_start.round - 1
202
+ ruby_length = ruby_length.round
203
+
204
+ if ruby_start < 0
205
+ ruby_length += ruby_start unless infinite_length
206
+ ruby_start = 0
207
+ end
208
+ return '' if ruby_length <= 0
209
+ ruby_string[ruby_start,ruby_length]
210
+ end
211
+
212
+ # UNTESTED
213
+ def Functions::string_length( string )
214
+ string(string).length
215
+ end
216
+
217
+ # UNTESTED
218
+ def Functions::normalize_space( string=nil )
219
+ string = string(@@context[:node]) if string.nil?
220
+ if string.kind_of? Array
221
+ string.collect{|x| string.to_s.strip.gsub(/\s+/um, ' ') if string}
222
+ else
223
+ string.to_s.strip.gsub(/\s+/um, ' ')
224
+ end
225
+ end
226
+
227
+ # This is entirely Mike Stok's beast
228
+ def Functions::translate( string, tr1, tr2 )
229
+ from = string(tr1)
230
+ to = string(tr2)
231
+
232
+ # the map is our translation table.
233
+ #
234
+ # if a character occurs more than once in the
235
+ # from string then we ignore the second &
236
+ # subsequent mappings
237
+ #
238
+ # if a character maps to nil then we delete it
239
+ # in the output. This happens if the from
240
+ # string is longer than the to string
241
+ #
242
+ # there's nothing about - or ^ being special in
243
+ # http://www.w3.org/TR/xpath#function-translate
244
+ # so we don't build ranges or negated classes
245
+
246
+ map = Hash.new
247
+ 0.upto(from.length - 1) { |pos|
248
+ from_char = from[pos]
249
+ unless map.has_key? from_char
250
+ map[from_char] =
251
+ if pos < to.length
252
+ to[pos]
253
+ else
254
+ nil
255
+ end
256
+ end
257
+ }
258
+
259
+ string(string).unpack('U*').collect { |c|
260
+ if map.has_key? c then map[c] else c end
261
+ }.compact.pack('U*')
262
+ end
263
+
264
+ # UNTESTED
265
+ def Functions::boolean( object=nil )
266
+ if object.kind_of? String
267
+ if object =~ /\d+/u
268
+ return object.to_f != 0
269
+ else
270
+ return object.size > 0
271
+ end
272
+ elsif object.kind_of? Array
273
+ object = object.find{|x| x and true}
274
+ end
275
+ return object ? true : false
276
+ end
277
+
278
+ # UNTESTED
279
+ def Functions::not( object )
280
+ not boolean( object )
281
+ end
282
+
283
+ # UNTESTED
284
+ def Functions::true( )
285
+ true
286
+ end
287
+
288
+ # UNTESTED
289
+ def Functions::false( )
290
+ false
291
+ end
292
+
293
+ # UNTESTED
294
+ def Functions::lang( language )
295
+ lang = false
296
+ node = @@context[:node]
297
+ attr = nil
298
+ until node.nil?
299
+ if node.node_type == :element
300
+ attr = node.attributes["xml:lang"]
301
+ unless attr.nil?
302
+ lang = compare_language(string(language), attr)
303
+ break
304
+ else
305
+ end
306
+ end
307
+ node = node.parent
308
+ end
309
+ lang
310
+ end
311
+
312
+ def Functions::compare_language lang1, lang2
313
+ lang2.downcase.index(lang1.downcase) == 0
314
+ end
315
+
316
+ # a string that consists of optional whitespace followed by an optional
317
+ # minus sign followed by a Number followed by whitespace is converted to
318
+ # the IEEE 754 number that is nearest (according to the IEEE 754
319
+ # round-to-nearest rule) to the mathematical value represented by the
320
+ # string; any other string is converted to NaN
321
+ #
322
+ # boolean true is converted to 1; boolean false is converted to 0
323
+ #
324
+ # a node-set is first converted to a string as if by a call to the string
325
+ # function and then converted in the same way as a string argument
326
+ #
327
+ # an object of a type other than the four basic types is converted to a
328
+ # number in a way that is dependent on that type
329
+ def Functions::number( object=nil )
330
+ object = @@context[:node] unless object
331
+ case object
332
+ when true
333
+ Float(1)
334
+ when false
335
+ Float(0)
336
+ when Array
337
+ number(string( object ))
338
+ when Numeric
339
+ object.to_f
340
+ else
341
+ str = string( object )
342
+ # If XPath ever gets scientific notation...
343
+ #if str =~ /^\s*-?(\d*\.?\d+|\d+\.)([Ee]\d*)?\s*$/
344
+ if str =~ /^\s*-?(\d*\.?\d+|\d+\.)\s*$/
345
+ str.to_f
346
+ else
347
+ (0.0 / 0.0)
348
+ end
349
+ end
350
+ end
351
+
352
+ def Functions::sum( nodes )
353
+ nodes = [nodes] unless nodes.kind_of? Array
354
+ nodes.inject(0) { |r,n| r += number(string(n)) }
355
+ end
356
+
357
+ def Functions::floor( number )
358
+ number(number).floor
359
+ end
360
+
361
+ def Functions::ceiling( number )
362
+ number(number).ceil
363
+ end
364
+
365
+ def Functions::round( number )
366
+ begin
367
+ number(number).round
368
+ rescue FloatDomainError
369
+ number(number)
370
+ end
371
+ end
372
+
373
+ def Functions::processing_instruction( node )
374
+ node.node_type == :processing_instruction
375
+ end
376
+
377
+ def Functions::method_missing( id )
378
+ puts "METHOD MISSING #{id.id2name}"
379
+ XPath.match( @@context[:node], id.id2name )
380
+ end
381
+ end
382
+ end
@@ -0,0 +1,70 @@
1
+ require "rexml/child"
2
+ require "rexml/source"
3
+
4
+ module REXML
5
+ # Represents an XML Instruction; IE, <? ... ?>
6
+ # TODO: Add parent arg (3rd arg) to constructor
7
+ class Instruction < Child
8
+ START = '<\?'
9
+ STOP = '\?>'
10
+
11
+ # target is the "name" of the Instruction; IE, the "tag" in <?tag ...?>
12
+ # content is everything else.
13
+ attr_accessor :target, :content
14
+
15
+ # Constructs a new Instruction
16
+ # @param target can be one of a number of things. If String, then
17
+ # the target of this instruction is set to this. If an Instruction,
18
+ # then the Instruction is shallowly cloned (target and content are
19
+ # copied). If a Source, then the source is scanned and parsed for
20
+ # an Instruction declaration.
21
+ # @param content Must be either a String, or a Parent. Can only
22
+ # be a Parent if the target argument is a Source. Otherwise, this
23
+ # String is set as the content of this instruction.
24
+ def initialize(target, content=nil)
25
+ if target.kind_of? String
26
+ super()
27
+ @target = target
28
+ @content = content
29
+ elsif target.kind_of? Instruction
30
+ super(content)
31
+ @target = target.target
32
+ @content = target.content
33
+ end
34
+ @content.strip! if @content
35
+ end
36
+
37
+ def clone
38
+ Instruction.new self
39
+ end
40
+
41
+ # == DEPRECATED
42
+ # See the rexml/formatters package
43
+ #
44
+ def write writer, indent=-1, transitive=false, ie_hack=false
45
+ Kernel.warn( "#{self.class.name}.write is deprecated" )
46
+ indent(writer, indent)
47
+ writer << START.sub(/\\/u, '')
48
+ writer << @target
49
+ writer << ' '
50
+ writer << @content
51
+ writer << STOP.sub(/\\/u, '')
52
+ end
53
+
54
+ # @return true if other is an Instruction, and the content and target
55
+ # of the other matches the target and content of this object.
56
+ def ==( other )
57
+ other.kind_of? Instruction and
58
+ other.target == @target and
59
+ other.content == @content
60
+ end
61
+
62
+ def node_type
63
+ :processing_instruction
64
+ end
65
+
66
+ def inspect
67
+ "<?p-i #{target} ...?>"
68
+ end
69
+ end
70
+ end