rexml 3.2.3 → 3.3.8

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rexml might be problematic. Click here for more details.

Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/NEWS.md +502 -0
  3. data/README.md +11 -14
  4. data/doc/rexml/context.rdoc +143 -0
  5. data/doc/rexml/tasks/rdoc/child.rdoc +87 -0
  6. data/doc/rexml/tasks/rdoc/document.rdoc +276 -0
  7. data/doc/rexml/tasks/rdoc/element.rdoc +602 -0
  8. data/doc/rexml/tasks/rdoc/node.rdoc +97 -0
  9. data/doc/rexml/tasks/rdoc/parent.rdoc +267 -0
  10. data/doc/rexml/tasks/tocs/child_toc.rdoc +12 -0
  11. data/doc/rexml/tasks/tocs/document_toc.rdoc +30 -0
  12. data/doc/rexml/tasks/tocs/element_toc.rdoc +55 -0
  13. data/doc/rexml/tasks/tocs/master_toc.rdoc +135 -0
  14. data/doc/rexml/tasks/tocs/node_toc.rdoc +16 -0
  15. data/doc/rexml/tasks/tocs/parent_toc.rdoc +25 -0
  16. data/doc/rexml/tutorial.rdoc +1358 -0
  17. data/lib/rexml/attribute.rb +17 -11
  18. data/lib/rexml/doctype.rb +55 -31
  19. data/lib/rexml/document.rb +199 -35
  20. data/lib/rexml/element.rb +1802 -487
  21. data/lib/rexml/entity.rb +10 -39
  22. data/lib/rexml/formatters/pretty.rb +3 -3
  23. data/lib/rexml/functions.rb +1 -2
  24. data/lib/rexml/light/node.rb +0 -8
  25. data/lib/rexml/namespace.rb +8 -4
  26. data/lib/rexml/node.rb +8 -4
  27. data/lib/rexml/parseexception.rb +1 -0
  28. data/lib/rexml/parsers/baseparser.rb +513 -250
  29. data/lib/rexml/parsers/pullparser.rb +12 -0
  30. data/lib/rexml/parsers/sax2parser.rb +16 -19
  31. data/lib/rexml/parsers/streamparser.rb +16 -10
  32. data/lib/rexml/parsers/treeparser.rb +9 -21
  33. data/lib/rexml/parsers/xpathparser.rb +161 -97
  34. data/lib/rexml/rexml.rb +29 -22
  35. data/lib/rexml/source.rb +128 -98
  36. data/lib/rexml/text.rb +46 -22
  37. data/lib/rexml/xpath_parser.rb +43 -33
  38. data/lib/rexml.rb +3 -0
  39. metadata +42 -46
  40. data/.gitignore +0 -9
  41. data/.travis.yml +0 -24
  42. data/Gemfile +0 -6
  43. data/Rakefile +0 -8
  44. data/rexml.gemspec +0 -84
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 50a1edf481c0166f41419e4ec6a7281db35e46a480c321f5f536afedc243c582
4
- data.tar.gz: 2fe98cd4b1f91b895362f49d1026f6e712ce218edfda7e51e108477fc274a65a
3
+ metadata.gz: 84b42219a4278ab15e7ee7627951d0b94dddc707cbf9563799b3266d02ed32db
4
+ data.tar.gz: 4895e6f04d100a2affc8d5c6af4c6dfec5ec4d0d863f8d22de1c66da1d253c61
5
5
  SHA512:
6
- metadata.gz: f0babb3c1a90a87879c923edec9dc99704fe2d27a7b1c36aeefd0dc5dccc7f5aefa4f7223149ca9bc079cd4fa30128ee289d16f398cdcc4e75378212439b73d4
7
- data.tar.gz: 920401977f208f24670de80b771a50915347471bba9c6a20a5672318d177c2f830c57aac1257dac5c7d93c3c4b505d307bae9955824e5867af42f94287c7dc4e
6
+ metadata.gz: 7729c31da310e2fb7c96cc3a5bd5b981fefdcdae6fe545bf2d113d91af5862fbb51789e9289b91e4247963169900b0cdccc373ffeea6ca3f935b2e32bab1e2e4
7
+ data.tar.gz: 542f689b7cd27b5c71aeb6845e5af2ac28186e31a98af8c45e984ce6ca563192b2a74e50b6acd95f1fde49ed6289bf9024bfd6612608455038a22e66c6b3a75b
data/NEWS.md CHANGED
@@ -1,5 +1,507 @@
1
1
  # News
2
2
 
3
+ ## 3.3.8 - 2024-09-29 {#version-3-3-8}
4
+
5
+ ### Improvements
6
+
7
+ * SAX2: Improve parse performance.
8
+ * GH-207
9
+ * Patch by NAITOH Jun.
10
+
11
+ ### Fixes
12
+
13
+ * Fixed a bug that unexpected attribute namespace conflict error for
14
+ the predefined "xml" namespace is reported.
15
+ * GH-208
16
+ * Patch by KITAITI Makoto
17
+
18
+ ### Thanks
19
+
20
+ * NAITOH Jun
21
+
22
+ * KITAITI Makoto
23
+
24
+ ## 3.3.7 - 2024-09-04 {#version-3-3-7}
25
+
26
+ ### Improvements
27
+
28
+ * Added local entity expansion limit methods
29
+ * GH-192
30
+ * GH-202
31
+ * Reported by takuya kodama.
32
+ * Patch by NAITOH Jun.
33
+
34
+ * Removed explicit strscan dependency
35
+ * GH-204
36
+ * Patch by Bo Anderson.
37
+
38
+ ### Thanks
39
+
40
+ * takuya kodama
41
+
42
+ * NAITOH Jun
43
+
44
+ * Bo Anderson
45
+
46
+ ## 3.3.6 - 2024-08-22 {#version-3-3-6}
47
+
48
+ ### Improvements
49
+
50
+ * Removed duplicated entity expansions for performance.
51
+ * GH-194
52
+ * Patch by Viktor Ivarsson.
53
+
54
+ * Improved namespace conflicted attribute check performance. It was
55
+ too slow for deep elements.
56
+ * Reported by l33thaxor.
57
+
58
+ ### Fixes
59
+
60
+ * Fixed a bug that default entity expansions are counted for
61
+ security check. Default entity expansions should not be counted
62
+ because they don't have a security risk.
63
+ * GH-198
64
+ * GH-199
65
+ * Patch Viktor Ivarsson
66
+
67
+ * Fixed a parser bug that parameter entity references in internal
68
+ subsets are expanded. It's not allowed in the XML specification.
69
+ * GH-191
70
+ * Patch by NAITOH Jun.
71
+
72
+ * Fixed a stream parser bug that user-defined entity references in
73
+ text aren't expanded.
74
+ * GH-200
75
+ * Patch by NAITOH Jun.
76
+
77
+ ### Thanks
78
+
79
+ * Viktor Ivarsson
80
+
81
+ * NAITOH Jun
82
+
83
+ * l33thaxor
84
+
85
+ ## 3.3.5 - 2024-08-12 {#version-3-3-5}
86
+
87
+ ### Fixes
88
+
89
+ * Fixed a bug that `REXML::Security.entity_expansion_text_limit`
90
+ check has wrong text size calculation in SAX and pull parsers.
91
+ * GH-193
92
+ * GH-195
93
+ * Reported by Viktor Ivarsson.
94
+ * Patch by NAITOH Jun.
95
+
96
+ ### Thanks
97
+
98
+ * Viktor Ivarsson
99
+
100
+ * NAITOH Jun
101
+
102
+ ## 3.3.4 - 2024-08-01 {#version-3-3-4}
103
+
104
+ ### Fixes
105
+
106
+ * Fixed a bug that `REXML::Security` isn't defined when
107
+ `REXML::Parsers::StreamParser` is used and
108
+ `rexml/parsers/streamparser` is only required.
109
+ * GH-189
110
+ * Patch by takuya kodama.
111
+
112
+ ### Thanks
113
+
114
+ * takuya kodama
115
+
116
+ ## 3.3.3 - 2024-08-01 {#version-3-3-3}
117
+
118
+ ### Improvements
119
+
120
+ * Added support for detecting invalid XML that has unsupported
121
+ content before root element
122
+ * GH-184
123
+ * Patch by NAITOH Jun.
124
+
125
+ * Added support for `REXML::Security.entity_expansion_limit=` and
126
+ `REXML::Security.entity_expansion_text_limit=` in SAX2 and pull
127
+ parsers
128
+ * GH-187
129
+ * Patch by NAITOH Jun.
130
+
131
+ * Added more tests for invalid XMLs.
132
+ * GH-183
133
+ * Patch by Watson.
134
+
135
+ * Added more performance tests.
136
+ * Patch by Watson.
137
+
138
+ * Improved parse performance.
139
+ * GH-186
140
+ * Patch by tomoya ishida.
141
+
142
+ ### Thanks
143
+
144
+ * NAITOH Jun
145
+
146
+ * Watson
147
+
148
+ * tomoya ishida
149
+
150
+ ## 3.3.2 - 2024-07-16 {#version-3-3-2}
151
+
152
+ ### Improvements
153
+
154
+ * Improved parse performance.
155
+ * GH-160
156
+ * Patch by NAITOH Jun.
157
+
158
+ * Improved parse performance.
159
+ * GH-169
160
+ * GH-170
161
+ * GH-171
162
+ * GH-172
163
+ * GH-173
164
+ * GH-174
165
+ * GH-175
166
+ * GH-176
167
+ * GH-177
168
+ * Patch by Watson.
169
+
170
+ * Added support for raising a parse exception when an XML has extra
171
+ content after the root element.
172
+ * GH-161
173
+ * Patch by NAITOH Jun.
174
+
175
+ * Added support for raising a parse exception when an XML
176
+ declaration exists in wrong position.
177
+ * GH-162
178
+ * Patch by NAITOH Jun.
179
+
180
+ * Removed needless a space after XML declaration in pretty print mode.
181
+ * GH-164
182
+ * Patch by NAITOH Jun.
183
+
184
+ * Stopped to emit `:text` event after the root element.
185
+ * GH-167
186
+ * Patch by NAITOH Jun.
187
+
188
+ ### Fixes
189
+
190
+ * Fixed a bug that SAX2 parser doesn't expand predefined entities for
191
+ `characters` callback.
192
+ * GH-168
193
+ * Patch by NAITOH Jun.
194
+
195
+ ### Thanks
196
+
197
+ * NAITOH Jun
198
+
199
+ * Watson
200
+
201
+ ## 3.3.1 - 2024-06-25 {#version-3-3-1}
202
+
203
+ ### Improvements
204
+
205
+ * Added support for detecting malformed top-level comments.
206
+ * GH-145
207
+ * Patch by Hiroya Fujinami.
208
+
209
+ * Improved `REXML::Element#attribute` performance.
210
+ * GH-146
211
+ * Patch by Hiroya Fujinami.
212
+
213
+ * Added support for detecting malformed `<!-->` comments.
214
+ * GH-147
215
+ * Patch by Hiroya Fujinami.
216
+
217
+ * Added support for detecting unclosed `DOCTYPE`.
218
+ * GH-152
219
+ * Patch by Hiroya Fujinami.
220
+
221
+ * Added `changlog_uri` metadata to gemspec.
222
+ * GH-156
223
+ * Patch by fynsta.
224
+
225
+ * Improved parse performance.
226
+ * GH-157
227
+ * GH-158
228
+ * Patch by NAITOH Jun.
229
+
230
+ ### Fixes
231
+
232
+ * Fixed a bug that large XML can't be parsed.
233
+ * GH-154
234
+ * Patch by NAITOH Jun.
235
+
236
+ * Fixed a bug that private constants are visible.
237
+ * GH-155
238
+ * Patch by NAITOH Jun.
239
+
240
+ ### Thanks
241
+
242
+ * Hiroya Fujinami
243
+
244
+ * NAITOH Jun
245
+
246
+ * fynsta
247
+
248
+ ## 3.3.0 - 2024-06-11 {#version-3-3-0}
249
+
250
+ ### Improvements
251
+
252
+ * Added support for strscan 0.7.0 installed with Ruby 2.6.
253
+ * GH-142
254
+ * Reported by Fernando Trigoso.
255
+
256
+ ### Thanks
257
+
258
+ * Fernando Trigoso
259
+
260
+ ## 3.2.9 - 2024-06-09 {#version-3-2-9}
261
+
262
+ ### Improvements
263
+
264
+ * Added support for old strscan.
265
+ * GH-132
266
+ * Reported by Adam.
267
+
268
+ * Improved attribute value parse performance.
269
+ * GH-135
270
+ * Patch by NAITOH Jun.
271
+
272
+ * Improved `REXML::Node#each_recursive` performance.
273
+ * GH-134
274
+ * GH-139
275
+ * Patch by Hiroya Fujinami.
276
+
277
+ * Improved text parse performance.
278
+ * Reported by mprogrammer.
279
+
280
+ ### Thanks
281
+
282
+ * Adam
283
+ * NAITOH Jun
284
+ * Hiroya Fujinami
285
+ * mprogrammer
286
+
287
+ ## 3.2.8 - 2024-05-16 {#version-3-2-8}
288
+
289
+ ### Fixes
290
+
291
+ * Suppressed a warning
292
+
293
+ ## 3.2.7 - 2024-05-16 {#version-3-2-7}
294
+
295
+ ### Improvements
296
+
297
+ * Improve parse performance by using `StringScanner`.
298
+
299
+ * GH-106
300
+ * GH-107
301
+ * GH-108
302
+ * GH-109
303
+ * GH-112
304
+ * GH-113
305
+ * GH-114
306
+ * GH-115
307
+ * GH-116
308
+ * GH-117
309
+ * GH-118
310
+ * GH-119
311
+ * GH-121
312
+
313
+ * Patch by NAITOH Jun.
314
+
315
+ * Improved parse performance when an attribute has many `<`s.
316
+
317
+ * GH-126
318
+
319
+ ### Fixes
320
+
321
+ * XPath: Fixed a bug of `normalize_space(array)`.
322
+
323
+ * GH-110
324
+ * GH-111
325
+
326
+ * Patch by flatisland.
327
+
328
+ * XPath: Fixed a bug that wrong position is used with nested path.
329
+
330
+ * GH-110
331
+ * GH-122
332
+
333
+ * Reported by jcavalieri.
334
+ * Patch by NAITOH Jun.
335
+
336
+ * Fixed a bug that an exception message can't be generated for
337
+ invalid encoding XML.
338
+
339
+ * GH-29
340
+ * GH-123
341
+
342
+ * Reported by DuKewu.
343
+ * Patch by NAITOH Jun.
344
+
345
+ ### Thanks
346
+
347
+ * NAITOH Jun
348
+ * flatisland
349
+ * jcavalieri
350
+ * DuKewu
351
+
352
+ ## 3.2.6 - 2023-07-27 {#version-3-2-6}
353
+
354
+ ### Improvements
355
+
356
+ * Required Ruby 2.5 or later explicitly.
357
+ [GH-69][gh-69]
358
+ [Patch by Ivo Anjo]
359
+
360
+ * Added documentation for maintenance cycle.
361
+ [GH-71][gh-71]
362
+ [Patch by Ivo Anjo]
363
+
364
+ * Added tutorial.
365
+ [GH-77][gh-77]
366
+ [GH-78][gh-78]
367
+ [Patch by Burdette Lamar]
368
+
369
+ * Improved performance and memory usage.
370
+ [GH-94][gh-94]
371
+ [Patch by fatkodima]
372
+
373
+ * `REXML::Parsers::XPathParser#abbreviate`: Added support for
374
+ function arguments.
375
+ [GH-95][gh-95]
376
+ [Reported by pulver]
377
+
378
+ * `REXML::Parsers::XPathParser#abbreviate`: Added support for string
379
+ literal that contains double-quote.
380
+ [GH-96][gh-96]
381
+ [Patch by pulver]
382
+
383
+ * `REXML::Parsers::XPathParser#abbreviate`: Added missing `/` to
384
+ `:descendant_or_self/:self/:parent`.
385
+ [GH-97][gh-97]
386
+ [Reported by pulver]
387
+
388
+ * `REXML::Parsers::XPathParser#abbreviate`: Added support for more patterns.
389
+ [GH-97][gh-97]
390
+ [Reported by pulver]
391
+
392
+ ### Fixes
393
+
394
+ * Fixed a typo in NEWS.
395
+ [GH-72][gh-72]
396
+ [Patch by Spencer Goodman]
397
+
398
+ * Fixed a typo in NEWS.
399
+ [GH-75][gh-75]
400
+ [Patch by Andrew Bromwich]
401
+
402
+ * Fixed documents.
403
+ [GH-87][gh-87]
404
+ [Patch by Alexander Ilyin]
405
+
406
+ * Fixed a bug that `Attriute` convert `'` and `&apos;` even when
407
+ `attribute_quote: :quote` is used.
408
+ [GH-92][gh-92]
409
+ [Reported by Edouard Brière]
410
+
411
+ * Fixed links in tutorial.
412
+ [GH-99][gh-99]
413
+ [Patch by gemmaro]
414
+
415
+
416
+ ### Thanks
417
+
418
+ * Ivo Anjo
419
+
420
+ * Spencer Goodman
421
+
422
+ * Andrew Bromwich
423
+
424
+ * Burdette Lamar
425
+
426
+ * Alexander Ilyin
427
+
428
+ * Edouard Brière
429
+
430
+ * fatkodima
431
+
432
+ * pulver
433
+
434
+ * gemmaro
435
+
436
+ [gh-69]:https://github.com/ruby/rexml/issues/69
437
+ [gh-71]:https://github.com/ruby/rexml/issues/71
438
+ [gh-72]:https://github.com/ruby/rexml/issues/72
439
+ [gh-75]:https://github.com/ruby/rexml/issues/75
440
+ [gh-77]:https://github.com/ruby/rexml/issues/77
441
+ [gh-87]:https://github.com/ruby/rexml/issues/87
442
+ [gh-92]:https://github.com/ruby/rexml/issues/92
443
+ [gh-94]:https://github.com/ruby/rexml/issues/94
444
+ [gh-95]:https://github.com/ruby/rexml/issues/95
445
+ [gh-96]:https://github.com/ruby/rexml/issues/96
446
+ [gh-97]:https://github.com/ruby/rexml/issues/97
447
+ [gh-98]:https://github.com/ruby/rexml/issues/98
448
+ [gh-99]:https://github.com/ruby/rexml/issues/99
449
+
450
+ ## 3.2.5 - 2021-04-05 {#version-3-2-5}
451
+
452
+ ### Improvements
453
+
454
+ * Add more validations to XPath parser.
455
+
456
+ * `require "rexml/document"` by default.
457
+ [GitHub#36][Patch by Koichi ITO]
458
+
459
+ * Don't add `#dclone` method to core classes globally.
460
+ [GitHub#37][Patch by Akira Matsuda]
461
+
462
+ * Add more documentations.
463
+ [Patch by Burdette Lamar]
464
+
465
+ * Added `REXML::Elements#parent`.
466
+ [GitHub#52][Patch by Burdette Lamar]
467
+
468
+ ### Fixes
469
+
470
+ * Fixed a bug that `REXML::DocType#clone` doesn't copy external ID
471
+ information.
472
+
473
+ * Fixed round-trip vulnerability bugs.
474
+ See also: https://www.ruby-lang.org/en/news/2021/04/05/xml-round-trip-vulnerability-in-rexml-cve-2021-28965/
475
+ [HackerOne#1104077][CVE-2021-28965][Reported by Juho Nurminen]
476
+
477
+ ### Thanks
478
+
479
+ * Koichi ITO
480
+
481
+ * Akira Matsuda
482
+
483
+ * Burdette Lamar
484
+
485
+ * Juho Nurminen
486
+
487
+ ## 3.2.4 - 2020-01-31 {#version-3-2-4}
488
+
489
+ ### Improvements
490
+
491
+ * Don't use `taint` with Ruby 2.7 or later.
492
+ [GitHub#21][Patch by Jeremy Evans]
493
+
494
+ ### Fixes
495
+
496
+ * Fixed a `elsif` typo.
497
+ [GitHub#22][Patch by Nobuyoshi Nakada]
498
+
499
+ ### Thanks
500
+
501
+ * Jeremy Evans
502
+
503
+ * Nobuyoshi Nakada
504
+
3
505
  ## 3.2.3 - 2019-10-12 {#version-3-2-3}
4
506
 
5
507
  ### Fixes
data/README.md CHANGED
@@ -4,21 +4,9 @@ REXML was inspired by the Electric XML library for Java, which features an easy-
4
4
 
5
5
  REXML supports both tree and stream document parsing. Stream parsing is faster (about 1.5 times as fast). However, with stream parsing, you don't get access to features such as XPath.
6
6
 
7
- ## Installation
7
+ ## API
8
8
 
9
- Add this line to your application's Gemfile:
10
-
11
- ```ruby
12
- gem 'rexml'
13
- ```
14
-
15
- And then execute:
16
-
17
- $ bundle
18
-
19
- Or install it yourself as:
20
-
21
- $ gem install rexml
9
+ See the [API documentation](https://ruby.github.io/rexml/).
22
10
 
23
11
  ## Usage
24
12
 
@@ -45,6 +33,15 @@ doc = Document.new string
45
33
 
46
34
  So parsing a string is just as easy as parsing a file.
47
35
 
36
+ ## Support
37
+
38
+ REXML support follows the same maintenance cycle as Ruby releases, as shown on <https://www.ruby-lang.org/en/downloads/branches/>.
39
+
40
+ If you are running on an end-of-life Ruby, do not expect modern REXML releases to be compatible with it; in fact, it's recommended that you DO NOT use this gem, and instead use the REXML version that came bundled with your end-of-life Ruby version.
41
+
42
+ The `required_ruby_version` on the gemspec is kept updated on a [best-effort basis](https://github.com/ruby/rexml/pull/70) by the community.
43
+ Up to version 3.2.5, this information was not set. That version [is known broken with at least Ruby < 2.3](https://github.com/ruby/rexml/issues/69).
44
+
48
45
  ## Development
49
46
 
50
47
  After checking out the repo, run `rake test` to run the tests.
@@ -0,0 +1,143 @@
1
+ == Element Context
2
+
3
+ Notes:
4
+ - All code on this page presupposes that the following has been executed:
5
+
6
+ require 'rexml/document'
7
+
8
+ - For convenience, examples on this page use +REXML::Document.new+, not +REXML::Element.new+.
9
+ This is completely valid, because REXML::Document is a subclass of REXML::Element.
10
+
11
+ The context for an element is a hash of processing directives
12
+ that influence the way \XML is read, stored, and written.
13
+ The context entries are:
14
+
15
+ - +:respect_whitespace+: controls treatment of whitespace.
16
+ - +:compress_whitespace+: determines whether whitespace is compressed.
17
+ - +:ignore_whitespace_nodes+: determines whether whitespace-only nodes are to be ignored.
18
+ - +:raw+: controls treatment of special characters and entities.
19
+
20
+ The default context for a new element is <tt>{}</tt>.
21
+ You can set the context at element-creation time:
22
+
23
+ d = REXML::Document.new('', {compress_whitespace: :all, raw: :all})
24
+ d.context # => {:compress_whitespace=>:all, :raw=>:all}
25
+
26
+ You can reset the entire context by assigning a new hash:
27
+
28
+ d.context = {ignore_whitespace_nodes: :all}
29
+ d.context # => {:ignore_whitespace_nodes=>:all}
30
+
31
+ Or you can create or modify an individual entry:
32
+
33
+ d.context[:raw] = :all
34
+ d.context # => {:ignore_whitespace_nodes=>:all, :raw=>:all}
35
+
36
+ === +:respect_whitespace+
37
+
38
+ Affects: +REXML::Element.new+, +REXML::Element.text=+.
39
+
40
+ By default, all parsed whitespace is respected (that is, stored whitespace not compressed):
41
+
42
+ xml_string = '<root><foo>a b</foo> <bar>c d</bar> <baz>e f</baz></root>'
43
+ d = REXML::Document.new(xml_string)
44
+ d.to_s # => "<root><foo>a b</foo> <bar>c d</bar> <baz>e f</baz></root>"
45
+
46
+ Use +:respect_whitespace+ with an array of element names
47
+ to specify the elements that _are_ to have their whitespace respected;
48
+ other elements' whitespace, and whitespace between elements, will be compressed.
49
+
50
+ In this example: +foo+ and +baz+ will have their whitespace respected;
51
+ +bar+ and the space between elements will have their whitespace compressed:
52
+
53
+ d = REXML::Document.new(xml_string, {respect_whitespace: ['foo', 'baz']})
54
+ d.to_s # => "<root><foo>a b</foo> <bar>c d</bar> <baz>e f</baz></root>"
55
+ bar = d.root[2] # => <bar> ... </>
56
+ bar.text = 'X Y'
57
+ d.to_s # => "<root><foo>a b</foo> <bar>X Y</bar> <baz>e f</baz></root>"
58
+
59
+ === +:compress_whitespace+
60
+
61
+ Affects: +REXML::Element.new+, +REXML::Element.text=+.
62
+
63
+ Use <tt>compress_whitespace: :all</tt>
64
+ to compress whitespace both within and between elements:
65
+
66
+ xml_string = '<root><foo>a b</foo> <bar>c d</bar> <baz>e f</baz></root>'
67
+ d = REXML::Document.new(xml_string, {compress_whitespace: :all})
68
+ d.to_s # => "<root><foo>a b</foo> <bar>c d</bar> <baz>e f</baz></root>"
69
+
70
+ Use +:compress_whitespace+ with an array of element names
71
+ to compress whitespace in those elements,
72
+ but not in other elements nor between elements.
73
+
74
+ In this example, +foo+ and +baz+ will have their whitespace compressed;
75
+ +bar+ and the space between elements will not:
76
+
77
+ d = REXML::Document.new(xml_string, {compress_whitespace: ['foo', 'baz']})
78
+ d.to_s # => "<root><foo>a b</foo> <bar>c d</bar> <baz>e f</baz></root>"
79
+ foo = d.root[0] # => <foo> ... </>
80
+ foo.text= 'X Y'
81
+ d.to_s # => "<root><foo>X Y</foo> <bar>c d</bar> <baz>e f</baz></root>"
82
+
83
+ === +:ignore_whitespace_nodes+
84
+
85
+ Affects: +REXML::Element.new+.
86
+
87
+ Use <tt>ignore_whitespace_nodes: :all</tt> to omit all whitespace-only elements.
88
+
89
+ In this example, +bar+ has a text node, while nodes +foo+ and +baz+ do not:
90
+
91
+ xml_string = '<root><foo> </foo><bar> BAR </bar><baz> </baz></root>'
92
+ d = REXML::Document.new(xml_string, {ignore_whitespace_nodes: :all})
93
+ d.to_s # => "<root><foo> FOO </foo><bar/><baz> BAZ </baz></root>"
94
+ root = d.root # => <root> ... </>
95
+ foo = root[0] # => <foo/>
96
+ bar = root[1] # => <bar> ... </>
97
+ baz = root[2] # => <baz/>
98
+ foo.first.class # => NilClass
99
+ bar.first.class # => REXML::Text
100
+ baz.first.class # => NilClass
101
+
102
+ Use +:ignore_whitespace_nodes+ with an array of element names
103
+ to specify the elements that are to have whitespace nodes ignored.
104
+
105
+ In this example, +bar+ and +baz+ have text nodes, while node +foo+ does not.
106
+
107
+ xml_string = '<root><foo> </foo><bar> BAR </bar><baz> </baz></root>'
108
+ d = REXML::Document.new(xml_string, {ignore_whitespace_nodes: ['foo']})
109
+ d.to_s # => "<root><foo/><bar> BAR </bar><baz> </baz></root>"
110
+ root = d.root # => <root> ... </>
111
+ foo = root[0] # => <foo/>
112
+ bar = root[1] # => <bar> ... </>
113
+ baz = root[2] # => <baz> ... </>
114
+ foo.first.class # => NilClass
115
+ bar.first.class # => REXML::Text
116
+ baz.first.class # => REXML::Text
117
+
118
+ === +:raw+
119
+
120
+ Affects: +Element.text=+, +Element.add_text+, +Text.to_s+.
121
+
122
+ Parsing of +a+ elements is not affected by +raw+:
123
+
124
+ xml_string = '<root><a>0 &lt; 1</a><b>1 &gt; 0</b></root>'
125
+ d = REXML::Document.new(xml_string, {:raw => ['a']})
126
+ d.root.to_s # => "<root><a>0 &lt; 1</a><b>1 &gt; 0</b></root>"
127
+ a, b = *d.root.elements
128
+ a.to_s # => "<a>0 &lt; 1</a>"
129
+ b.to_s # => "<b>1 &gt; 0</b>"
130
+
131
+ But Element#text= is affected:
132
+
133
+ a.text = '0 &lt; 1'
134
+ b.text = '1 &gt; 0'
135
+ a.to_s # => "<a>0 &lt; 1</a>"
136
+ b.to_s # => "<b>1 &amp;gt; 0</b>"
137
+
138
+ As is Element.add_text:
139
+
140
+ a.add_text(' so 1 &gt; 0')
141
+ b.add_text(' so 0 &lt; 1')
142
+ a.to_s # => "<a>0 &lt; 1 so 1 &gt; 0</a>"
143
+ b.to_s # => "<b>1 &amp;gt; 0 so 0 &amp;lt; 1</b>"