libxml-ruby 2.8.0 → 3.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/HISTORY +842 -775
- data/LICENSE +20 -20
- data/MANIFEST +166 -166
- data/README.rdoc +217 -184
- data/Rakefile +90 -78
- data/ext/libxml/extconf.h +3 -0
- data/ext/libxml/extconf.rb +61 -116
- data/ext/libxml/libxml.c +80 -76
- data/ext/libxml/ruby_libxml.h +67 -75
- data/ext/libxml/ruby_xml.c +933 -893
- data/ext/libxml/ruby_xml.h +10 -10
- data/ext/libxml/ruby_xml_attr.c +333 -333
- data/ext/libxml/ruby_xml_attr.h +12 -12
- data/ext/libxml/ruby_xml_attr_decl.c +153 -153
- data/ext/libxml/ruby_xml_attr_decl.h +11 -11
- data/ext/libxml/ruby_xml_attributes.c +275 -275
- data/ext/libxml/ruby_xml_attributes.h +15 -15
- data/ext/libxml/ruby_xml_cbg.c +85 -85
- data/ext/libxml/ruby_xml_document.c +1123 -1147
- data/ext/libxml/ruby_xml_document.h +11 -11
- data/ext/libxml/ruby_xml_dtd.c +248 -268
- data/ext/libxml/ruby_xml_dtd.h +9 -9
- data/ext/libxml/ruby_xml_encoding.c +250 -260
- data/ext/libxml/ruby_xml_encoding.h +16 -19
- data/ext/libxml/ruby_xml_error.c +996 -996
- data/ext/libxml/ruby_xml_error.h +12 -12
- data/ext/libxml/ruby_xml_html_parser.c +89 -92
- data/ext/libxml/ruby_xml_html_parser.h +10 -10
- data/ext/libxml/ruby_xml_html_parser_context.c +337 -338
- data/ext/libxml/ruby_xml_html_parser_context.h +10 -10
- data/ext/libxml/ruby_xml_html_parser_options.c +46 -46
- data/ext/libxml/ruby_xml_html_parser_options.h +10 -10
- data/ext/libxml/ruby_xml_input_cbg.c +191 -191
- data/ext/libxml/ruby_xml_input_cbg.h +20 -20
- data/ext/libxml/ruby_xml_io.c +47 -50
- data/ext/libxml/ruby_xml_io.h +10 -10
- data/ext/libxml/ruby_xml_namespace.c +153 -153
- data/ext/libxml/ruby_xml_namespace.h +10 -10
- data/ext/libxml/ruby_xml_namespaces.c +293 -293
- data/ext/libxml/ruby_xml_namespaces.h +9 -9
- data/ext/libxml/ruby_xml_node.c +1402 -1452
- data/ext/libxml/ruby_xml_node.h +13 -11
- data/ext/libxml/ruby_xml_parser.c +91 -94
- data/ext/libxml/ruby_xml_parser.h +12 -12
- data/ext/libxml/ruby_xml_parser_context.c +999 -1001
- data/ext/libxml/ruby_xml_parser_context.h +10 -10
- data/ext/libxml/ruby_xml_parser_options.c +66 -66
- data/ext/libxml/ruby_xml_parser_options.h +12 -12
- data/ext/libxml/ruby_xml_reader.c +1239 -1228
- data/ext/libxml/ruby_xml_reader.h +17 -17
- data/ext/libxml/ruby_xml_relaxng.c +110 -111
- data/ext/libxml/ruby_xml_relaxng.h +10 -10
- data/ext/libxml/ruby_xml_sax2_handler.c +326 -328
- data/ext/libxml/ruby_xml_sax2_handler.h +10 -10
- data/ext/libxml/ruby_xml_sax_parser.c +116 -120
- data/ext/libxml/ruby_xml_sax_parser.h +10 -10
- data/ext/libxml/ruby_xml_schema.c +278 -301
- data/ext/libxml/ruby_xml_schema.h +809 -809
- data/ext/libxml/ruby_xml_schema_attribute.c +109 -109
- data/ext/libxml/ruby_xml_schema_attribute.h +15 -15
- data/ext/libxml/ruby_xml_schema_element.c +95 -94
- data/ext/libxml/ruby_xml_schema_element.h +14 -14
- data/ext/libxml/ruby_xml_schema_facet.c +52 -52
- data/ext/libxml/ruby_xml_schema_facet.h +13 -13
- data/ext/libxml/ruby_xml_schema_type.c +232 -259
- data/ext/libxml/ruby_xml_schema_type.h +9 -9
- data/ext/libxml/ruby_xml_version.h +9 -9
- data/ext/libxml/ruby_xml_writer.c +1133 -1137
- data/ext/libxml/ruby_xml_writer.h +10 -10
- data/ext/libxml/ruby_xml_xinclude.c +16 -16
- data/ext/libxml/ruby_xml_xinclude.h +11 -11
- data/ext/libxml/ruby_xml_xpath.c +194 -188
- data/ext/libxml/ruby_xml_xpath.h +13 -13
- data/ext/libxml/ruby_xml_xpath_context.c +360 -361
- data/ext/libxml/ruby_xml_xpath_context.h +9 -9
- data/ext/libxml/ruby_xml_xpath_expression.c +81 -81
- data/ext/libxml/ruby_xml_xpath_expression.h +10 -10
- data/ext/libxml/ruby_xml_xpath_object.c +338 -335
- data/ext/libxml/ruby_xml_xpath_object.h +17 -17
- data/ext/libxml/ruby_xml_xpointer.c +99 -99
- data/ext/libxml/ruby_xml_xpointer.h +11 -11
- data/ext/vc/libxml_ruby.sln +17 -15
- data/lib/libxml-ruby.rb +30 -0
- data/lib/libxml.rb +3 -33
- data/lib/libxml/node.rb +2 -78
- data/lib/libxml/parser.rb +0 -266
- data/lib/libxml/sax_parser.rb +0 -17
- data/lib/libxml/schema.rb +47 -66
- data/lib/libxml/schema/attribute.rb +19 -19
- data/lib/libxml/schema/element.rb +19 -27
- data/lib/libxml/schema/type.rb +21 -29
- data/libxml-ruby.gemspec +48 -44
- data/script/benchmark/depixelate +634 -634
- data/script/benchmark/hamlet.xml +9054 -9054
- data/script/benchmark/parsecount +170 -170
- data/script/benchmark/throughput +41 -41
- data/script/test +6 -6
- data/setup.rb +0 -1
- data/test/c14n/given/example-1.xml +14 -14
- data/test/c14n/given/example-2.xml +11 -11
- data/test/c14n/given/example-3.xml +18 -18
- data/test/c14n/given/example-4.xml +9 -9
- data/test/c14n/given/example-5.xml +12 -12
- data/test/c14n/given/example-6.xml +2 -2
- data/test/c14n/given/example-7.xml +11 -11
- data/test/c14n/given/example-8.xml +11 -11
- data/test/c14n/given/example-8.xpath +9 -9
- data/test/c14n/result/1-1-without-comments/example-1 +3 -3
- data/test/c14n/result/1-1-without-comments/example-2 +10 -10
- data/test/c14n/result/1-1-without-comments/example-3 +13 -13
- data/test/c14n/result/1-1-without-comments/example-4 +8 -8
- data/test/c14n/result/1-1-without-comments/example-5 +2 -2
- data/test/c14n/result/with-comments/example-1 +5 -5
- data/test/c14n/result/with-comments/example-2 +10 -10
- data/test/c14n/result/with-comments/example-3 +13 -13
- data/test/c14n/result/with-comments/example-4 +8 -8
- data/test/c14n/result/with-comments/example-5 +3 -3
- data/test/c14n/result/without-comments/example-1 +3 -3
- data/test/c14n/result/without-comments/example-2 +10 -10
- data/test/c14n/result/without-comments/example-3 +13 -13
- data/test/c14n/result/without-comments/example-4 +8 -8
- data/test/c14n/result/without-comments/example-5 +2 -2
- data/test/model/atom.xml +12 -12
- data/test/model/bands.iso-8859-1.xml +4 -4
- data/test/model/bands.utf-8.xml +4 -4
- data/test/model/bands.xml +4 -4
- data/test/model/books.xml +153 -153
- data/test/model/cwm_1_0.xml +11336 -0
- data/test/model/merge_bug_data.xml +58 -58
- data/test/model/ruby-lang.html +238 -238
- data/test/model/rubynet.xml +79 -79
- data/test/model/shiporder.rnc +28 -28
- data/test/model/shiporder.rng +86 -86
- data/test/model/shiporder.xml +22 -22
- data/test/model/shiporder.xsd +39 -39
- data/test/model/soap.xml +27 -27
- data/test/model/xinclude.xml +4 -4
- data/test/test.xml +2 -0
- data/test/{tc_attr.rb → test_attr.rb} +23 -25
- data/test/{tc_attr_decl.rb → test_attr_decl.rb} +13 -14
- data/test/{tc_attributes.rb → test_attributes.rb} +11 -18
- data/test/{tc_canonicalize.rb → test_canonicalize.rb} +36 -41
- data/test/test_deprecated_require.rb +12 -0
- data/test/{tc_document.rb → test_document.rb} +32 -27
- data/test/test_document_write.rb +146 -0
- data/test/{tc_dtd.rb → test_dtd.rb} +28 -29
- data/test/{tc_encoding.rb → test_encoding.rb} +129 -126
- data/test/{tc_encoding_sax.rb → test_encoding_sax.rb} +7 -6
- data/test/test_error.rb +178 -0
- data/test/test_helper.rb +3 -10
- data/test/test_html_parser.rb +162 -0
- data/test/test_html_parser_context.rb +23 -0
- data/test/test_namespace.rb +60 -0
- data/test/{tc_namespaces.rb → test_namespaces.rb} +34 -44
- data/test/{tc_node.rb → test_node.rb} +68 -47
- data/test/{tc_node_cdata.rb → test_node_cdata.rb} +12 -13
- data/test/{tc_node_comment.rb → test_node_comment.rb} +7 -8
- data/test/{tc_node_copy.rb → test_node_copy.rb} +4 -6
- data/test/{tc_node_edit.rb → test_node_edit.rb} +23 -41
- data/test/{tc_node_pi.rb → test_node_pi.rb} +37 -40
- data/test/{tc_node_text.rb → test_node_text.rb} +10 -12
- data/test/{tc_node_write.rb → test_node_write.rb} +18 -29
- data/test/test_node_xlink.rb +28 -0
- data/test/test_parser.rb +324 -0
- data/test/{tc_parser_context.rb → test_parser_context.rb} +41 -42
- data/test/{tc_properties.rb → test_properties.rb} +6 -7
- data/test/test_reader.rb +363 -0
- data/test/test_relaxng.rb +53 -0
- data/test/{tc_sax_parser.rb → test_sax_parser.rb} +36 -37
- data/test/{tc_schema.rb → test_schema.rb} +43 -37
- data/test/test_suite.rb +38 -40
- data/test/{tc_traversal.rb → test_traversal.rb} +5 -6
- data/test/{tc_writer.rb → test_writer.rb} +468 -448
- data/test/{tc_xinclude.rb → test_xinclude.rb} +4 -5
- data/test/test_xml.rb +262 -0
- data/test/{tc_xpath.rb → test_xpath.rb} +31 -32
- data/test/{tc_xpath_context.rb → test_xpath_context.rb} +8 -9
- data/test/test_xpath_expression.rb +37 -0
- data/test/{tc_xpointer.rb → test_xpointer.rb} +16 -18
- metadata +117 -95
- data/lib/libxml/ns.rb +0 -22
- data/lib/libxml/properties.rb +0 -23
- data/lib/libxml/reader.rb +0 -29
- data/lib/libxml/xpath_object.rb +0 -16
- data/test/etc_doc_to_s.rb +0 -21
- data/test/ets_doc_file.rb +0 -17
- data/test/ets_doc_to_s.rb +0 -23
- data/test/ets_gpx.rb +0 -28
- data/test/ets_node_gc.rb +0 -23
- data/test/ets_test.xml +0 -2
- data/test/ets_tsr.rb +0 -11
- data/test/tc_deprecated_require.rb +0 -13
- data/test/tc_document_write.rb +0 -196
- data/test/tc_error.rb +0 -180
- data/test/tc_html_parser.rb +0 -153
- data/test/tc_html_parser_context.rb +0 -24
- data/test/tc_namespace.rb +0 -62
- data/test/tc_node_xlink.rb +0 -29
- data/test/tc_parser.rb +0 -381
- data/test/tc_reader.rb +0 -400
- data/test/tc_relaxng.rb +0 -54
- data/test/tc_xml.rb +0 -226
- data/test/tc_xpath_expression.rb +0 -38
@@ -1,15 +1,14 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
|
4
|
-
require 'test/unit'
|
3
|
+
require_relative './test_helper'
|
5
4
|
|
6
|
-
class TestTranversal < Test
|
5
|
+
class TestTranversal < Minitest::Test
|
7
6
|
ROOT_NODES_LENGTH = 27
|
8
7
|
ROOT_ELEMENTS_LENGTH = 13
|
9
8
|
|
10
9
|
def setup
|
11
10
|
filename = File.join(File.dirname(__FILE__), 'model/books.xml')
|
12
|
-
@doc = XML::Document.file(filename)
|
11
|
+
@doc = LibXML::XML::Document.file(filename)
|
13
12
|
end
|
14
13
|
|
15
14
|
def teardown
|
@@ -144,10 +143,10 @@ class TestTranversal < Test::Unit::TestCase
|
|
144
143
|
end
|
145
144
|
|
146
145
|
def test_doc_class
|
147
|
-
assert_instance_of(XML::Document, @doc)
|
146
|
+
assert_instance_of(LibXML::XML::Document, @doc)
|
148
147
|
end
|
149
148
|
|
150
149
|
def test_root_class
|
151
|
-
assert_instance_of(XML::Node, @doc.root)
|
150
|
+
assert_instance_of(LibXML::XML::Node, @doc.root)
|
152
151
|
end
|
153
152
|
end
|
@@ -1,448 +1,468 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
|
4
|
-
require 'stringio'
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
writer
|
13
|
-
writer.
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
writer
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
writer
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
writer
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
writer
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
writer
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
end
|
100
|
-
assert_equal(writer.result.strip!, expected)
|
101
|
-
end
|
102
|
-
|
103
|
-
def
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
end
|
114
|
-
assert_equal(writer.result.strip!,
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
writer
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
assert(writer.write_string '
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
assert(writer.
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
assert_equal(writer.result,
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
assert(writer.
|
348
|
-
assert(writer.write_string '
|
349
|
-
assert(writer.
|
350
|
-
end
|
351
|
-
assert_equal(writer.result, expected)
|
352
|
-
|
353
|
-
writer = XML::Writer.string
|
354
|
-
dtd writer, 'html' do
|
355
|
-
assert(writer.
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
assert(writer.
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
end
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
writer.
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
writer
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
assert(writer.
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
end
|
448
|
-
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require_relative './test_helper'
|
4
|
+
require 'stringio'
|
5
|
+
|
6
|
+
class TestWriter < Minitest::Test
|
7
|
+
XSL_PREFIX = 'xsl'
|
8
|
+
XSL_URI = 'http://www.w3.org/1999/XSL/Transform'
|
9
|
+
|
10
|
+
def test_generic_failure
|
11
|
+
writer = LibXML::XML::Writer.string
|
12
|
+
writer.start_document
|
13
|
+
assert(!writer.end_element)
|
14
|
+
writer.end_document
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_empty_doc
|
18
|
+
writer = LibXML::XML::Writer.string
|
19
|
+
document(writer)
|
20
|
+
assert_equal(writer.result.strip!, '<?xml version="1.0"?>')
|
21
|
+
|
22
|
+
writer = LibXML::XML::Writer.string
|
23
|
+
document(writer, :encoding => LibXML::XML::Encoding::ISO_8859_1)
|
24
|
+
assert_equal(writer.result.strip!, '<?xml version="1.0" encoding="ISO-8859-1"?>')
|
25
|
+
|
26
|
+
writer = LibXML::XML::Writer.string
|
27
|
+
document(writer, :standalone => 1)
|
28
|
+
assert_equal(writer.result.strip!, '<?xml version="1.0" standalone="yes"?>')
|
29
|
+
|
30
|
+
writer = LibXML::XML::Writer.string
|
31
|
+
document(writer, :standalone => 1, :encoding => LibXML::XML::Encoding::ISO_8859_1, :foo => :bar)
|
32
|
+
assert_equal(writer.result.strip!, '<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>')
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_file_encoding
|
36
|
+
value = "François".encode(Encoding::UTF_8)
|
37
|
+
|
38
|
+
File.open('test.xml', 'wb', encoding: 'UTF-8') do |file|
|
39
|
+
writer = LibXML::XML::Writer::io(file)
|
40
|
+
document(writer, encoding: LibXML::XML::Encoding::UTF_8) do
|
41
|
+
writer.write_element('Name', value)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_io_encoding
|
47
|
+
value = "François".encode(Encoding::UTF_8)
|
48
|
+
expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Name>François</Name>".encode(Encoding::UTF_8)
|
49
|
+
|
50
|
+
io = StringIO.new
|
51
|
+
writer = LibXML::XML::Writer::io(io)
|
52
|
+
document(writer, encoding: LibXML::XML::Encoding::UTF_8) do
|
53
|
+
writer.write_element('Name', value)
|
54
|
+
end
|
55
|
+
assert_equal(expected, io.string.strip)
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_single_root
|
59
|
+
writer = LibXML::XML::Writer.string
|
60
|
+
document(writer) do
|
61
|
+
element writer, 'root'
|
62
|
+
end
|
63
|
+
|
64
|
+
assert_equal(writer.result.strip!, "<?xml version=\"1.0\"?>\n<root/>")
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_pi
|
68
|
+
expected = "<?xml version=\"1.0\"?>\n<?php echo \"foo\";?>"
|
69
|
+
|
70
|
+
writer = LibXML::XML::Writer.string
|
71
|
+
document(writer) do
|
72
|
+
assert(writer.start_pi('php'))
|
73
|
+
assert(writer.write_string('echo "foo";'))
|
74
|
+
assert(writer.end_pi)
|
75
|
+
end
|
76
|
+
assert_equal(writer.result.strip!, expected)
|
77
|
+
|
78
|
+
writer = LibXML::XML::Writer.string
|
79
|
+
document(writer) do
|
80
|
+
assert(writer.write_pi('php', 'echo "foo";'))
|
81
|
+
end
|
82
|
+
assert_equal(writer.result.strip!, expected)
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_comment
|
86
|
+
expected = "<?xml version=\"1.0\"?>\n<!--foo-->"
|
87
|
+
|
88
|
+
writer = LibXML::XML::Writer.string
|
89
|
+
document(writer) do
|
90
|
+
assert(writer.start_comment)
|
91
|
+
assert(writer.write_string 'foo')
|
92
|
+
assert(writer.end_comment)
|
93
|
+
end
|
94
|
+
assert_equal(writer.result.strip!, expected)
|
95
|
+
|
96
|
+
writer = LibXML::XML::Writer.string
|
97
|
+
document(writer) do
|
98
|
+
assert(writer.write_comment 'foo')
|
99
|
+
end
|
100
|
+
assert_equal(writer.result.strip!, expected)
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_cdata
|
104
|
+
expected = "<?xml version=\"1.0\"?>\n<root><![CDATA[<?php echo $foo; ?>]]></root>"
|
105
|
+
|
106
|
+
writer = LibXML::XML::Writer.string
|
107
|
+
document(writer) do
|
108
|
+
element writer, 'root' do
|
109
|
+
assert(writer.start_cdata)
|
110
|
+
assert(writer.write_string '<?php echo $foo; ?>')
|
111
|
+
assert(writer.end_cdata)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
assert_equal(writer.result.strip!, expected)
|
115
|
+
|
116
|
+
writer = LibXML::XML::Writer.string
|
117
|
+
document(writer) do
|
118
|
+
element writer, 'root' do
|
119
|
+
assert(writer.write_cdata '<?php echo $foo; ?>')
|
120
|
+
end
|
121
|
+
end
|
122
|
+
assert_equal(writer.result.strip!, expected)
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_write_empty_elements
|
126
|
+
writer = LibXML::XML::Writer.string
|
127
|
+
document(writer) do
|
128
|
+
assert(writer.write_element 'foo')
|
129
|
+
end
|
130
|
+
assert_equal(writer.result.strip!, "<?xml version=\"1.0\"?>\n<foo/>")
|
131
|
+
|
132
|
+
writer = LibXML::XML::Writer.string
|
133
|
+
document(writer) do
|
134
|
+
assert(writer.write_element_ns XSL_PREFIX, 'stylesheet', XSL_URI)
|
135
|
+
end
|
136
|
+
assert_equal(writer.result.strip!, "<?xml version=\"1.0\"?>\n<" + XSL_PREFIX + ":stylesheet xmlns:xsl=\"" + XSL_URI + "\"/>")
|
137
|
+
end
|
138
|
+
|
139
|
+
def test_valued_element
|
140
|
+
expected = "<?xml version=\"1.0\"?>\n<abc>123<def>456<ghi>789</ghi>cueillir des cerises</def>nous irons au bois</abc>"
|
141
|
+
|
142
|
+
writer = LibXML::XML::Writer.string
|
143
|
+
document(writer) do
|
144
|
+
assert(writer.start_element 'abc')
|
145
|
+
assert(writer.write_string '123')
|
146
|
+
assert(writer.start_element 'def')
|
147
|
+
assert(writer.write_string '456')
|
148
|
+
assert(writer.start_element 'ghi')
|
149
|
+
assert(writer.write_string '789')
|
150
|
+
assert(writer.end_element)
|
151
|
+
assert(writer.write_string 'cueillir des cerises')
|
152
|
+
assert(writer.end_element)
|
153
|
+
assert(writer.write_string 'nous irons au bois')
|
154
|
+
assert(writer.end_element)
|
155
|
+
end
|
156
|
+
assert_equal(writer.result.strip!, expected)
|
157
|
+
|
158
|
+
writer = LibXML::XML::Writer.string
|
159
|
+
document(writer) do
|
160
|
+
assert(writer.start_element 'abc')
|
161
|
+
assert(writer.write_string '123')
|
162
|
+
assert(writer.start_element 'def')
|
163
|
+
assert(writer.write_string '456')
|
164
|
+
assert(writer.write_element 'ghi', '789')
|
165
|
+
assert(writer.write_string 'cueillir des cerises')
|
166
|
+
assert(writer.end_element)
|
167
|
+
assert(writer.write_string 'nous irons au bois')
|
168
|
+
assert(writer.end_element)
|
169
|
+
end
|
170
|
+
assert_equal(writer.result.strip!, expected)
|
171
|
+
end
|
172
|
+
|
173
|
+
def test_valued_element_ns
|
174
|
+
expected = "<?xml version=\"1.0\"?>\n" +
|
175
|
+
"<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">" +
|
176
|
+
"<xsl:attribute-set>" +
|
177
|
+
"<xsl:attribute>20px</xsl:attribute>" +
|
178
|
+
"<xsl:attribute>solid</xsl:attribute>" +
|
179
|
+
"</xsl:attribute-set>" +
|
180
|
+
"</xsl:stylesheet>"
|
181
|
+
|
182
|
+
writer = LibXML::XML::Writer.string
|
183
|
+
document(writer) do
|
184
|
+
assert(writer.start_element_ns XSL_PREFIX, 'stylesheet', XSL_URI)
|
185
|
+
assert(writer.start_element_ns XSL_PREFIX, 'attribute-set')
|
186
|
+
assert(writer.start_element_ns XSL_PREFIX, 'attribute')
|
187
|
+
assert(writer.write_string '20px')
|
188
|
+
assert(writer.end_element)
|
189
|
+
assert(writer.start_element_ns XSL_PREFIX, 'attribute')
|
190
|
+
assert(writer.write_string 'solid')
|
191
|
+
assert(writer.end_element)
|
192
|
+
assert(writer.end_element)
|
193
|
+
assert(writer.end_element)
|
194
|
+
end
|
195
|
+
assert_equal(writer.result.strip!, expected)
|
196
|
+
|
197
|
+
writer = LibXML::XML::Writer.string
|
198
|
+
document(writer) do
|
199
|
+
assert(writer.start_element_ns XSL_PREFIX, 'stylesheet', XSL_URI)
|
200
|
+
assert(writer.start_element_ns XSL_PREFIX, 'attribute-set')
|
201
|
+
assert(writer.write_element_ns XSL_PREFIX, 'attribute', nil, '20px')
|
202
|
+
assert(writer.write_element_ns XSL_PREFIX, 'attribute', nil, 'solid')
|
203
|
+
assert(writer.end_element)
|
204
|
+
assert(writer.end_element)
|
205
|
+
end
|
206
|
+
assert_equal(writer.result.strip!, expected)
|
207
|
+
end
|
208
|
+
|
209
|
+
def test_attribute
|
210
|
+
writer = LibXML::XML::Writer.string
|
211
|
+
document(writer) do
|
212
|
+
element writer, 'root' do
|
213
|
+
element writer, 'child' do
|
214
|
+
assert(writer.start_attribute 'foo')
|
215
|
+
assert(writer.write_string 'bar')
|
216
|
+
assert(writer.end_attribute)
|
217
|
+
end
|
218
|
+
end
|
219
|
+
end
|
220
|
+
assert_equal(writer.result.strip!, "<?xml version=\"1.0\"?>\n<root><child foo=\"bar\"/></root>")
|
221
|
+
|
222
|
+
writer = LibXML::XML::Writer.string
|
223
|
+
document(writer) do
|
224
|
+
element writer, 'root' do
|
225
|
+
element writer, 'child' do
|
226
|
+
assert(writer.write_attribute 'abc', 'def')
|
227
|
+
assert(writer.write_string 'ghi') # must be done after attributes
|
228
|
+
end
|
229
|
+
end
|
230
|
+
end
|
231
|
+
assert_equal(writer.result.strip!, "<?xml version=\"1.0\"?>\n<root><child abc=\"def\">ghi</child></root>")
|
232
|
+
end
|
233
|
+
|
234
|
+
def test_attribute_ns
|
235
|
+
expected = "<?xml version=\"1.0\"?>\n<root><link xlink:href=\"abc\" xhtml:class=\"def\"/></root>"
|
236
|
+
|
237
|
+
writer = LibXML::XML::Writer.string
|
238
|
+
document(writer) do
|
239
|
+
element writer, 'root' do
|
240
|
+
element writer, 'link' do
|
241
|
+
assert(writer.write_attribute_ns 'xlink', 'href', nil, 'abc')
|
242
|
+
assert(writer.write_attribute_ns 'xhtml', 'class', nil, 'def')
|
243
|
+
end
|
244
|
+
end
|
245
|
+
end
|
246
|
+
assert_equal(writer.result.strip!, expected)
|
247
|
+
|
248
|
+
writer = LibXML::XML::Writer.string
|
249
|
+
document(writer) do
|
250
|
+
element writer, 'root' do
|
251
|
+
element writer, 'link' do
|
252
|
+
assert(writer.start_attribute_ns 'xlink', 'href')
|
253
|
+
assert(writer.write_string 'abc')
|
254
|
+
assert(writer.end_attribute)
|
255
|
+
assert(writer.start_attribute_ns 'xhtml', 'class')
|
256
|
+
assert(writer.write_string 'def')
|
257
|
+
assert(writer.end_attribute)
|
258
|
+
end
|
259
|
+
end
|
260
|
+
end
|
261
|
+
assert_equal(writer.result.strip!, expected)
|
262
|
+
end
|
263
|
+
|
264
|
+
def test_quote_char
|
265
|
+
if LibXML::XML::Writer.method_defined? :set_quote_char
|
266
|
+
writer = LibXML::XML::Writer.string
|
267
|
+
writer.set_quote_char "'"
|
268
|
+
document(writer) do
|
269
|
+
element writer, 'root' do
|
270
|
+
assert(writer.start_attribute 'abc')
|
271
|
+
assert(writer.write_string 'def')
|
272
|
+
assert(writer.end_attribute)
|
273
|
+
end
|
274
|
+
end
|
275
|
+
assert(writer.result.strip!.end_with? "<root abc='def'/>")
|
276
|
+
end
|
277
|
+
end
|
278
|
+
|
279
|
+
def test_indentation_on
|
280
|
+
if LibXML::XML::Writer.method_defined? :set_indent
|
281
|
+
writer = LibXML::XML::Writer.string
|
282
|
+
assert(writer.set_indent true)
|
283
|
+
document(writer) do
|
284
|
+
element writer, 'root' do
|
285
|
+
element writer, 'child' do
|
286
|
+
assert(writer.start_attribute 'abc')
|
287
|
+
assert(writer.write_string 'def')
|
288
|
+
assert(writer.end_attribute)
|
289
|
+
end
|
290
|
+
end
|
291
|
+
end
|
292
|
+
assert_equal(writer.result.strip!, "<?xml version=\"1.0\"?>\n<root>\n <child abc=\"def\"/>\n</root>")
|
293
|
+
end
|
294
|
+
end
|
295
|
+
|
296
|
+
def test_indentation_string
|
297
|
+
if LibXML::XML::Writer.method_defined? :set_indent_string
|
298
|
+
writer = LibXML::XML::Writer.string
|
299
|
+
assert(writer.set_indent true)
|
300
|
+
assert(writer.set_indent_string ' ' * 4)
|
301
|
+
document(writer) do
|
302
|
+
element writer, 'root' do
|
303
|
+
element writer, 'child' do
|
304
|
+
assert(writer.start_attribute 'abc')
|
305
|
+
assert(writer.write_string 'def')
|
306
|
+
assert(writer.end_attribute)
|
307
|
+
end
|
308
|
+
end
|
309
|
+
end
|
310
|
+
assert_equal(writer.result.strip!, "<?xml version=\"1.0\"?>\n<root>\n <child abc=\"def\"/>\n</root>")
|
311
|
+
end
|
312
|
+
end
|
313
|
+
|
314
|
+
def test_dtd_declaration
|
315
|
+
writer = LibXML::XML::Writer.string
|
316
|
+
dtd writer, 'html'
|
317
|
+
assert_equal(writer.result, '<!DOCTYPE html>')
|
318
|
+
|
319
|
+
writer = LibXML::XML::Writer.string
|
320
|
+
dtd writer, 'html', '-//W3C//DTD XHTML 1.0 Strict//EN', 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'
|
321
|
+
assert_equal(writer.result, '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">')
|
322
|
+
end
|
323
|
+
|
324
|
+
def test_dtd_attlist
|
325
|
+
expected = '<!DOCTYPE http [<!ATTLIST method (get|post) "get">]>'
|
326
|
+
|
327
|
+
writer = LibXML::XML::Writer.string
|
328
|
+
dtd writer, 'http' do
|
329
|
+
assert(writer.start_dtd_attlist 'method')
|
330
|
+
assert(writer.write_string '(get|post) "get"')
|
331
|
+
assert(writer.end_dtd_attlist)
|
332
|
+
end
|
333
|
+
assert_equal(writer.result, expected)
|
334
|
+
|
335
|
+
writer = LibXML::XML::Writer.string
|
336
|
+
dtd writer, 'http' do
|
337
|
+
assert(writer.write_dtd_attlist 'method', '(get|post) "get"')
|
338
|
+
end
|
339
|
+
assert_equal(writer.result, expected)
|
340
|
+
end
|
341
|
+
|
342
|
+
def test_dtd_element
|
343
|
+
expected = '<!DOCTYPE html [<!ELEMENT dl (dt|dd)+>]>'
|
344
|
+
|
345
|
+
writer = LibXML::XML::Writer.string
|
346
|
+
dtd writer, 'html' do
|
347
|
+
assert(writer.start_dtd_element 'dl')
|
348
|
+
assert(writer.write_string '(dt|dd)+')
|
349
|
+
assert(writer.end_dtd_element)
|
350
|
+
end
|
351
|
+
assert_equal(writer.result, expected)
|
352
|
+
|
353
|
+
writer = LibXML::XML::Writer.string
|
354
|
+
dtd writer, 'html' do
|
355
|
+
assert(writer.write_dtd_element 'dl', '(dt|dd)+')
|
356
|
+
end
|
357
|
+
assert_equal(writer.result, expected)
|
358
|
+
end
|
359
|
+
|
360
|
+
def test_dtd_entity
|
361
|
+
# parameterized entity
|
362
|
+
expected = '<!DOCTYPE html [<!ENTITY % special.pre "br | span | bdo | map"><!ENTITY % special "%special.pre; | object | img">]>'
|
363
|
+
|
364
|
+
writer = LibXML::XML::Writer.string
|
365
|
+
dtd writer, 'html' do
|
366
|
+
assert(writer.start_dtd_entity 'special.pre', true)
|
367
|
+
assert(writer.write_string 'br | span | bdo | map')
|
368
|
+
assert(writer.end_dtd_entity)
|
369
|
+
assert(writer.start_dtd_entity 'special', true)
|
370
|
+
assert(writer.write_string '%special.pre; | object | img')
|
371
|
+
assert(writer.end_dtd_entity)
|
372
|
+
end
|
373
|
+
assert_equal(writer.result, expected)
|
374
|
+
|
375
|
+
writer = LibXML::XML::Writer.string
|
376
|
+
dtd writer, 'html' do
|
377
|
+
assert(writer.write_dtd_internal_entity 'special.pre', 'br | span | bdo | map', true)
|
378
|
+
assert(writer.write_dtd_internal_entity 'special', '%special.pre; | object | img', true)
|
379
|
+
end
|
380
|
+
assert_equal(writer.result, expected)
|
381
|
+
|
382
|
+
# non parameterized entity
|
383
|
+
expected = '<!DOCTYPE html [<!ENTITY Alpha "Α">]>'
|
384
|
+
|
385
|
+
writer = LibXML::XML::Writer.string
|
386
|
+
dtd writer, 'html' do
|
387
|
+
assert(writer.start_dtd_entity 'Alpha')
|
388
|
+
assert(writer.write_string 'Α')
|
389
|
+
assert(writer.end_dtd_entity)
|
390
|
+
end
|
391
|
+
assert_equal(writer.result, expected)
|
392
|
+
|
393
|
+
writer = LibXML::XML::Writer.string
|
394
|
+
dtd writer, 'html' do
|
395
|
+
assert(writer.start_dtd_entity 'Alpha', false)
|
396
|
+
assert(writer.write_string 'Α')
|
397
|
+
assert(writer.end_dtd_entity)
|
398
|
+
end
|
399
|
+
assert_equal(writer.result, expected)
|
400
|
+
|
401
|
+
writer = LibXML::XML::Writer.string
|
402
|
+
dtd writer, 'html' do
|
403
|
+
assert(writer.write_dtd_internal_entity 'Alpha', 'Α', false)
|
404
|
+
end
|
405
|
+
assert_equal(writer.result, expected)
|
406
|
+
end
|
407
|
+
|
408
|
+
def test_dtd_notation
|
409
|
+
writer = LibXML::XML::Writer.string
|
410
|
+
dtd writer, 'pictures' do
|
411
|
+
assert(writer.write_dtd_notation 'GIF89a', '-//Compuserve//NOTATION Graphics Interchange Format 89a//EN', nil)
|
412
|
+
assert(writer.write_dtd_external_entity 'pictures', nil, 'images/plage.gif', 'GIF89a', false)
|
413
|
+
end
|
414
|
+
assert_equal(writer.result, '<!DOCTYPE pictures [<!NOTATION GIF89a PUBLIC "-//Compuserve//NOTATION Graphics Interchange Format 89a//EN"><!ENTITY pictures SYSTEM "images/plage.gif" NDATA GIF89a>]>')
|
415
|
+
end
|
416
|
+
|
417
|
+
def test_encoding
|
418
|
+
iso = 'éloïse'.encode 'ISO-8859-1'
|
419
|
+
|
420
|
+
writer = LibXML::XML::Writer.string
|
421
|
+
document(writer) do
|
422
|
+
assert(writer.write_element iso)
|
423
|
+
end
|
424
|
+
assert_equal(writer.result.strip!, "<?xml version=\"1.0\"?>\n<éloïse/>")
|
425
|
+
end
|
426
|
+
|
427
|
+
def test_flush
|
428
|
+
writer = LibXML::XML::Writer.string
|
429
|
+
assert(writer.start_document)
|
430
|
+
assert_equal(writer.flush.strip!, '<?xml version="1.0"?>')
|
431
|
+
assert(writer.start_element 'foo')
|
432
|
+
assert(writer.end_element)
|
433
|
+
assert(writer.end_document)
|
434
|
+
writer.flush false
|
435
|
+
assert_equal(writer.result.strip, '<foo/>')
|
436
|
+
end
|
437
|
+
|
438
|
+
def test_nil_pe_issue
|
439
|
+
expected = '<!DOCTYPE html [<!ENTITY special.pre "br | span | bdo | map"><!ENTITY special "%special.pre; | object | img">]>'
|
440
|
+
|
441
|
+
writer = LibXML::XML::Writer.string
|
442
|
+
dtd writer, 'html' do
|
443
|
+
assert(writer.write_dtd_internal_entity 'special.pre', 'br | span | bdo | map', nil)
|
444
|
+
assert(writer.write_dtd_internal_entity 'special', '%special.pre; | object | img', nil)
|
445
|
+
end
|
446
|
+
assert_equal(writer.result, expected)
|
447
|
+
end
|
448
|
+
|
449
|
+
private
|
450
|
+
|
451
|
+
def document(writer, options = {})
|
452
|
+
assert(writer.start_document options)
|
453
|
+
yield if block_given?
|
454
|
+
assert(writer.end_document)
|
455
|
+
end
|
456
|
+
|
457
|
+
def dtd(writer, name, pubid = nil, sysid = nil)
|
458
|
+
assert(writer.start_dtd name, pubid, sysid)
|
459
|
+
yield if block_given?
|
460
|
+
assert(writer.end_dtd)
|
461
|
+
end
|
462
|
+
|
463
|
+
def element(writer, localname)
|
464
|
+
assert(writer.start_element localname)
|
465
|
+
yield if block_given?
|
466
|
+
assert(writer.end_element)
|
467
|
+
end
|
468
|
+
end
|