libxml-ruby 0.8.3-x86-mswin32-60 → 0.9.0-x86-mswin32-60
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.
- data/CHANGES +18 -0
- data/RAKEFILE +15 -39
- data/README +48 -47
- data/ext/libxml/libxml.c +847 -22
- data/ext/libxml/ruby_libxml.h +71 -95
- data/ext/libxml/ruby_xml_attr.c +500 -500
- data/ext/libxml/ruby_xml_attributes.c +1 -1
- data/ext/libxml/ruby_xml_document.c +1144 -1135
- data/ext/libxml/ruby_xml_document.h +4 -11
- data/ext/libxml/ruby_xml_dtd.c +27 -0
- data/ext/libxml/ruby_xml_encoding.c +164 -0
- data/ext/libxml/ruby_xml_encoding.h +13 -0
- data/ext/libxml/ruby_xml_error.c +941 -0
- data/ext/libxml/ruby_xml_error.h +13 -0
- data/ext/libxml/ruby_xml_html_parser.c +71 -387
- data/ext/libxml/ruby_xml_html_parser.h +1 -17
- data/ext/libxml/ruby_xml_input.c +179 -0
- data/ext/libxml/ruby_xml_input.h +18 -0
- data/ext/libxml/ruby_xml_input_cbg.c +17 -3
- data/ext/libxml/ruby_xml_node.c +1566 -1582
- data/ext/libxml/ruby_xml_node.h +1 -4
- data/ext/libxml/ruby_xml_ns.c +14 -3
- data/ext/libxml/ruby_xml_parser.c +164 -1398
- data/ext/libxml/ruby_xml_parser.h +5 -17
- data/ext/libxml/ruby_xml_parser_context.c +131 -169
- data/ext/libxml/ruby_xml_parser_context.h +2 -9
- data/ext/libxml/ruby_xml_reader.c +910 -945
- data/ext/libxml/ruby_xml_relaxng.c +32 -3
- data/ext/libxml/ruby_xml_sax_parser.c +106 -364
- data/ext/libxml/ruby_xml_sax_parser.h +1 -37
- data/ext/libxml/ruby_xml_schema.c +174 -145
- data/ext/libxml/ruby_xml_xinclude.c +9 -5
- data/ext/libxml/ruby_xml_xpath.c +25 -6
- data/ext/libxml/ruby_xml_xpath.h +1 -2
- data/ext/libxml/ruby_xml_xpath_context.c +17 -19
- data/ext/libxml/ruby_xml_xpath_object.c +60 -56
- data/ext/libxml/ruby_xml_xpointer.c +11 -5
- data/ext/libxml/sax_parser_callbacks.inc +42 -37
- data/ext/libxml/version.h +3 -3
- data/ext/mingw/Rakefile +20 -27
- data/ext/mingw/build.rake +41 -0
- data/{lib → ext/mingw}/libiconv-2.dll +0 -0
- data/ext/mingw/libxml2-2.dll +0 -0
- data/ext/mingw/libxml_ruby.dll.a +0 -0
- data/ext/mingw/libxml_ruby.so +0 -0
- data/ext/vc/libxml_ruby.vcproj +23 -15
- data/lib/libxml.rb +8 -2
- data/lib/libxml/document.rb +16 -4
- data/lib/libxml/error.rb +84 -0
- data/lib/libxml/hpricot.rb +76 -0
- data/lib/libxml/html_parser.rb +61 -0
- data/lib/libxml/node.rb +36 -25
- data/lib/libxml/parser.rb +312 -33
- data/lib/libxml/parser_context.rb +17 -0
- data/lib/libxml/properties.rb +15 -2
- data/lib/libxml/reader.rb +15 -0
- data/lib/libxml/sax_callbacks.rb +179 -0
- data/lib/libxml/sax_parser.rb +42 -0
- data/lib/libxml/tree.rb +1 -2
- data/lib/libxml/xpath_object.rb +12 -0
- data/test/model/atom.xml +4 -0
- data/test/tc_attributes.rb +43 -19
- data/test/tc_document.rb +1 -1
- data/test/tc_document_write.rb +15 -8
- data/test/tc_dtd.rb +36 -20
- data/test/tc_encoding.rb +13 -0
- data/test/tc_error.rb +136 -0
- data/test/tc_node.rb +2 -3
- data/test/tc_node_copy.rb +1 -1
- data/test/tc_node_edit.rb +6 -0
- data/test/tc_ns.rb +18 -0
- data/test/tc_parser.rb +113 -228
- data/test/tc_parser_context.rb +1 -2
- data/test/tc_reader.rb +24 -14
- data/test/tc_relaxng.rb +18 -6
- data/test/tc_sax_parser.rb +48 -13
- data/test/tc_schema.rb +20 -8
- data/test/tc_well_formed.rb +2 -1
- data/test/tc_xml.rb +212 -0
- data/test/tc_xpath.rb +60 -46
- data/test/tc_xpointer.rb +7 -11
- data/test/test_suite.rb +4 -3
- metadata +32 -115
- data/doc/rdoc/classes/LibXML.html +0 -241
- data/doc/rdoc/classes/LibXML/XML.html +0 -185
- data/doc/rdoc/classes/LibXML/XML/Attr.html +0 -1010
- data/doc/rdoc/classes/LibXML/XML/Attributes.html +0 -526
- data/doc/rdoc/classes/LibXML/XML/Document.html +0 -1489
- data/doc/rdoc/classes/LibXML/XML/Dtd.html +0 -213
- data/doc/rdoc/classes/LibXML/XML/Error.html +0 -117
- data/doc/rdoc/classes/LibXML/XML/HTMLParser.html +0 -348
- data/doc/rdoc/classes/LibXML/XML/InputCallbacks.html +0 -160
- data/doc/rdoc/classes/LibXML/XML/NS.html +0 -381
- data/doc/rdoc/classes/LibXML/XML/Node.html +0 -3396
- data/doc/rdoc/classes/LibXML/XML/Node/FailedModify.html +0 -123
- data/doc/rdoc/classes/LibXML/XML/Node/Set.html +0 -440
- data/doc/rdoc/classes/LibXML/XML/Node/SetNamespace.html +0 -123
- data/doc/rdoc/classes/LibXML/XML/Node/UnknownType.html +0 -123
- data/doc/rdoc/classes/LibXML/XML/Parser.html +0 -2239
- data/doc/rdoc/classes/LibXML/XML/Parser/Context.html +0 -1255
- data/doc/rdoc/classes/LibXML/XML/Parser/ParseError.html +0 -123
- data/doc/rdoc/classes/LibXML/XML/Reader.html +0 -2264
- data/doc/rdoc/classes/LibXML/XML/RelaxNG.html +0 -237
- data/doc/rdoc/classes/LibXML/XML/SaxParser.html +0 -415
- data/doc/rdoc/classes/LibXML/XML/Schema.html +0 -308
- data/doc/rdoc/classes/LibXML/XML/State.html +0 -124
- data/doc/rdoc/classes/LibXML/XML/Tree.html +0 -111
- data/doc/rdoc/classes/LibXML/XML/XInclude.html +0 -123
- data/doc/rdoc/classes/LibXML/XML/XInclude/Error.html +0 -117
- data/doc/rdoc/classes/LibXML/XML/XMLParserOptions.html +0 -198
- data/doc/rdoc/classes/LibXML/XML/XPath.html +0 -184
- data/doc/rdoc/classes/LibXML/XML/XPath/Context.html +0 -404
- data/doc/rdoc/classes/LibXML/XML/XPath/InvalidPath.html +0 -172
- data/doc/rdoc/classes/LibXML/XML/XPath/Object.html +0 -627
- data/doc/rdoc/classes/LibXML/XML/XPointer.html +0 -170
- data/doc/rdoc/classes/LibXML/XML/XPointer/Context.html +0 -123
- data/doc/rdoc/classes/LibXML/XML/XPointer/Context/InvalidPath.html +0 -117
- data/doc/rdoc/classes/LibXML/XML/XPointer/InvalidExpression.html +0 -124
- data/doc/rdoc/classes/singleton.html +0 -114
- data/doc/rdoc/created.rid +0 -1
- data/doc/rdoc/files/CHANGES.html +0 -442
- data/doc/rdoc/files/LICENSE.html +0 -133
- data/doc/rdoc/files/README.html +0 -388
- data/doc/rdoc/files/VERSION.html +0 -107
- data/doc/rdoc/files/ext/libxml/cbg_c.html +0 -101
- data/doc/rdoc/files/ext/libxml/libxml_c.html +0 -101
- data/doc/rdoc/files/ext/libxml/ruby_xml_attr_c.html +0 -101
- data/doc/rdoc/files/ext/libxml/ruby_xml_attributes_c.html +0 -101
- data/doc/rdoc/files/ext/libxml/ruby_xml_document_c.html +0 -101
- data/doc/rdoc/files/ext/libxml/ruby_xml_dtd_c.html +0 -101
- data/doc/rdoc/files/ext/libxml/ruby_xml_html_parser_c.html +0 -101
- data/doc/rdoc/files/ext/libxml/ruby_xml_input_cbg_c.html +0 -101
- data/doc/rdoc/files/ext/libxml/ruby_xml_node_c.html +0 -101
- data/doc/rdoc/files/ext/libxml/ruby_xml_node_set_c.html +0 -101
- data/doc/rdoc/files/ext/libxml/ruby_xml_ns_c.html +0 -101
- data/doc/rdoc/files/ext/libxml/ruby_xml_parser_c.html +0 -101
- data/doc/rdoc/files/ext/libxml/ruby_xml_parser_context_c.html +0 -101
- data/doc/rdoc/files/ext/libxml/ruby_xml_reader_c.html +0 -101
- data/doc/rdoc/files/ext/libxml/ruby_xml_relaxng_c.html +0 -101
- data/doc/rdoc/files/ext/libxml/ruby_xml_sax_parser_c.html +0 -101
- data/doc/rdoc/files/ext/libxml/ruby_xml_schema_c.html +0 -101
- data/doc/rdoc/files/ext/libxml/ruby_xml_state_c.html +0 -101
- data/doc/rdoc/files/ext/libxml/ruby_xml_xinclude_c.html +0 -101
- data/doc/rdoc/files/ext/libxml/ruby_xml_xpath_c.html +0 -101
- data/doc/rdoc/files/ext/libxml/ruby_xml_xpath_context_c.html +0 -101
- data/doc/rdoc/files/ext/libxml/ruby_xml_xpath_object_c.html +0 -101
- data/doc/rdoc/files/ext/libxml/ruby_xml_xpointer_c.html +0 -101
- data/doc/rdoc/files/ext/libxml/ruby_xml_xpointer_context_c.html +0 -101
- data/doc/rdoc/files/lib/libxml/attr_rb.html +0 -108
- data/doc/rdoc/files/lib/libxml/attributes_rb.html +0 -108
- data/doc/rdoc/files/lib/libxml/document_rb.html +0 -108
- data/doc/rdoc/files/lib/libxml/node_rb.html +0 -108
- data/doc/rdoc/files/lib/libxml/node_set_rb.html +0 -108
- data/doc/rdoc/files/lib/libxml/parser_options_rb.html +0 -107
- data/doc/rdoc/files/lib/libxml/parser_rb.html +0 -101
- data/doc/rdoc/files/lib/libxml/properties_rb.html +0 -108
- data/doc/rdoc/files/lib/libxml/tree_rb.html +0 -107
- data/doc/rdoc/files/lib/libxml_rb.html +0 -124
- data/doc/rdoc/files/lib/xml/libxml_rb.html +0 -124
- data/doc/rdoc/files/lib/xml_rb.html +0 -134
- data/doc/rdoc/fr_class_index.html +0 -62
- data/doc/rdoc/fr_file_index.html +0 -66
- data/doc/rdoc/fr_method_index.html +0 -392
- data/doc/rdoc/index.html +0 -24
- data/doc/rdoc/rdoc-style.css +0 -208
- data/ext/libxml/ruby_xml_node_set.c +0 -172
- data/ext/libxml/ruby_xml_node_set.h +0 -20
- data/ext/libxml/ruby_xml_xpointer_context.c +0 -22
- data/ext/libxml/ruby_xml_xpointer_context.h +0 -18
- data/lib/libxml/node_set.rb +0 -27
- data/lib/libxml2-2.dll +0 -0
- data/lib/libxml_ruby.dll.a +0 -0
- data/lib/libxml_ruby.so +0 -0
- data/test/tc_node_set.rb +0 -24
- data/test/tc_node_set2.rb +0 -37
@@ -1,1135 +1,1144 @@
|
|
1
|
-
/* $Id: ruby_xml_document.c
|
2
|
-
|
3
|
-
/*
|
4
|
-
|
5
|
-
|
6
|
-
*
|
7
|
-
*
|
8
|
-
*
|
9
|
-
*
|
10
|
-
*
|
11
|
-
*
|
12
|
-
*
|
13
|
-
* doc = XML::Document.new()
|
14
|
-
* doc.root = XML::Node.new('root_node')
|
15
|
-
* doc.root << XML::Node.new('elem1')
|
16
|
-
* doc.save('output.xml', format)
|
17
|
-
*
|
18
|
-
*
|
19
|
-
*
|
20
|
-
*
|
21
|
-
*
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
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
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
}
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
VALUE
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
else
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
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
|
-
|
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
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
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
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
break;
|
422
|
-
case
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
*
|
450
|
-
*
|
451
|
-
|
452
|
-
|
453
|
-
*
|
454
|
-
|
455
|
-
VALUE
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
}
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
xdoc
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
*
|
551
|
-
*
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
*
|
729
|
-
*
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
if (
|
739
|
-
rb_raise(
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
if (
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
|
750
|
-
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
|
767
|
-
|
768
|
-
|
769
|
-
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
*
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
|
805
|
-
|
806
|
-
|
807
|
-
|
808
|
-
|
809
|
-
|
810
|
-
|
811
|
-
|
812
|
-
|
813
|
-
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
|
819
|
-
|
820
|
-
|
821
|
-
|
822
|
-
|
823
|
-
|
824
|
-
|
825
|
-
|
826
|
-
|
827
|
-
|
828
|
-
|
829
|
-
|
830
|
-
|
831
|
-
|
832
|
-
|
833
|
-
|
834
|
-
|
835
|
-
|
836
|
-
|
837
|
-
|
838
|
-
|
839
|
-
|
840
|
-
|
841
|
-
|
842
|
-
|
843
|
-
|
844
|
-
|
845
|
-
|
846
|
-
|
847
|
-
|
848
|
-
|
849
|
-
|
850
|
-
|
851
|
-
|
852
|
-
|
853
|
-
|
854
|
-
|
855
|
-
|
856
|
-
|
857
|
-
|
858
|
-
|
859
|
-
|
860
|
-
|
861
|
-
|
862
|
-
|
863
|
-
|
864
|
-
*
|
865
|
-
|
866
|
-
|
867
|
-
*
|
868
|
-
|
869
|
-
|
870
|
-
|
871
|
-
|
872
|
-
|
873
|
-
|
874
|
-
|
875
|
-
|
876
|
-
|
877
|
-
|
878
|
-
|
879
|
-
|
880
|
-
|
881
|
-
|
882
|
-
*
|
883
|
-
*
|
884
|
-
*
|
885
|
-
|
886
|
-
|
887
|
-
|
888
|
-
|
889
|
-
|
890
|
-
|
891
|
-
|
892
|
-
|
893
|
-
|
894
|
-
|
895
|
-
return(
|
896
|
-
|
897
|
-
|
898
|
-
|
899
|
-
|
900
|
-
|
901
|
-
|
902
|
-
|
903
|
-
|
904
|
-
|
905
|
-
|
906
|
-
{
|
907
|
-
|
908
|
-
|
909
|
-
|
910
|
-
|
911
|
-
|
912
|
-
|
913
|
-
|
914
|
-
|
915
|
-
|
916
|
-
|
917
|
-
|
918
|
-
|
919
|
-
|
920
|
-
|
921
|
-
|
922
|
-
|
923
|
-
|
924
|
-
|
925
|
-
|
926
|
-
|
927
|
-
|
928
|
-
|
929
|
-
|
930
|
-
|
931
|
-
|
932
|
-
|
933
|
-
|
934
|
-
|
935
|
-
|
936
|
-
|
937
|
-
|
938
|
-
|
939
|
-
|
940
|
-
|
941
|
-
|
942
|
-
|
943
|
-
|
944
|
-
|
945
|
-
|
946
|
-
|
947
|
-
|
948
|
-
|
949
|
-
|
950
|
-
|
951
|
-
|
952
|
-
|
953
|
-
|
954
|
-
|
955
|
-
|
956
|
-
|
957
|
-
|
958
|
-
|
959
|
-
|
960
|
-
|
961
|
-
|
962
|
-
|
963
|
-
|
964
|
-
|
965
|
-
|
966
|
-
|
967
|
-
|
968
|
-
|
969
|
-
|
970
|
-
|
971
|
-
|
972
|
-
|
973
|
-
|
974
|
-
|
975
|
-
|
976
|
-
|
977
|
-
|
978
|
-
|
979
|
-
|
980
|
-
|
981
|
-
|
982
|
-
|
983
|
-
|
984
|
-
|
985
|
-
|
986
|
-
|
987
|
-
|
988
|
-
|
989
|
-
|
990
|
-
|
991
|
-
|
992
|
-
|
993
|
-
|
994
|
-
|
995
|
-
|
996
|
-
|
997
|
-
|
998
|
-
|
999
|
-
|
1000
|
-
|
1001
|
-
|
1002
|
-
|
1003
|
-
|
1004
|
-
|
1005
|
-
|
1006
|
-
|
1007
|
-
|
1008
|
-
|
1009
|
-
|
1010
|
-
|
1011
|
-
|
1012
|
-
|
1013
|
-
|
1014
|
-
|
1015
|
-
|
1016
|
-
|
1017
|
-
|
1018
|
-
|
1019
|
-
|
1020
|
-
|
1021
|
-
|
1022
|
-
|
1023
|
-
|
1024
|
-
|
1025
|
-
|
1026
|
-
|
1027
|
-
|
1028
|
-
|
1029
|
-
|
1030
|
-
|
1031
|
-
|
1032
|
-
|
1033
|
-
|
1034
|
-
|
1035
|
-
|
1036
|
-
|
1037
|
-
|
1038
|
-
|
1039
|
-
|
1040
|
-
|
1041
|
-
|
1042
|
-
|
1043
|
-
|
1044
|
-
|
1045
|
-
|
1046
|
-
|
1047
|
-
|
1048
|
-
|
1049
|
-
|
1050
|
-
|
1051
|
-
|
1052
|
-
|
1053
|
-
|
1054
|
-
|
1055
|
-
|
1056
|
-
|
1057
|
-
|
1058
|
-
|
1059
|
-
|
1060
|
-
|
1061
|
-
|
1062
|
-
|
1063
|
-
|
1064
|
-
|
1065
|
-
|
1066
|
-
|
1067
|
-
|
1068
|
-
|
1069
|
-
|
1070
|
-
|
1071
|
-
|
1072
|
-
|
1073
|
-
|
1074
|
-
|
1075
|
-
|
1076
|
-
|
1077
|
-
|
1078
|
-
|
1079
|
-
|
1080
|
-
|
1081
|
-
|
1082
|
-
|
1083
|
-
|
1084
|
-
|
1085
|
-
|
1086
|
-
|
1087
|
-
|
1088
|
-
|
1089
|
-
|
1090
|
-
|
1091
|
-
|
1092
|
-
|
1093
|
-
|
1094
|
-
|
1095
|
-
|
1096
|
-
|
1097
|
-
|
1098
|
-
|
1099
|
-
|
1100
|
-
|
1101
|
-
|
1102
|
-
|
1103
|
-
|
1104
|
-
|
1105
|
-
|
1106
|
-
|
1107
|
-
|
1108
|
-
|
1109
|
-
|
1110
|
-
|
1111
|
-
rb_define_method(cXMLDocument, "
|
1112
|
-
rb_define_method(cXMLDocument, "
|
1113
|
-
rb_define_method(cXMLDocument, "
|
1114
|
-
rb_define_method(cXMLDocument, "
|
1115
|
-
rb_define_method(cXMLDocument, "
|
1116
|
-
rb_define_method(cXMLDocument, "
|
1117
|
-
rb_define_method(cXMLDocument, "
|
1118
|
-
rb_define_method(cXMLDocument, "
|
1119
|
-
rb_define_method(cXMLDocument, "
|
1120
|
-
rb_define_method(cXMLDocument, "
|
1121
|
-
rb_define_method(cXMLDocument, "
|
1122
|
-
rb_define_method(cXMLDocument, "
|
1123
|
-
rb_define_method(cXMLDocument, "
|
1124
|
-
rb_define_method(cXMLDocument, "
|
1125
|
-
rb_define_method(cXMLDocument, "
|
1126
|
-
rb_define_method(cXMLDocument, "
|
1127
|
-
rb_define_method(cXMLDocument, "
|
1128
|
-
rb_define_method(cXMLDocument, "
|
1129
|
-
rb_define_method(cXMLDocument, "
|
1130
|
-
rb_define_method(cXMLDocument, "
|
1131
|
-
rb_define_method(cXMLDocument, "
|
1132
|
-
rb_define_method(cXMLDocument, "
|
1133
|
-
rb_define_method(cXMLDocument, "
|
1134
|
-
rb_define_method(cXMLDocument, "
|
1135
|
-
|
1
|
+
/* $Id: ruby_xml_document.c 575 2008-11-18 09:22:15Z cfis $ */
|
2
|
+
|
3
|
+
/*
|
4
|
+
* Document-class: LibXML::XML::Document
|
5
|
+
*
|
6
|
+
* The XML::Document class provides a tree based API for working
|
7
|
+
* with xml documents. You may directly create a document and
|
8
|
+
* manipulate it, or create a document from a data source by
|
9
|
+
* using an XML::Parser object.
|
10
|
+
*
|
11
|
+
* To create a document from scratch:
|
12
|
+
*
|
13
|
+
* doc = XML::Document.new()
|
14
|
+
* doc.root = XML::Node.new('root_node')
|
15
|
+
* doc.root << XML::Node.new('elem1')
|
16
|
+
* doc.save('output.xml', format)
|
17
|
+
*
|
18
|
+
* To read a document
|
19
|
+
*
|
20
|
+
* doc = XML::Document.file('my_file')
|
21
|
+
*
|
22
|
+
* To use a parser to read a document:
|
23
|
+
*
|
24
|
+
* parser = XML::Parser.new
|
25
|
+
* parser.file = 'my_file'
|
26
|
+
* doc = parser.parse
|
27
|
+
*/
|
28
|
+
|
29
|
+
#include <stdarg.h>
|
30
|
+
#include <st.h>
|
31
|
+
#include "ruby_libxml.h"
|
32
|
+
#include "ruby_xml_document.h"
|
33
|
+
|
34
|
+
|
35
|
+
VALUE cXMLDocument;
|
36
|
+
|
37
|
+
|
38
|
+
/* We have to make sure that documents are freed after
|
39
|
+
XPathObjects. The Ruby gc does not guarantee this
|
40
|
+
at shutdown or in normal operation when a document,
|
41
|
+
xpath context and xpath object form a cycle. So
|
42
|
+
we implement this simple reference counting scheme.
|
43
|
+
It works as you'd expect, except with a simple twist.
|
44
|
+
If a document is freed, but still has outstanding
|
45
|
+
references, its reference count is made negative. Thus
|
46
|
+
if it has ref_count of 1, then its becomes -1. At that
|
47
|
+
point, decrement will increase the account to 0, and
|
48
|
+
once it reaches 0, the document is freed. */
|
49
|
+
|
50
|
+
static st_table *ref_count_table = 0;
|
51
|
+
|
52
|
+
void
|
53
|
+
ruby_xml_document_internal_free(xmlDocPtr xdoc) {
|
54
|
+
st_delete(ref_count_table, (st_data_t*)&xdoc, 0);
|
55
|
+
xdoc->_private = NULL;
|
56
|
+
xmlFreeDoc(xdoc);
|
57
|
+
}
|
58
|
+
|
59
|
+
int
|
60
|
+
ruby_xml_document_incr(xmlDocPtr xdoc) {
|
61
|
+
int ref_count;
|
62
|
+
|
63
|
+
if (st_lookup(ref_count_table, (st_data_t)xdoc, (st_data_t*)&ref_count))
|
64
|
+
{
|
65
|
+
ref_count++;
|
66
|
+
st_insert(ref_count_table, (st_data_t)xdoc, (st_data_t)ref_count);
|
67
|
+
}
|
68
|
+
else
|
69
|
+
{
|
70
|
+
ref_count = 1;
|
71
|
+
st_add_direct(ref_count_table, (st_data_t)xdoc, (st_data_t)ref_count);
|
72
|
+
}
|
73
|
+
|
74
|
+
return ref_count;
|
75
|
+
}
|
76
|
+
|
77
|
+
int
|
78
|
+
ruby_xml_document_decr(xmlDocPtr xdoc) {
|
79
|
+
int ref_count = 0;
|
80
|
+
|
81
|
+
if (!st_lookup(ref_count_table, (st_data_t)xdoc, (st_data_t*)&ref_count))
|
82
|
+
rb_raise(rb_eRuntimeError, "Document does not have a reference count.");
|
83
|
+
|
84
|
+
if (ref_count == 0)
|
85
|
+
{
|
86
|
+
rb_raise(rb_eRuntimeError, "Document already has no references.");
|
87
|
+
}
|
88
|
+
else if (ref_count > 0)
|
89
|
+
{
|
90
|
+
ref_count--;
|
91
|
+
}
|
92
|
+
else
|
93
|
+
{
|
94
|
+
ref_count++;
|
95
|
+
if (ref_count == 0)
|
96
|
+
{
|
97
|
+
ruby_xml_document_internal_free(xdoc);
|
98
|
+
return ref_count;
|
99
|
+
}
|
100
|
+
}
|
101
|
+
|
102
|
+
st_insert(ref_count_table, (st_data_t)xdoc, ref_count);
|
103
|
+
return ref_count;
|
104
|
+
}
|
105
|
+
|
106
|
+
void
|
107
|
+
ruby_xml_document_free(xmlDocPtr xdoc) {
|
108
|
+
int ref_count;
|
109
|
+
|
110
|
+
if (!st_lookup(ref_count_table, (st_data_t)xdoc, (st_data_t*)&ref_count))
|
111
|
+
{
|
112
|
+
ruby_xml_document_internal_free(xdoc);
|
113
|
+
}
|
114
|
+
else if (ref_count == 0)
|
115
|
+
{
|
116
|
+
ruby_xml_document_internal_free(xdoc);
|
117
|
+
}
|
118
|
+
else if (ref_count > 0)
|
119
|
+
{
|
120
|
+
ref_count *= -1;
|
121
|
+
st_insert(ref_count_table, (st_data_t)xdoc, ref_count);
|
122
|
+
}
|
123
|
+
else
|
124
|
+
{
|
125
|
+
rb_raise(rb_eRuntimeError, "Ruby is attempting to free document twice.");
|
126
|
+
}
|
127
|
+
}
|
128
|
+
|
129
|
+
void
|
130
|
+
ruby_xml_document_mark(xmlDocPtr xdoc) {
|
131
|
+
rb_gc_mark(LIBXML_STATE);
|
132
|
+
}
|
133
|
+
|
134
|
+
VALUE
|
135
|
+
ruby_xml_document_wrap(xmlDocPtr xdoc) {
|
136
|
+
VALUE result;
|
137
|
+
|
138
|
+
// This node is already wrapped
|
139
|
+
if (xdoc->_private != NULL)
|
140
|
+
{
|
141
|
+
result = (VALUE)xdoc->_private;
|
142
|
+
}
|
143
|
+
else
|
144
|
+
{
|
145
|
+
result = Data_Wrap_Struct(cXMLDocument, ruby_xml_document_mark, ruby_xml_document_free, xdoc);
|
146
|
+
xdoc->_private = (void*)result;
|
147
|
+
}
|
148
|
+
|
149
|
+
return result;
|
150
|
+
}
|
151
|
+
|
152
|
+
|
153
|
+
/*
|
154
|
+
* call-seq:
|
155
|
+
* XML::Document.alloc(xml_version = 1.0) -> document
|
156
|
+
*
|
157
|
+
* Alocates a new XML::Document, optionally specifying the
|
158
|
+
* XML version.
|
159
|
+
*/
|
160
|
+
VALUE
|
161
|
+
ruby_xml_document_alloc(VALUE klass) {
|
162
|
+
return Data_Wrap_Struct(klass, ruby_xml_document_mark, ruby_xml_document_free, NULL);
|
163
|
+
}
|
164
|
+
|
165
|
+
/*
|
166
|
+
* call-seq:
|
167
|
+
* XML::Document.initialize(xml_version = 1.0) -> document
|
168
|
+
*
|
169
|
+
* Initializes a new XML::Document, optionally specifying the
|
170
|
+
* XML version.
|
171
|
+
*/
|
172
|
+
VALUE
|
173
|
+
ruby_xml_document_initialize(int argc, VALUE *argv, VALUE self) {
|
174
|
+
xmlDocPtr xdoc;
|
175
|
+
VALUE xmlver;
|
176
|
+
|
177
|
+
switch (argc) {
|
178
|
+
case 0:
|
179
|
+
xmlver = rb_str_new2("1.0");
|
180
|
+
break;
|
181
|
+
case 1:
|
182
|
+
rb_scan_args(argc, argv, "01", &xmlver);
|
183
|
+
break;
|
184
|
+
default:
|
185
|
+
rb_raise(rb_eArgError, "wrong number of arguments (need 0 or 1)");
|
186
|
+
}
|
187
|
+
|
188
|
+
Check_Type(xmlver, T_STRING);
|
189
|
+
xdoc = xmlNewDoc((xmlChar*)StringValuePtr(xmlver));
|
190
|
+
xdoc->_private = (void*)self;
|
191
|
+
DATA_PTR(self) = xdoc;
|
192
|
+
|
193
|
+
return self;
|
194
|
+
}
|
195
|
+
|
196
|
+
|
197
|
+
/*
|
198
|
+
* call-seq:
|
199
|
+
* document.compression -> num
|
200
|
+
*
|
201
|
+
* Obtain this document's compression mode identifier.
|
202
|
+
*/
|
203
|
+
VALUE
|
204
|
+
ruby_xml_document_compression_get(VALUE self) {
|
205
|
+
#ifdef HAVE_ZLIB_H
|
206
|
+
xmlDocPtr xdoc;
|
207
|
+
|
208
|
+
int compmode;
|
209
|
+
Data_Get_Struct(self, xmlDoc, xdoc);
|
210
|
+
|
211
|
+
compmode = xmlGetDocCompressMode(xdoc);
|
212
|
+
if (compmode == -1)
|
213
|
+
return(Qnil);
|
214
|
+
else
|
215
|
+
return(INT2NUM(compmode));
|
216
|
+
#else
|
217
|
+
rb_warn("libxml not compiled with zlib support");
|
218
|
+
return(Qfalse);
|
219
|
+
#endif
|
220
|
+
}
|
221
|
+
|
222
|
+
|
223
|
+
/*
|
224
|
+
* call-seq:
|
225
|
+
* document.compression = num
|
226
|
+
*
|
227
|
+
* Set this document's compression mode.
|
228
|
+
*/
|
229
|
+
VALUE
|
230
|
+
ruby_xml_document_compression_set(VALUE self, VALUE num) {
|
231
|
+
#ifdef HAVE_ZLIB_H
|
232
|
+
xmlDocPtr xdoc;
|
233
|
+
|
234
|
+
int compmode;
|
235
|
+
Check_Type(num, T_FIXNUM);
|
236
|
+
Data_Get_Struct(self, xmlDoc, xdoc);
|
237
|
+
|
238
|
+
if (xdoc == NULL) {
|
239
|
+
return(Qnil);
|
240
|
+
} else {
|
241
|
+
xmlSetDocCompressMode(xdoc, NUM2INT(num));
|
242
|
+
|
243
|
+
compmode = xmlGetDocCompressMode(xdoc);
|
244
|
+
if (compmode == -1)
|
245
|
+
return(Qnil);
|
246
|
+
else
|
247
|
+
return(INT2NUM(compmode));
|
248
|
+
}
|
249
|
+
#else
|
250
|
+
rb_warn("libxml compiled without zlib support");
|
251
|
+
return(Qfalse);
|
252
|
+
#endif
|
253
|
+
}
|
254
|
+
|
255
|
+
|
256
|
+
/*
|
257
|
+
* call-seq:
|
258
|
+
* document.compression? -> (true|false)
|
259
|
+
*
|
260
|
+
* Determine whether this document is compressed.
|
261
|
+
*/
|
262
|
+
VALUE
|
263
|
+
ruby_xml_document_compression_q(VALUE self) {
|
264
|
+
#ifdef HAVE_ZLIB_H
|
265
|
+
xmlDocPtr xdoc;
|
266
|
+
|
267
|
+
Data_Get_Struct(self, xmlDoc, xdoc);
|
268
|
+
|
269
|
+
if (xdoc->compression != -1)
|
270
|
+
return(Qtrue);
|
271
|
+
else
|
272
|
+
return(Qfalse);
|
273
|
+
#else
|
274
|
+
rb_warn("libxml compiled without zlib support");
|
275
|
+
return(Qfalse);
|
276
|
+
#endif
|
277
|
+
}
|
278
|
+
|
279
|
+
|
280
|
+
/*
|
281
|
+
* call-seq:
|
282
|
+
* document.child -> node
|
283
|
+
*
|
284
|
+
* Get this document's child node.
|
285
|
+
*/
|
286
|
+
VALUE
|
287
|
+
ruby_xml_document_child_get(VALUE self) {
|
288
|
+
xmlDocPtr xdoc;
|
289
|
+
Data_Get_Struct(self, xmlDoc, xdoc);
|
290
|
+
|
291
|
+
if (xdoc->children == NULL)
|
292
|
+
return(Qnil);
|
293
|
+
|
294
|
+
return ruby_xml_node2_wrap(cXMLNode, xdoc->children);
|
295
|
+
}
|
296
|
+
|
297
|
+
|
298
|
+
/*
|
299
|
+
* call-seq:
|
300
|
+
* document.child? -> (true|false)
|
301
|
+
*
|
302
|
+
* Determine whether this document has a child node.
|
303
|
+
*/
|
304
|
+
VALUE
|
305
|
+
ruby_xml_document_child_q(VALUE self) {
|
306
|
+
xmlDocPtr xdoc;
|
307
|
+
Data_Get_Struct(self, xmlDoc, xdoc);
|
308
|
+
|
309
|
+
if (xdoc->children == NULL)
|
310
|
+
return(Qfalse);
|
311
|
+
else
|
312
|
+
return(Qtrue);
|
313
|
+
}
|
314
|
+
|
315
|
+
|
316
|
+
/*
|
317
|
+
* call-seq:
|
318
|
+
* document.dump([stream]) -> true
|
319
|
+
*
|
320
|
+
* Dump this document's XML to the specified IO stream.
|
321
|
+
* If no stream is specified, stdout is used.
|
322
|
+
*/
|
323
|
+
VALUE
|
324
|
+
ruby_xml_document_dump(int argc, VALUE *argv, VALUE self) {
|
325
|
+
OpenFile *fptr;
|
326
|
+
VALUE io;
|
327
|
+
FILE *out;
|
328
|
+
xmlDocPtr xdoc;
|
329
|
+
|
330
|
+
Data_Get_Struct(self, xmlDoc, xdoc);
|
331
|
+
if (xdoc == NULL)
|
332
|
+
return(Qnil);
|
333
|
+
|
334
|
+
switch (argc) {
|
335
|
+
case 0:
|
336
|
+
io = rb_stdout;
|
337
|
+
break;
|
338
|
+
case 1:
|
339
|
+
io = argv[0];
|
340
|
+
if (!rb_obj_is_kind_of(io, rb_cIO))
|
341
|
+
rb_raise(rb_eTypeError, "need an IO object");
|
342
|
+
break;
|
343
|
+
default:
|
344
|
+
rb_raise(rb_eArgError, "wrong number of arguments (0 or 1)");
|
345
|
+
}
|
346
|
+
|
347
|
+
GetOpenFile(io, fptr);
|
348
|
+
rb_io_check_writable(fptr);
|
349
|
+
out = GetWriteFile(fptr);
|
350
|
+
xmlDocDump(out, xdoc);
|
351
|
+
return(Qtrue);
|
352
|
+
}
|
353
|
+
|
354
|
+
|
355
|
+
/*
|
356
|
+
* call-seq:
|
357
|
+
* document.debug_dump([stream]) -> true
|
358
|
+
*
|
359
|
+
* Debug version of dump.
|
360
|
+
*/
|
361
|
+
VALUE
|
362
|
+
ruby_xml_document_debug_dump(int argc, VALUE *argv, VALUE self) {
|
363
|
+
#ifdef LIBXML_DEBUG_ENABLED
|
364
|
+
OpenFile *fptr;
|
365
|
+
VALUE io;
|
366
|
+
FILE *out;
|
367
|
+
xmlDocPtr xdoc;
|
368
|
+
|
369
|
+
Data_Get_Struct(self, xmlDoc, xdoc);
|
370
|
+
if (xdoc == NULL)
|
371
|
+
return(Qnil);
|
372
|
+
|
373
|
+
switch (argc) {
|
374
|
+
case 0:
|
375
|
+
io = rb_stderr;
|
376
|
+
break;
|
377
|
+
case 1:
|
378
|
+
io = argv[0];
|
379
|
+
if (!rb_obj_is_kind_of(io, rb_cIO))
|
380
|
+
rb_raise(rb_eTypeError, "need an IO object");
|
381
|
+
break;
|
382
|
+
default:
|
383
|
+
rb_raise(rb_eArgError, "wrong number of arguments (0 or 1)");
|
384
|
+
}
|
385
|
+
|
386
|
+
GetOpenFile(io, fptr);
|
387
|
+
rb_io_check_writable(fptr);
|
388
|
+
out = GetWriteFile(fptr);
|
389
|
+
xmlDebugDumpDocument(out, xdoc);
|
390
|
+
return(Qtrue);
|
391
|
+
#else
|
392
|
+
rb_warn("libxml was compiled without debugging support. Please recompile libxml and ruby-libxml");
|
393
|
+
return(Qfalse);
|
394
|
+
#endif
|
395
|
+
}
|
396
|
+
|
397
|
+
|
398
|
+
/*
|
399
|
+
* call-seq:
|
400
|
+
* document.debug_dump_head([stream]) -> true
|
401
|
+
*
|
402
|
+
* Debug-dump this document's header to the specified IO stream.
|
403
|
+
* If no stream is specified, stdout is used.
|
404
|
+
*/
|
405
|
+
VALUE
|
406
|
+
ruby_xml_document_debug_dump_head(int argc, VALUE *argv, VALUE self) {
|
407
|
+
#ifdef LIBXML_DEBUG_ENABLED
|
408
|
+
OpenFile *fptr;
|
409
|
+
VALUE io;
|
410
|
+
FILE *out;
|
411
|
+
xmlDocPtr xdoc;
|
412
|
+
|
413
|
+
|
414
|
+
Data_Get_Struct(self, xmlDoc, xdoc);
|
415
|
+
if (xdoc == NULL)
|
416
|
+
return(Qnil);
|
417
|
+
|
418
|
+
switch (argc) {
|
419
|
+
case 0:
|
420
|
+
io = rb_stdout;
|
421
|
+
break;
|
422
|
+
case 1:
|
423
|
+
io = argv[0];
|
424
|
+
if (!rb_obj_is_kind_of(io, rb_cIO))
|
425
|
+
rb_raise(rb_eTypeError, "need an IO object");
|
426
|
+
break;
|
427
|
+
default:
|
428
|
+
rb_raise(rb_eArgError, "wrong number of arguments (0 or 1)");
|
429
|
+
}
|
430
|
+
|
431
|
+
GetOpenFile(io, fptr);
|
432
|
+
rb_io_check_writable(fptr);
|
433
|
+
out = GetWriteFile(fptr);
|
434
|
+
xmlDebugDumpDocumentHead(out, xdoc);
|
435
|
+
return(Qtrue);
|
436
|
+
#else
|
437
|
+
rb_warn("libxml was compiled without debugging support. Please recompile libxml and ruby-libxml");
|
438
|
+
return(Qfalse);
|
439
|
+
#endif
|
440
|
+
}
|
441
|
+
|
442
|
+
|
443
|
+
/*
|
444
|
+
* call-seq:
|
445
|
+
* document.format_dump([stream], [spacing]) -> true
|
446
|
+
*
|
447
|
+
* Dump this document's formatted XML to the specified IO stream.
|
448
|
+
* If no stream is specified, stdout is used. If spacing is
|
449
|
+
* specified, it must be a boolean that determines whether
|
450
|
+
* spacing is used.
|
451
|
+
*/
|
452
|
+
VALUE
|
453
|
+
ruby_xml_document_format_dump(int argc, VALUE *argv, VALUE self) {
|
454
|
+
OpenFile *fptr;
|
455
|
+
VALUE bool, io;
|
456
|
+
FILE *out;
|
457
|
+
xmlDocPtr xdoc;
|
458
|
+
|
459
|
+
int size, spacing;
|
460
|
+
|
461
|
+
Data_Get_Struct(self, xmlDoc, xdoc);
|
462
|
+
if (xdoc == NULL)
|
463
|
+
return(Qnil);
|
464
|
+
|
465
|
+
switch (argc) {
|
466
|
+
case 0:
|
467
|
+
io = rb_stdout;
|
468
|
+
spacing = 1;
|
469
|
+
break;
|
470
|
+
case 1:
|
471
|
+
io = argv[0];
|
472
|
+
if (!rb_obj_is_kind_of(io, rb_cIO))
|
473
|
+
rb_raise(rb_eTypeError, "need an IO object");
|
474
|
+
spacing = 1;
|
475
|
+
break;
|
476
|
+
case 2:
|
477
|
+
io = argv[0];
|
478
|
+
if (!rb_obj_is_kind_of(io, rb_cIO))
|
479
|
+
rb_raise(rb_eTypeError, "need an IO object");
|
480
|
+
bool = argv[1];
|
481
|
+
if (TYPE(bool) == T_TRUE)
|
482
|
+
spacing = 1;
|
483
|
+
else if (TYPE(bool) == T_FALSE)
|
484
|
+
spacing = 0;
|
485
|
+
else
|
486
|
+
rb_raise(rb_eTypeError, "incorect argument type, second argument must be bool");
|
487
|
+
|
488
|
+
break;
|
489
|
+
default:
|
490
|
+
rb_raise(rb_eArgError, "wrong number of arguments (0 or 1)");
|
491
|
+
}
|
492
|
+
|
493
|
+
GetOpenFile(io, fptr);
|
494
|
+
rb_io_check_writable(fptr);
|
495
|
+
out = GetWriteFile(fptr);
|
496
|
+
size = xmlDocFormatDump(out, xdoc, spacing);
|
497
|
+
return(INT2NUM(size));
|
498
|
+
}
|
499
|
+
|
500
|
+
|
501
|
+
/*
|
502
|
+
* call-seq:
|
503
|
+
* document.debug_format_dump([stream]) -> true
|
504
|
+
*
|
505
|
+
* *Deprecated* in favour of format_dump.
|
506
|
+
*/
|
507
|
+
VALUE
|
508
|
+
ruby_xml_document_debug_format_dump(int argc, VALUE *argv, VALUE self) {
|
509
|
+
rb_warn("debug_format_dump has been deprecaited, use format_dump instead");
|
510
|
+
return(ruby_xml_document_format_dump(argc, argv, self));
|
511
|
+
}
|
512
|
+
|
513
|
+
|
514
|
+
/*
|
515
|
+
* call-seq:
|
516
|
+
* document.encoding -> "encoding"
|
517
|
+
*
|
518
|
+
* Obtain the encoding specified by this document.
|
519
|
+
*/
|
520
|
+
VALUE
|
521
|
+
ruby_xml_document_encoding_get(VALUE self) {
|
522
|
+
xmlDocPtr xdoc;
|
523
|
+
|
524
|
+
Data_Get_Struct(self, xmlDoc, xdoc);
|
525
|
+
if (xdoc->encoding == NULL)
|
526
|
+
return(Qnil);
|
527
|
+
else
|
528
|
+
return(rb_str_new2((const char*)xdoc->encoding));
|
529
|
+
}
|
530
|
+
|
531
|
+
|
532
|
+
/*
|
533
|
+
* call-seq:
|
534
|
+
* document.encoding = "encoding"
|
535
|
+
*
|
536
|
+
* Set the encoding for this document.
|
537
|
+
*/
|
538
|
+
VALUE
|
539
|
+
ruby_xml_document_encoding_set(VALUE self, VALUE encoding) {
|
540
|
+
xmlDocPtr xdoc;
|
541
|
+
|
542
|
+
|
543
|
+
Check_Type(encoding, T_STRING);
|
544
|
+
Data_Get_Struct(self, xmlDoc, xdoc);
|
545
|
+
xdoc->encoding = xmlStrdup(StringValuePtr(encoding));
|
546
|
+
return(ruby_xml_document_encoding_get(self));
|
547
|
+
}
|
548
|
+
|
549
|
+
/*
|
550
|
+
* call-seq:
|
551
|
+
* document.last -> node
|
552
|
+
*
|
553
|
+
* Obtain the last node.
|
554
|
+
*/
|
555
|
+
VALUE
|
556
|
+
ruby_xml_document_last_get(VALUE self) {
|
557
|
+
xmlDocPtr xdoc;
|
558
|
+
|
559
|
+
|
560
|
+
Data_Get_Struct(self, xmlDoc, xdoc);
|
561
|
+
|
562
|
+
if (xdoc->last == NULL)
|
563
|
+
return(Qnil);
|
564
|
+
|
565
|
+
return ruby_xml_node2_wrap(cXMLNode, xdoc->last);
|
566
|
+
}
|
567
|
+
|
568
|
+
|
569
|
+
/*
|
570
|
+
* call-seq:
|
571
|
+
* document.last? -> (true|false)
|
572
|
+
*
|
573
|
+
* Determine whether there is a last node.
|
574
|
+
*/
|
575
|
+
VALUE
|
576
|
+
ruby_xml_document_last_q(VALUE self) {
|
577
|
+
xmlDocPtr xdoc;
|
578
|
+
|
579
|
+
Data_Get_Struct(self, xmlDoc, xdoc);
|
580
|
+
|
581
|
+
if (xdoc->last == NULL)
|
582
|
+
return(Qfalse);
|
583
|
+
else
|
584
|
+
return(Qtrue);
|
585
|
+
}
|
586
|
+
|
587
|
+
|
588
|
+
/*
|
589
|
+
* call-seq:
|
590
|
+
* document.next -> node
|
591
|
+
*
|
592
|
+
* Obtain the next node.
|
593
|
+
*/
|
594
|
+
VALUE
|
595
|
+
ruby_xml_document_next_get(VALUE self) {
|
596
|
+
xmlDocPtr xdoc;
|
597
|
+
|
598
|
+
|
599
|
+
Data_Get_Struct(self, xmlDoc, xdoc);
|
600
|
+
|
601
|
+
if (xdoc->next == NULL)
|
602
|
+
return(Qnil);
|
603
|
+
|
604
|
+
return ruby_xml_node2_wrap(cXMLNode, xdoc->next);
|
605
|
+
}
|
606
|
+
|
607
|
+
|
608
|
+
/*
|
609
|
+
* call-seq:
|
610
|
+
* document.next? -> (true|false)
|
611
|
+
*
|
612
|
+
* Determine whether there is a next node.
|
613
|
+
*/
|
614
|
+
VALUE
|
615
|
+
ruby_xml_document_next_q(VALUE self) {
|
616
|
+
xmlDocPtr xdoc;
|
617
|
+
|
618
|
+
Data_Get_Struct(self, xmlDoc, xdoc);
|
619
|
+
|
620
|
+
if (xdoc->next == NULL)
|
621
|
+
return(Qfalse);
|
622
|
+
else
|
623
|
+
return(Qtrue);
|
624
|
+
}
|
625
|
+
|
626
|
+
|
627
|
+
/*
|
628
|
+
* call-seq:
|
629
|
+
* document.parent -> node
|
630
|
+
*
|
631
|
+
* Obtain the parent node.
|
632
|
+
*/
|
633
|
+
VALUE
|
634
|
+
ruby_xml_document_parent_get(VALUE self) {
|
635
|
+
xmlDocPtr xdoc;
|
636
|
+
|
637
|
+
|
638
|
+
Data_Get_Struct(self, xmlDoc, xdoc);
|
639
|
+
|
640
|
+
if (xdoc->parent == NULL)
|
641
|
+
return(Qnil);
|
642
|
+
|
643
|
+
return ruby_xml_node2_wrap(cXMLNode, xdoc->parent);
|
644
|
+
}
|
645
|
+
|
646
|
+
|
647
|
+
/*
|
648
|
+
* call-seq:
|
649
|
+
* document.parent? -> (true|false)
|
650
|
+
*
|
651
|
+
* Determine whether there is a parent node.
|
652
|
+
*/
|
653
|
+
VALUE
|
654
|
+
ruby_xml_document_parent_q(VALUE self) {
|
655
|
+
xmlDocPtr xdoc;
|
656
|
+
|
657
|
+
Data_Get_Struct(self, xmlDoc, xdoc);
|
658
|
+
|
659
|
+
if (xdoc->parent == NULL)
|
660
|
+
return(Qfalse);
|
661
|
+
else
|
662
|
+
return(Qtrue);
|
663
|
+
}
|
664
|
+
|
665
|
+
|
666
|
+
/*
|
667
|
+
* call-seq:
|
668
|
+
* document.prev -> node
|
669
|
+
*
|
670
|
+
* Obtain the previous node.
|
671
|
+
*/
|
672
|
+
VALUE
|
673
|
+
ruby_xml_document_prev_get(VALUE self) {
|
674
|
+
xmlDocPtr xdoc;
|
675
|
+
|
676
|
+
|
677
|
+
Data_Get_Struct(self, xmlDoc, xdoc);
|
678
|
+
|
679
|
+
if (xdoc->prev == NULL)
|
680
|
+
return(Qnil);
|
681
|
+
|
682
|
+
return ruby_xml_node2_wrap(cXMLNode, xdoc->prev);
|
683
|
+
}
|
684
|
+
|
685
|
+
|
686
|
+
/*
|
687
|
+
* call-seq:
|
688
|
+
* document.prev? -> (true|false)
|
689
|
+
*
|
690
|
+
* Determine whether there is a previous node.
|
691
|
+
*/
|
692
|
+
VALUE
|
693
|
+
ruby_xml_document_prev_q(VALUE self) {
|
694
|
+
xmlDocPtr xdoc;
|
695
|
+
|
696
|
+
Data_Get_Struct(self, xmlDoc, xdoc);
|
697
|
+
|
698
|
+
if (xdoc->prev == NULL)
|
699
|
+
return(Qfalse);
|
700
|
+
else
|
701
|
+
return(Qtrue);
|
702
|
+
}
|
703
|
+
|
704
|
+
|
705
|
+
/*
|
706
|
+
* call-seq:
|
707
|
+
* document.root -> node
|
708
|
+
*
|
709
|
+
* Obtain the root node.
|
710
|
+
*/
|
711
|
+
VALUE
|
712
|
+
ruby_xml_document_root_get(VALUE self) {
|
713
|
+
xmlDocPtr xdoc;
|
714
|
+
|
715
|
+
xmlNodePtr root;
|
716
|
+
|
717
|
+
Data_Get_Struct(self, xmlDoc, xdoc);
|
718
|
+
root = xmlDocGetRootElement(xdoc);
|
719
|
+
|
720
|
+
if (root == NULL)
|
721
|
+
return(Qnil);
|
722
|
+
|
723
|
+
return ruby_xml_node2_wrap(cXMLNode, root);
|
724
|
+
}
|
725
|
+
|
726
|
+
|
727
|
+
/*
|
728
|
+
* call-seq:
|
729
|
+
* document.root = node
|
730
|
+
*
|
731
|
+
* Set the root node.
|
732
|
+
*/
|
733
|
+
VALUE
|
734
|
+
ruby_xml_document_root_set(VALUE self, VALUE node) {
|
735
|
+
xmlDocPtr xdoc;
|
736
|
+
xmlNodePtr xroot, xnode;
|
737
|
+
|
738
|
+
if (rb_obj_is_kind_of(node, cXMLNode) == Qfalse)
|
739
|
+
rb_raise(rb_eTypeError, "must pass an XML::Node type object");
|
740
|
+
|
741
|
+
Data_Get_Struct(self, xmlDoc, xdoc);
|
742
|
+
Data_Get_Struct(node, xmlNode, xnode);
|
743
|
+
xroot = xmlDocSetRootElement(xdoc, xnode);
|
744
|
+
if (xroot == NULL)
|
745
|
+
return(Qnil);
|
746
|
+
|
747
|
+
return ruby_xml_node2_wrap(cXMLNode, xroot);
|
748
|
+
}
|
749
|
+
|
750
|
+
|
751
|
+
/*
|
752
|
+
* call-seq:
|
753
|
+
* document.save(filename, format = false) -> int
|
754
|
+
*
|
755
|
+
* Save this document to the file given by filename,
|
756
|
+
* optionally formatting the output.
|
757
|
+
|
758
|
+
* Parameters:
|
759
|
+
* filename: The filename or URL of the new document
|
760
|
+
* format: Specifies whether formatting spaces should be added.
|
761
|
+
* returns: The number of bytes written or -1 in case of error.
|
762
|
+
*/
|
763
|
+
VALUE
|
764
|
+
ruby_xml_document_save(int argc, VALUE *argv, VALUE self) {
|
765
|
+
xmlDocPtr xdoc;
|
766
|
+
|
767
|
+
const char *filename;
|
768
|
+
int format = 0;
|
769
|
+
int len;
|
770
|
+
|
771
|
+
if (argc <1 || argc > 2)
|
772
|
+
rb_raise(rb_eArgError, "wrong number of arguments (need 1 or 2)");
|
773
|
+
|
774
|
+
Check_Type(argv[0], T_STRING);
|
775
|
+
filename = StringValuePtr(argv[0]);
|
776
|
+
|
777
|
+
if (argc == 2)
|
778
|
+
{
|
779
|
+
switch (TYPE(argv[1])) {
|
780
|
+
case T_TRUE:
|
781
|
+
format = 1;
|
782
|
+
break;
|
783
|
+
case T_FALSE:
|
784
|
+
format = 0;
|
785
|
+
break;
|
786
|
+
default:
|
787
|
+
rb_raise(rb_eArgError, "The second parameter (format) must be true or false");
|
788
|
+
}
|
789
|
+
}
|
790
|
+
|
791
|
+
Data_Get_Struct(self, xmlDoc, xdoc);
|
792
|
+
len = xmlSaveFormatFileEnc(filename, xdoc, (const char*)xdoc->encoding, format);
|
793
|
+
|
794
|
+
if (len == -1)
|
795
|
+
rb_raise(rb_eIOError, "Could not write document");
|
796
|
+
else
|
797
|
+
return(INT2NUM(len));
|
798
|
+
}
|
799
|
+
|
800
|
+
|
801
|
+
/*
|
802
|
+
* call-seq:
|
803
|
+
* document.standalone? -> (true|false)
|
804
|
+
*
|
805
|
+
* Determine whether this is a standalone document.
|
806
|
+
*/
|
807
|
+
VALUE
|
808
|
+
ruby_xml_document_standalone_q(VALUE self) {
|
809
|
+
xmlDocPtr xdoc;
|
810
|
+
|
811
|
+
Data_Get_Struct(self, xmlDoc, xdoc);
|
812
|
+
if (xdoc->standalone)
|
813
|
+
return(Qtrue);
|
814
|
+
else
|
815
|
+
return(Qfalse);
|
816
|
+
}
|
817
|
+
|
818
|
+
|
819
|
+
/*
|
820
|
+
* call-seq:
|
821
|
+
* document.to_s({format=true,encoding) -> "xml"
|
822
|
+
*
|
823
|
+
* Coerce this document to a string representation
|
824
|
+
* of it's XML. The default is to pretty format, but this
|
825
|
+
* depends Parser#indent_tree_output==true or
|
826
|
+
* Parser#default_keep_blanks==false.
|
827
|
+
*
|
828
|
+
* The encoding is not applied to the document, but is
|
829
|
+
* encoding target of the resulting string.
|
830
|
+
*/
|
831
|
+
VALUE
|
832
|
+
ruby_xml_document_to_s(int argc, VALUE *argv, VALUE self) {
|
833
|
+
xmlDocPtr xdoc;
|
834
|
+
|
835
|
+
xmlChar *result, *encoding=NULL;
|
836
|
+
int format, len;
|
837
|
+
VALUE rresult;
|
838
|
+
|
839
|
+
switch (argc) {
|
840
|
+
case 0:
|
841
|
+
format = 1;
|
842
|
+
break;
|
843
|
+
case 2:
|
844
|
+
if (TYPE(argv[1]) == T_STRING)
|
845
|
+
encoding=(xmlChar *)StringValuePtr(argv[1]);
|
846
|
+
case 1:
|
847
|
+
if (TYPE(argv[0]) == T_TRUE)
|
848
|
+
format = 1;
|
849
|
+
else if (TYPE(argv[0]) == T_FALSE)
|
850
|
+
format = 0;
|
851
|
+
else
|
852
|
+
rb_raise(rb_eTypeError, "wrong type of argument, must be bool");
|
853
|
+
break;
|
854
|
+
default:
|
855
|
+
rb_raise(rb_eArgError, "wrong number of arguments (0 or 1)");
|
856
|
+
}
|
857
|
+
|
858
|
+
Data_Get_Struct(self, xmlDoc, xdoc);
|
859
|
+
if (xdoc == NULL) {
|
860
|
+
return(Qnil);
|
861
|
+
} else if (encoding != NULL) {
|
862
|
+
if (format) {
|
863
|
+
xmlDocDumpFormatMemoryEnc(xdoc, &result, &len,
|
864
|
+
(const char*)encoding, format);
|
865
|
+
} else {
|
866
|
+
xmlDocDumpMemoryEnc(xdoc, &result, &len,
|
867
|
+
(const char *)encoding);
|
868
|
+
}
|
869
|
+
} else {
|
870
|
+
if (format)
|
871
|
+
xmlDocDumpFormatMemory(xdoc, &result, &len, format);
|
872
|
+
else
|
873
|
+
xmlDocDumpMemory(xdoc, &result, &len);
|
874
|
+
}
|
875
|
+
rresult=rb_str_new((const char*)result,len);
|
876
|
+
xmlFree(result);
|
877
|
+
return rresult;
|
878
|
+
}
|
879
|
+
|
880
|
+
|
881
|
+
/*
|
882
|
+
* call-seq:
|
883
|
+
* document.url -> "url"
|
884
|
+
*
|
885
|
+
* Obtain this document's source URL, if any.
|
886
|
+
*/
|
887
|
+
VALUE
|
888
|
+
ruby_xml_document_url_get(VALUE self) {
|
889
|
+
xmlDocPtr xdoc;
|
890
|
+
|
891
|
+
Data_Get_Struct(self, xmlDoc, xdoc);
|
892
|
+
if (xdoc->URL == NULL)
|
893
|
+
return(Qnil);
|
894
|
+
else
|
895
|
+
return(rb_str_new2((const char*)xdoc->URL));
|
896
|
+
}
|
897
|
+
|
898
|
+
|
899
|
+
/*
|
900
|
+
* call-seq:
|
901
|
+
* document.version -> "version"
|
902
|
+
*
|
903
|
+
* Obtain the XML version specified by this document.
|
904
|
+
*/
|
905
|
+
VALUE
|
906
|
+
ruby_xml_document_version_get(VALUE self) {
|
907
|
+
xmlDocPtr xdoc;
|
908
|
+
|
909
|
+
Data_Get_Struct(self, xmlDoc, xdoc);
|
910
|
+
if (xdoc->version == NULL)
|
911
|
+
return(Qnil);
|
912
|
+
else
|
913
|
+
return(rb_str_new2((const char*)xdoc->version));
|
914
|
+
}
|
915
|
+
|
916
|
+
|
917
|
+
/*
|
918
|
+
* call-seq:
|
919
|
+
* document.xinclude -> num
|
920
|
+
*
|
921
|
+
* Process xinclude directives in this document.
|
922
|
+
*/
|
923
|
+
VALUE
|
924
|
+
ruby_xml_document_xinclude(VALUE self) {
|
925
|
+
#ifdef LIBXML_XINCLUDE_ENABLED
|
926
|
+
xmlDocPtr xdoc;
|
927
|
+
|
928
|
+
int ret;
|
929
|
+
|
930
|
+
Data_Get_Struct(self, xmlDoc, xdoc);
|
931
|
+
ret = xmlXIncludeProcess(xdoc);
|
932
|
+
if (ret >= 0)
|
933
|
+
{
|
934
|
+
return(INT2NUM(ret));
|
935
|
+
}
|
936
|
+
else
|
937
|
+
{
|
938
|
+
ruby_xml_raise(&xmlLastError);
|
939
|
+
return Qnil;
|
940
|
+
}
|
941
|
+
#else
|
942
|
+
rb_warn("libxml was compiled without XInclude support. Please recompile libxml and ruby-libxml");
|
943
|
+
return(Qfalse);
|
944
|
+
#endif
|
945
|
+
}
|
946
|
+
|
947
|
+
void
|
948
|
+
LibXML_validity_error(void * ctxt, const char * msg, va_list ap)
|
949
|
+
{
|
950
|
+
if (rb_block_given_p()) {
|
951
|
+
char buff[1024];
|
952
|
+
snprintf(buff, 1024, msg, ap);
|
953
|
+
rb_yield(rb_ary_new3(2, rb_str_new2(buff), Qtrue));
|
954
|
+
} else {
|
955
|
+
fprintf(stderr, "error -- found validity error: ");
|
956
|
+
fprintf(stderr, msg, ap);
|
957
|
+
}
|
958
|
+
}
|
959
|
+
|
960
|
+
void
|
961
|
+
LibXML_validity_warning(void * ctxt, const char * msg, va_list ap)
|
962
|
+
{
|
963
|
+
if (rb_block_given_p()) {
|
964
|
+
char buff[1024];
|
965
|
+
snprintf(buff, 1024, msg, ap);
|
966
|
+
rb_yield(rb_ary_new3(2, rb_str_new2(buff), Qfalse));
|
967
|
+
} else {
|
968
|
+
fprintf(stderr, "warning -- found validity error: ");
|
969
|
+
fprintf(stderr, msg, ap);
|
970
|
+
}
|
971
|
+
}
|
972
|
+
|
973
|
+
/*
|
974
|
+
* call-seq:
|
975
|
+
* document.validate_schema(schema) -> (true|false)
|
976
|
+
*
|
977
|
+
* Validate this document against the specified XML::Schema.
|
978
|
+
*
|
979
|
+
* If a block is provided it is used as an error handler for validaten errors.
|
980
|
+
* The block is called with two argument, the message and a flag indication
|
981
|
+
* if the message is an error (true) or a warning (false).
|
982
|
+
*/
|
983
|
+
VALUE
|
984
|
+
ruby_xml_document_validate_schema(VALUE self, VALUE schema) {
|
985
|
+
xmlSchemaValidCtxtPtr vptr;
|
986
|
+
xmlDocPtr xdoc;
|
987
|
+
ruby_xml_schema *c_schema;
|
988
|
+
int is_invalid;
|
989
|
+
|
990
|
+
Data_Get_Struct(self, xmlDoc, xdoc);
|
991
|
+
Data_Get_Struct(schema, ruby_xml_schema, c_schema);
|
992
|
+
|
993
|
+
vptr = xmlSchemaNewValidCtxt(c_schema->schema);
|
994
|
+
|
995
|
+
xmlSchemaSetValidErrors(vptr, (xmlSchemaValidityErrorFunc)LibXML_validity_error,
|
996
|
+
(xmlSchemaValidityWarningFunc)LibXML_validity_warning, NULL);
|
997
|
+
|
998
|
+
is_invalid = xmlSchemaValidateDoc(vptr, xdoc);
|
999
|
+
xmlSchemaFreeValidCtxt(vptr);
|
1000
|
+
if (is_invalid)
|
1001
|
+
{
|
1002
|
+
ruby_xml_raise(&xmlLastError);
|
1003
|
+
return Qfalse;
|
1004
|
+
} else
|
1005
|
+
{
|
1006
|
+
return Qtrue;
|
1007
|
+
}
|
1008
|
+
}
|
1009
|
+
|
1010
|
+
/*
|
1011
|
+
* call-seq:
|
1012
|
+
* document.validate_schema(relaxng) -> (true|false)
|
1013
|
+
*
|
1014
|
+
* Validate this document against the specified XML::RelaxNG.
|
1015
|
+
*
|
1016
|
+
* If a block is provided it is used as an error handler for validaten errors.
|
1017
|
+
* The block is called with two argument, the message and a flag indication
|
1018
|
+
* if the message is an error (true) or a warning (false).
|
1019
|
+
*/
|
1020
|
+
VALUE
|
1021
|
+
ruby_xml_document_validate_relaxng(VALUE self, VALUE relaxng) {
|
1022
|
+
xmlRelaxNGValidCtxtPtr vptr;
|
1023
|
+
xmlDocPtr xdoc;
|
1024
|
+
ruby_xml_relaxng *c_relaxng;
|
1025
|
+
int is_invalid;
|
1026
|
+
|
1027
|
+
Data_Get_Struct(self, xmlDoc, xdoc);
|
1028
|
+
Data_Get_Struct(relaxng, ruby_xml_relaxng, c_relaxng);
|
1029
|
+
|
1030
|
+
vptr = xmlRelaxNGNewValidCtxt(c_relaxng->relaxng);
|
1031
|
+
|
1032
|
+
xmlRelaxNGSetValidErrors(vptr, (xmlRelaxNGValidityErrorFunc)LibXML_validity_error,
|
1033
|
+
(xmlRelaxNGValidityWarningFunc)LibXML_validity_warning, NULL);
|
1034
|
+
|
1035
|
+
is_invalid = xmlRelaxNGValidateDoc(vptr, xdoc);
|
1036
|
+
xmlRelaxNGFreeValidCtxt(vptr);
|
1037
|
+
if (is_invalid)
|
1038
|
+
{
|
1039
|
+
ruby_xml_raise(&xmlLastError);
|
1040
|
+
return Qfalse;
|
1041
|
+
} else
|
1042
|
+
{
|
1043
|
+
return Qtrue;
|
1044
|
+
}
|
1045
|
+
}
|
1046
|
+
|
1047
|
+
|
1048
|
+
/*
|
1049
|
+
* call-seq:
|
1050
|
+
* document.validate(dtd) -> (true|false)
|
1051
|
+
*
|
1052
|
+
* Validate this document against the specified XML::DTD.
|
1053
|
+
*/
|
1054
|
+
VALUE
|
1055
|
+
ruby_xml_document_validate_dtd(VALUE self, VALUE dtd) {
|
1056
|
+
VALUE error = Qnil;
|
1057
|
+
xmlValidCtxt ctxt;
|
1058
|
+
xmlDocPtr xdoc;
|
1059
|
+
ruby_xml_dtd *c_dtd;
|
1060
|
+
|
1061
|
+
Data_Get_Struct(self, xmlDoc, xdoc);
|
1062
|
+
Data_Get_Struct(dtd, ruby_xml_dtd, c_dtd);
|
1063
|
+
|
1064
|
+
ctxt.userData = &error;
|
1065
|
+
ctxt.error = (xmlValidityErrorFunc)LibXML_validity_error;
|
1066
|
+
ctxt.warning = (xmlValidityWarningFunc)LibXML_validity_warning;
|
1067
|
+
|
1068
|
+
ctxt.nodeNr = 0;
|
1069
|
+
ctxt.nodeTab = NULL;
|
1070
|
+
ctxt.vstateNr = 0;
|
1071
|
+
ctxt.vstateTab = NULL;
|
1072
|
+
|
1073
|
+
if (xmlValidateDtd(&ctxt, xdoc, c_dtd->dtd))
|
1074
|
+
{
|
1075
|
+
return(Qtrue);
|
1076
|
+
}
|
1077
|
+
else
|
1078
|
+
{
|
1079
|
+
ruby_xml_raise(&xmlLastError);
|
1080
|
+
return Qfalse;
|
1081
|
+
}
|
1082
|
+
}
|
1083
|
+
|
1084
|
+
|
1085
|
+
/*
|
1086
|
+
* call-seq:
|
1087
|
+
* document.reader -> reader
|
1088
|
+
*
|
1089
|
+
* Create a XML::Reader from the document. This is a shortcut to
|
1090
|
+
* XML::Reader.walker().
|
1091
|
+
*/
|
1092
|
+
static VALUE
|
1093
|
+
ruby_xml_document_reader(VALUE self)
|
1094
|
+
{
|
1095
|
+
return ruby_xml_reader_new_walker(cXMLReader, self);
|
1096
|
+
}
|
1097
|
+
|
1098
|
+
// Rdoc needs to know
|
1099
|
+
#ifdef RDOC_NEVER_DEFINED
|
1100
|
+
mLibXML = rb_define_module("LibXML");
|
1101
|
+
mXML = rb_define_module_under(mLibXML, "XML");
|
1102
|
+
#endif
|
1103
|
+
|
1104
|
+
void
|
1105
|
+
ruby_init_xml_document(void) {
|
1106
|
+
ref_count_table = st_init_numtable();
|
1107
|
+
|
1108
|
+
cXMLDocument = rb_define_class_under(mXML, "Document", rb_cObject);
|
1109
|
+
rb_define_alloc_func(cXMLDocument, ruby_xml_document_alloc);
|
1110
|
+
|
1111
|
+
rb_define_method(cXMLDocument, "initialize", ruby_xml_document_initialize, -1);
|
1112
|
+
rb_define_method(cXMLDocument, "child", ruby_xml_document_child_get, 0);
|
1113
|
+
rb_define_method(cXMLDocument, "child?", ruby_xml_document_child_q, 0);
|
1114
|
+
rb_define_method(cXMLDocument, "compression", ruby_xml_document_compression_get, 0);
|
1115
|
+
rb_define_method(cXMLDocument, "compression=", ruby_xml_document_compression_set, 1);
|
1116
|
+
rb_define_method(cXMLDocument, "compression?", ruby_xml_document_compression_q, 0);
|
1117
|
+
rb_define_method(cXMLDocument, "dump", ruby_xml_document_dump, -1);
|
1118
|
+
rb_define_method(cXMLDocument, "debug_dump", ruby_xml_document_debug_dump, -1);
|
1119
|
+
rb_define_method(cXMLDocument, "debug_dump_head", ruby_xml_document_debug_dump_head, -1);
|
1120
|
+
rb_define_method(cXMLDocument, "debug_format_dump", ruby_xml_document_debug_format_dump, -1);
|
1121
|
+
rb_define_method(cXMLDocument, "encoding", ruby_xml_document_encoding_get, 0);
|
1122
|
+
rb_define_method(cXMLDocument, "encoding=", ruby_xml_document_encoding_set, 1);
|
1123
|
+
rb_define_method(cXMLDocument, "format_dump", ruby_xml_document_format_dump, -1);
|
1124
|
+
rb_define_method(cXMLDocument, "last", ruby_xml_document_last_get, 0);
|
1125
|
+
rb_define_method(cXMLDocument, "last?", ruby_xml_document_last_q, 0);
|
1126
|
+
rb_define_method(cXMLDocument, "next", ruby_xml_document_next_get, 0);
|
1127
|
+
rb_define_method(cXMLDocument, "next?", ruby_xml_document_next_q, 0);
|
1128
|
+
rb_define_method(cXMLDocument, "parent", ruby_xml_document_parent_get, 0);
|
1129
|
+
rb_define_method(cXMLDocument, "parent?", ruby_xml_document_parent_q, 0);
|
1130
|
+
rb_define_method(cXMLDocument, "prev", ruby_xml_document_prev_get, 0);
|
1131
|
+
rb_define_method(cXMLDocument, "prev?", ruby_xml_document_prev_q, 0);
|
1132
|
+
rb_define_method(cXMLDocument, "root", ruby_xml_document_root_get, 0);
|
1133
|
+
rb_define_method(cXMLDocument, "root=", ruby_xml_document_root_set, 1);
|
1134
|
+
rb_define_method(cXMLDocument, "save", ruby_xml_document_save, -1);
|
1135
|
+
rb_define_method(cXMLDocument, "standalone?", ruby_xml_document_standalone_q, 0);
|
1136
|
+
rb_define_method(cXMLDocument, "to_s", ruby_xml_document_to_s, -1);
|
1137
|
+
rb_define_method(cXMLDocument, "url", ruby_xml_document_url_get, 0);
|
1138
|
+
rb_define_method(cXMLDocument, "version", ruby_xml_document_version_get, 0);
|
1139
|
+
rb_define_method(cXMLDocument, "xinclude", ruby_xml_document_xinclude, 0);
|
1140
|
+
rb_define_method(cXMLDocument, "validate", ruby_xml_document_validate_dtd, 1);
|
1141
|
+
rb_define_method(cXMLDocument, "validate_schema", ruby_xml_document_validate_schema, 1);
|
1142
|
+
rb_define_method(cXMLDocument, "validate_relaxng", ruby_xml_document_validate_relaxng, 1);
|
1143
|
+
rb_define_method(cXMLDocument, "reader", ruby_xml_document_reader, 0);
|
1144
|
+
}
|