libxml-ruby 2.7.0 → 2.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +6 -14
- data/HISTORY +33 -11
- data/README.rdoc +7 -7
- data/Rakefile +80 -77
- data/ext/libxml/extconf.h +4 -5
- data/ext/libxml/extconf.rb +57 -118
- data/ext/libxml/libxml.c +4 -0
- data/ext/libxml/ruby_xml.c +977 -893
- data/ext/libxml/ruby_xml.h +20 -10
- data/ext/libxml/ruby_xml_attr.c +333 -333
- data/ext/libxml/ruby_xml_attr_decl.c +2 -2
- data/ext/libxml/ruby_xml_cbg.c +85 -85
- data/ext/libxml/ruby_xml_document.c +1133 -1147
- data/ext/libxml/ruby_xml_dtd.c +261 -268
- data/ext/libxml/ruby_xml_encoding.c +262 -260
- data/ext/libxml/ruby_xml_encoding.h +19 -19
- data/ext/libxml/ruby_xml_html_parser_context.c +337 -338
- data/ext/libxml/ruby_xml_input_cbg.c +191 -191
- data/ext/libxml/ruby_xml_io.c +52 -50
- data/ext/libxml/ruby_xml_namespace.c +2 -2
- data/ext/libxml/ruby_xml_node.c +1446 -1452
- data/ext/libxml/ruby_xml_parser_context.c +999 -1001
- data/ext/libxml/ruby_xml_reader.c +1226 -1228
- data/ext/libxml/ruby_xml_relaxng.c +110 -111
- data/ext/libxml/ruby_xml_sax2_handler.c +326 -328
- data/ext/libxml/ruby_xml_schema.c +300 -301
- data/ext/libxml/ruby_xml_version.h +3 -3
- data/ext/libxml/ruby_xml_writer.c +34 -16
- data/ext/libxml/ruby_xml_xpath.c +188 -187
- data/ext/libxml/ruby_xml_xpath_context.c +360 -361
- data/ext/libxml/ruby_xml_xpath_object.c +335 -335
- data/libxml-ruby.gemspec +47 -44
- data/test/tc_attr.rb +5 -7
- data/test/tc_attr_decl.rb +5 -6
- data/test/tc_attributes.rb +1 -2
- data/test/tc_canonicalize.rb +1 -2
- data/test/tc_deprecated_require.rb +1 -2
- data/test/tc_document.rb +4 -5
- data/test/tc_document_write.rb +2 -3
- data/test/tc_dtd.rb +4 -5
- data/test/tc_encoding.rb +126 -126
- data/test/tc_encoding_sax.rb +4 -3
- data/test/tc_error.rb +14 -15
- data/test/tc_html_parser.rb +15 -7
- data/test/tc_html_parser_context.rb +1 -2
- data/test/tc_namespace.rb +2 -3
- data/test/tc_namespaces.rb +5 -6
- data/test/tc_node.rb +2 -3
- data/test/tc_node_cdata.rb +2 -3
- data/test/tc_node_comment.rb +1 -2
- data/test/tc_node_copy.rb +1 -2
- data/test/tc_node_edit.rb +5 -7
- data/test/tc_node_pi.rb +1 -2
- data/test/tc_node_text.rb +2 -3
- data/test/tc_node_write.rb +2 -3
- data/test/tc_node_xlink.rb +1 -2
- data/test/tc_parser.rb +18 -24
- data/test/tc_parser_context.rb +6 -7
- data/test/tc_properties.rb +1 -2
- data/test/tc_reader.rb +9 -10
- data/test/tc_relaxng.rb +4 -5
- data/test/tc_sax_parser.rb +9 -10
- data/test/tc_schema.rb +4 -5
- data/test/tc_traversal.rb +1 -2
- data/test/tc_writer.rb +1 -2
- data/test/tc_xinclude.rb +1 -2
- data/test/tc_xml.rb +1 -2
- data/test/tc_xpath.rb +8 -9
- data/test/tc_xpath_context.rb +3 -4
- data/test/tc_xpath_expression.rb +3 -4
- data/test/tc_xpointer.rb +1 -3
- data/test/test_helper.rb +3 -1
- data/test/test_suite.rb +0 -1
- metadata +90 -72
- 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/model/kml_sample.xml +0 -915
- data/test/remove_test.rb +0 -9
- data/test/tc_gc.rb +0 -86
- data/test/tc_parser.rb.orig +0 -384
data/ext/libxml/ruby_xml_node.c
CHANGED
@@ -1,1452 +1,1446 @@
|
|
1
|
-
#include "ruby_libxml.h"
|
2
|
-
#include "ruby_xml_node.h"
|
3
|
-
#include <assert.h>
|
4
|
-
|
5
|
-
VALUE cXMLNode;
|
6
|
-
|
7
|
-
/* Document-class: LibXML::XML::Node
|
8
|
-
*
|
9
|
-
* Nodes are the primary objects that make up an XML document.
|
10
|
-
* The node class represents most node types that are found in
|
11
|
-
* an XML document (but not LibXML::XML::Attributes, see LibXML::XML::Attr).
|
12
|
-
* It exposes libxml's full API for creating, querying
|
13
|
-
* moving and deleting node objects. Many of these methods are
|
14
|
-
* documented in the DOM Level 3 specification found at:
|
15
|
-
* http://www.w3.org/TR/DOM-Level-3-Core/. */
|
16
|
-
|
17
|
-
|
18
|
-
/* Memory management:
|
19
|
-
*
|
20
|
-
* The bindings create a one-to-one mapping between libxml nodes
|
21
|
-
* and Ruby nodes. If a libxml node is
|
22
|
-
*
|
23
|
-
*
|
24
|
-
* When a libxml document or top level node is freed, it will free
|
25
|
-
* all its children. Thus Ruby is responsible for:
|
26
|
-
*
|
27
|
-
* * Using the mark function to keep alive any documents Ruby is
|
28
|
-
* referencing via the document or child nodes.
|
29
|
-
* * Using the mark function to keep alive any top level, free
|
30
|
-
* standing nodes Ruby is referencing via the node or its children.
|
31
|
-
*
|
32
|
-
* In general use, this will cause Ruby nodes to be freed before
|
33
|
-
* a libxml document. When a Ruby node is freed, the
|
34
|
-
*
|
35
|
-
*
|
36
|
-
* In the sweep phase in Ruby 1.9.*, the document tends to be
|
37
|
-
* freed before the nodes. To support this, the bindings register
|
38
|
-
* a callback function with libxml that is called each time a node
|
39
|
-
* is freed. In that case, the data_ptr is set to null, so the bindings
|
40
|
-
* can recognize the situation.
|
41
|
-
*/
|
42
|
-
|
43
|
-
static void rxml_node_deregisterNode(xmlNodePtr xnode)
|
44
|
-
{
|
45
|
-
/* Has the node been wrapped and exposed to Ruby? */
|
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
|
-
or it has been freed by libxml already in Ruby's
|
83
|
-
mark phase. */
|
84
|
-
if (xnode == NULL)
|
85
|
-
return;
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
{
|
101
|
-
result = (
|
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
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
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
|
-
xnode = xmlNewComment(
|
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
|
-
if (NIL_P(
|
208
|
-
{
|
209
|
-
|
210
|
-
}
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
xnode = xmlNewPI((xmlChar*) StringValuePtr(name),
|
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
|
-
if (
|
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
|
-
xtarget
|
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
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
if (
|
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
|
-
|
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
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
case
|
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
|
-
if (
|
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
|
-
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
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
|
-
case
|
867
|
-
return (
|
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
|
-
|
896
|
-
|
897
|
-
|
898
|
-
case
|
899
|
-
{
|
900
|
-
|
901
|
-
name =
|
902
|
-
break;
|
903
|
-
}
|
904
|
-
case
|
905
|
-
{
|
906
|
-
|
907
|
-
name =
|
908
|
-
break;
|
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
|
-
break;
|
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
|
-
|
1112
|
-
|
1113
|
-
|
1114
|
-
|
1115
|
-
|
1116
|
-
|
1117
|
-
|
1118
|
-
|
1119
|
-
|
1120
|
-
|
1121
|
-
|
1122
|
-
|
1123
|
-
|
1124
|
-
|
1125
|
-
|
1126
|
-
|
1127
|
-
|
1128
|
-
|
1129
|
-
|
1130
|
-
|
1131
|
-
|
1132
|
-
|
1133
|
-
|
1134
|
-
|
1135
|
-
|
1136
|
-
|
1137
|
-
|
1138
|
-
|
1139
|
-
|
1140
|
-
|
1141
|
-
|
1142
|
-
|
1143
|
-
|
1144
|
-
|
1145
|
-
|
1146
|
-
|
1147
|
-
|
1148
|
-
|
1149
|
-
xnode
|
1150
|
-
|
1151
|
-
|
1152
|
-
|
1153
|
-
|
1154
|
-
|
1155
|
-
|
1156
|
-
|
1157
|
-
|
1158
|
-
|
1159
|
-
|
1160
|
-
|
1161
|
-
|
1162
|
-
|
1163
|
-
|
1164
|
-
|
1165
|
-
|
1166
|
-
|
1167
|
-
*
|
1168
|
-
*
|
1169
|
-
|
1170
|
-
|
1171
|
-
|
1172
|
-
|
1173
|
-
|
1174
|
-
|
1175
|
-
|
1176
|
-
|
1177
|
-
|
1178
|
-
|
1179
|
-
|
1180
|
-
|
1181
|
-
|
1182
|
-
*
|
1183
|
-
*
|
1184
|
-
*
|
1185
|
-
*
|
1186
|
-
*
|
1187
|
-
*
|
1188
|
-
*
|
1189
|
-
*
|
1190
|
-
*
|
1191
|
-
|
1192
|
-
|
1193
|
-
|
1194
|
-
|
1195
|
-
|
1196
|
-
|
1197
|
-
|
1198
|
-
|
1199
|
-
|
1200
|
-
|
1201
|
-
|
1202
|
-
|
1203
|
-
|
1204
|
-
|
1205
|
-
|
1206
|
-
|
1207
|
-
|
1208
|
-
|
1209
|
-
|
1210
|
-
|
1211
|
-
|
1212
|
-
|
1213
|
-
|
1214
|
-
|
1215
|
-
|
1216
|
-
|
1217
|
-
|
1218
|
-
|
1219
|
-
|
1220
|
-
|
1221
|
-
|
1222
|
-
|
1223
|
-
|
1224
|
-
|
1225
|
-
|
1226
|
-
|
1227
|
-
|
1228
|
-
|
1229
|
-
|
1230
|
-
|
1231
|
-
|
1232
|
-
|
1233
|
-
*
|
1234
|
-
*
|
1235
|
-
*
|
1236
|
-
*
|
1237
|
-
*
|
1238
|
-
|
1239
|
-
|
1240
|
-
|
1241
|
-
|
1242
|
-
|
1243
|
-
|
1244
|
-
|
1245
|
-
|
1246
|
-
|
1247
|
-
|
1248
|
-
|
1249
|
-
|
1250
|
-
|
1251
|
-
|
1252
|
-
|
1253
|
-
|
1254
|
-
|
1255
|
-
|
1256
|
-
|
1257
|
-
|
1258
|
-
|
1259
|
-
|
1260
|
-
|
1261
|
-
|
1262
|
-
|
1263
|
-
|
1264
|
-
|
1265
|
-
|
1266
|
-
|
1267
|
-
|
1268
|
-
|
1269
|
-
|
1270
|
-
|
1271
|
-
|
1272
|
-
|
1273
|
-
|
1274
|
-
|
1275
|
-
|
1276
|
-
|
1277
|
-
|
1278
|
-
|
1279
|
-
|
1280
|
-
|
1281
|
-
|
1282
|
-
|
1283
|
-
|
1284
|
-
|
1285
|
-
|
1286
|
-
|
1287
|
-
|
1288
|
-
|
1289
|
-
|
1290
|
-
|
1291
|
-
|
1292
|
-
|
1293
|
-
|
1294
|
-
|
1295
|
-
|
1296
|
-
|
1297
|
-
|
1298
|
-
|
1299
|
-
|
1300
|
-
|
1301
|
-
|
1302
|
-
|
1303
|
-
|
1304
|
-
|
1305
|
-
|
1306
|
-
|
1307
|
-
|
1308
|
-
|
1309
|
-
|
1310
|
-
|
1311
|
-
|
1312
|
-
|
1313
|
-
|
1314
|
-
|
1315
|
-
|
1316
|
-
|
1317
|
-
|
1318
|
-
*
|
1319
|
-
*
|
1320
|
-
|
1321
|
-
|
1322
|
-
|
1323
|
-
|
1324
|
-
|
1325
|
-
|
1326
|
-
|
1327
|
-
|
1328
|
-
|
1329
|
-
|
1330
|
-
|
1331
|
-
|
1332
|
-
|
1333
|
-
|
1334
|
-
|
1335
|
-
|
1336
|
-
|
1337
|
-
|
1338
|
-
|
1339
|
-
|
1340
|
-
|
1341
|
-
|
1342
|
-
|
1343
|
-
|
1344
|
-
|
1345
|
-
|
1346
|
-
|
1347
|
-
|
1348
|
-
|
1349
|
-
|
1350
|
-
cXMLNode
|
1351
|
-
|
1352
|
-
rb_define_const(cXMLNode, "
|
1353
|
-
rb_define_const(cXMLNode, "
|
1354
|
-
rb_define_const(cXMLNode, "
|
1355
|
-
rb_define_const(cXMLNode, "
|
1356
|
-
rb_define_const(cXMLNode, "
|
1357
|
-
rb_define_const(cXMLNode, "
|
1358
|
-
rb_define_const(cXMLNode, "
|
1359
|
-
rb_define_const(cXMLNode, "
|
1360
|
-
|
1361
|
-
rb_define_const(cXMLNode, "
|
1362
|
-
rb_define_const(cXMLNode, "
|
1363
|
-
rb_define_const(cXMLNode, "
|
1364
|
-
rb_define_const(cXMLNode, "
|
1365
|
-
rb_define_const(cXMLNode, "
|
1366
|
-
|
1367
|
-
rb_define_const(cXMLNode, "
|
1368
|
-
rb_define_const(cXMLNode, "
|
1369
|
-
rb_define_const(cXMLNode, "
|
1370
|
-
rb_define_const(cXMLNode, "
|
1371
|
-
rb_define_const(cXMLNode, "
|
1372
|
-
rb_define_const(cXMLNode, "
|
1373
|
-
rb_define_const(cXMLNode, "
|
1374
|
-
rb_define_const(cXMLNode, "
|
1375
|
-
rb_define_const(cXMLNode, "
|
1376
|
-
rb_define_const(cXMLNode, "
|
1377
|
-
rb_define_const(cXMLNode, "
|
1378
|
-
rb_define_const(cXMLNode, "
|
1379
|
-
rb_define_const(cXMLNode, "
|
1380
|
-
rb_define_const(cXMLNode, "
|
1381
|
-
|
1382
|
-
|
1383
|
-
rb_define_const(cXMLNode, "
|
1384
|
-
|
1385
|
-
rb_define_const(cXMLNode, "
|
1386
|
-
|
1387
|
-
|
1388
|
-
|
1389
|
-
|
1390
|
-
|
1391
|
-
|
1392
|
-
|
1393
|
-
|
1394
|
-
|
1395
|
-
|
1396
|
-
|
1397
|
-
|
1398
|
-
|
1399
|
-
|
1400
|
-
|
1401
|
-
rb_define_method(cXMLNode, "
|
1402
|
-
|
1403
|
-
|
1404
|
-
|
1405
|
-
rb_define_method(cXMLNode, "
|
1406
|
-
|
1407
|
-
|
1408
|
-
rb_define_method(cXMLNode, "
|
1409
|
-
rb_define_method(cXMLNode, "
|
1410
|
-
rb_define_method(cXMLNode, "
|
1411
|
-
rb_define_method(cXMLNode, "
|
1412
|
-
|
1413
|
-
|
1414
|
-
|
1415
|
-
rb_define_method(cXMLNode, "
|
1416
|
-
rb_define_method(cXMLNode, "
|
1417
|
-
rb_define_method(cXMLNode, "
|
1418
|
-
rb_define_method(cXMLNode, "
|
1419
|
-
|
1420
|
-
|
1421
|
-
rb_define_method(cXMLNode, "
|
1422
|
-
rb_define_method(cXMLNode, "
|
1423
|
-
rb_define_method(cXMLNode, "
|
1424
|
-
rb_define_method(cXMLNode, "
|
1425
|
-
rb_define_method(cXMLNode, "
|
1426
|
-
rb_define_method(cXMLNode, "
|
1427
|
-
rb_define_method(cXMLNode, "
|
1428
|
-
rb_define_method(cXMLNode, "
|
1429
|
-
rb_define_method(cXMLNode, "
|
1430
|
-
rb_define_method(cXMLNode, "
|
1431
|
-
rb_define_method(cXMLNode, "
|
1432
|
-
rb_define_method(cXMLNode, "
|
1433
|
-
rb_define_method(cXMLNode, "
|
1434
|
-
rb_define_method(cXMLNode, "
|
1435
|
-
rb_define_method(cXMLNode, "
|
1436
|
-
rb_define_method(cXMLNode, "
|
1437
|
-
rb_define_method(cXMLNode, "
|
1438
|
-
rb_define_method(cXMLNode, "
|
1439
|
-
rb_define_method(cXMLNode, "
|
1440
|
-
rb_define_method(cXMLNode, "
|
1441
|
-
rb_define_method(cXMLNode, "
|
1442
|
-
rb_define_method(cXMLNode, "
|
1443
|
-
rb_define_method(cXMLNode, "
|
1444
|
-
|
1445
|
-
|
1446
|
-
|
1447
|
-
rb_define_method(cXMLNode, "xlink?", rxml_node_xlink_q, 0);
|
1448
|
-
rb_define_method(cXMLNode, "xlink_type", rxml_node_xlink_type, 0);
|
1449
|
-
rb_define_method(cXMLNode, "xlink_type_name", rxml_node_xlink_type_name, 0);
|
1450
|
-
|
1451
|
-
rb_define_alias(cXMLNode, "==", "eql?");
|
1452
|
-
}
|
1
|
+
#include "ruby_libxml.h"
|
2
|
+
#include "ruby_xml_node.h"
|
3
|
+
#include <assert.h>
|
4
|
+
|
5
|
+
VALUE cXMLNode;
|
6
|
+
|
7
|
+
/* Document-class: LibXML::XML::Node
|
8
|
+
*
|
9
|
+
* Nodes are the primary objects that make up an XML document.
|
10
|
+
* The node class represents most node types that are found in
|
11
|
+
* an XML document (but not LibXML::XML::Attributes, see LibXML::XML::Attr).
|
12
|
+
* It exposes libxml's full API for creating, querying
|
13
|
+
* moving and deleting node objects. Many of these methods are
|
14
|
+
* documented in the DOM Level 3 specification found at:
|
15
|
+
* http://www.w3.org/TR/DOM-Level-3-Core/. */
|
16
|
+
|
17
|
+
|
18
|
+
/* Memory management:
|
19
|
+
*
|
20
|
+
* The bindings create a one-to-one mapping between libxml nodes
|
21
|
+
* and Ruby nodes. If a libxml node is wrapped, the mapping is stored in the
|
22
|
+
* private_pointers hashtable.
|
23
|
+
*
|
24
|
+
* When a libxml document or top level node is freed, it will free
|
25
|
+
* all its children. Thus Ruby is responsible for:
|
26
|
+
*
|
27
|
+
* * Using the mark function to keep alive any documents Ruby is
|
28
|
+
* referencing via the document or child nodes.
|
29
|
+
* * Using the mark function to keep alive any top level, free
|
30
|
+
* standing nodes Ruby is referencing via the node or its children.
|
31
|
+
*
|
32
|
+
* In general use, this will cause Ruby nodes to be freed before
|
33
|
+
* a libxml document. When a Ruby node is freed, the hashtable entry is
|
34
|
+
* removed.
|
35
|
+
*
|
36
|
+
* In the sweep phase in Ruby 1.9.*, the document tends to be
|
37
|
+
* freed before the nodes. To support this, the bindings register
|
38
|
+
* a callback function with libxml that is called each time a node
|
39
|
+
* is freed. In that case, the data_ptr is set to null, so the bindings
|
40
|
+
* can recognize the situation.
|
41
|
+
*/
|
42
|
+
|
43
|
+
static void rxml_node_deregisterNode(xmlNodePtr xnode)
|
44
|
+
{
|
45
|
+
/* Has the node been wrapped and exposed to Ruby? */
|
46
|
+
VALUE node = rxml_lookup_node(xnode);
|
47
|
+
if (node == Qnil)
|
48
|
+
return;
|
49
|
+
|
50
|
+
/* Node was wrapped. Disassociate the ruby object from the xml node
|
51
|
+
and turn off the free function so Ruby will not call it when the
|
52
|
+
wrapping object is itself freed. Note we still MUST include
|
53
|
+
the mark function. Unsetting it breaks the Ruby GC. */
|
54
|
+
RDATA(node)->dfree = NULL;
|
55
|
+
RDATA(node)->data = NULL;
|
56
|
+
|
57
|
+
// Remove the hashtable entry
|
58
|
+
rxml_unregister_node(xnode);
|
59
|
+
}
|
60
|
+
|
61
|
+
static void rxml_node_free(xmlNodePtr xnode)
|
62
|
+
{
|
63
|
+
/* The ruby object wrapping the xml object no longer exists. */
|
64
|
+
rxml_unregister_node(xnode);
|
65
|
+
|
66
|
+
/* Ruby is responsible for freeing this node if it does not
|
67
|
+
have a parent and is not owned by a document. Note a corner
|
68
|
+
case here - calling node2 = doc.import(node1) will cause node2
|
69
|
+
to not have a parent but to have a document. */
|
70
|
+
if (xnode->doc == NULL && xnode->parent == NULL)
|
71
|
+
{
|
72
|
+
xmlFreeNode(xnode);
|
73
|
+
}
|
74
|
+
}
|
75
|
+
|
76
|
+
void rxml_node_mark(xmlNodePtr xnode)
|
77
|
+
{
|
78
|
+
VALUE doc = Qnil;
|
79
|
+
VALUE parent = Qnil;
|
80
|
+
|
81
|
+
/* Either the node has not been created yet in initialize
|
82
|
+
or it has been freed by libxml already in Ruby's
|
83
|
+
mark phase. */
|
84
|
+
if (xnode == NULL)
|
85
|
+
return;
|
86
|
+
|
87
|
+
doc = rxml_lookup_doc(xnode->doc);
|
88
|
+
if (doc != Qnil)
|
89
|
+
rb_gc_mark(doc);
|
90
|
+
|
91
|
+
parent = rxml_lookup_node(xnode->parent);
|
92
|
+
if (parent != Qnil)
|
93
|
+
rb_gc_mark(parent);
|
94
|
+
}
|
95
|
+
|
96
|
+
VALUE rxml_node_wrap(xmlNodePtr xnode)
|
97
|
+
{
|
98
|
+
VALUE result = rxml_lookup_node(xnode);
|
99
|
+
|
100
|
+
if (result == Qnil) {
|
101
|
+
result = Data_Wrap_Struct(cXMLNode, rxml_node_mark, rxml_node_free, xnode);
|
102
|
+
rxml_register_node(xnode, result);
|
103
|
+
}
|
104
|
+
return result;
|
105
|
+
}
|
106
|
+
|
107
|
+
static VALUE rxml_node_alloc(VALUE klass)
|
108
|
+
{
|
109
|
+
/* Ruby is responsible for freeing this node not libxml but don't set
|
110
|
+
up mark and free yet until we assign the node. */
|
111
|
+
return Data_Wrap_Struct(klass, rxml_node_mark, rxml_node_free, NULL);
|
112
|
+
}
|
113
|
+
|
114
|
+
static xmlNodePtr rxml_get_xnode(VALUE node)
|
115
|
+
{
|
116
|
+
xmlNodePtr result;
|
117
|
+
Data_Get_Struct(node, xmlNode, result);
|
118
|
+
|
119
|
+
if (!result)
|
120
|
+
rb_raise(rb_eRuntimeError, "This node has already been freed.");
|
121
|
+
|
122
|
+
return result;
|
123
|
+
}
|
124
|
+
|
125
|
+
/*
|
126
|
+
* call-seq:
|
127
|
+
* XML::Node.new_cdata(content = nil) -> XML::Node
|
128
|
+
*
|
129
|
+
* Create a new #CDATA node, optionally setting
|
130
|
+
* the node's content.
|
131
|
+
*/
|
132
|
+
static VALUE rxml_node_new_cdata(int argc, VALUE *argv, VALUE klass)
|
133
|
+
{
|
134
|
+
VALUE content = Qnil;
|
135
|
+
xmlNodePtr xnode;
|
136
|
+
|
137
|
+
rb_scan_args(argc, argv, "01", &content);
|
138
|
+
|
139
|
+
if (NIL_P(content))
|
140
|
+
{
|
141
|
+
xnode = xmlNewCDataBlock(NULL, NULL, 0);
|
142
|
+
}
|
143
|
+
else
|
144
|
+
{
|
145
|
+
content = rb_obj_as_string(content);
|
146
|
+
xnode = xmlNewCDataBlock(NULL, (xmlChar*) StringValuePtr(content), (int)RSTRING_LEN(content));
|
147
|
+
}
|
148
|
+
|
149
|
+
if (xnode == NULL)
|
150
|
+
rxml_raise(&xmlLastError);
|
151
|
+
|
152
|
+
return rxml_node_wrap(xnode);
|
153
|
+
}
|
154
|
+
|
155
|
+
/*
|
156
|
+
* call-seq:
|
157
|
+
* XML::Node.new_comment(content = nil) -> XML::Node
|
158
|
+
*
|
159
|
+
* Create a new comment node, optionally setting
|
160
|
+
* the node's content.
|
161
|
+
*
|
162
|
+
*/
|
163
|
+
static VALUE rxml_node_new_comment(int argc, VALUE *argv, VALUE klass)
|
164
|
+
{
|
165
|
+
VALUE content = Qnil;
|
166
|
+
xmlNodePtr xnode;
|
167
|
+
|
168
|
+
rb_scan_args(argc, argv, "01", &content);
|
169
|
+
|
170
|
+
if (NIL_P(content))
|
171
|
+
{
|
172
|
+
xnode = xmlNewComment(NULL);
|
173
|
+
}
|
174
|
+
else
|
175
|
+
{
|
176
|
+
content = rb_obj_as_string(content);
|
177
|
+
xnode = xmlNewComment((xmlChar*) StringValueCStr(content));
|
178
|
+
}
|
179
|
+
|
180
|
+
if (xnode == NULL)
|
181
|
+
rxml_raise(&xmlLastError);
|
182
|
+
|
183
|
+
return rxml_node_wrap(xnode);
|
184
|
+
}
|
185
|
+
|
186
|
+
/*
|
187
|
+
* call-seq:
|
188
|
+
* XML::Node.new_pi(name, content = nil) -> XML::Node
|
189
|
+
*
|
190
|
+
* Create a new pi node, optionally setting
|
191
|
+
* the node's content.
|
192
|
+
*
|
193
|
+
*/
|
194
|
+
static VALUE rxml_node_new_pi(int argc, VALUE *argv, VALUE klass)
|
195
|
+
{
|
196
|
+
VALUE name = Qnil;
|
197
|
+
VALUE content = Qnil;
|
198
|
+
xmlNodePtr xnode;
|
199
|
+
|
200
|
+
rb_scan_args(argc, argv, "11", &name, &content);
|
201
|
+
|
202
|
+
if (NIL_P(name))
|
203
|
+
{
|
204
|
+
rb_raise(rb_eRuntimeError, "You must provide me with a name for a PI.");
|
205
|
+
}
|
206
|
+
name = rb_obj_as_string(name);
|
207
|
+
if (NIL_P(content))
|
208
|
+
{
|
209
|
+
xnode = xmlNewPI((xmlChar*) StringValuePtr(name), NULL);
|
210
|
+
}
|
211
|
+
else
|
212
|
+
{
|
213
|
+
content = rb_obj_as_string(content);
|
214
|
+
xnode = xmlNewPI((xmlChar*) StringValuePtr(name), (xmlChar*) StringValueCStr(content));
|
215
|
+
}
|
216
|
+
|
217
|
+
if (xnode == NULL)
|
218
|
+
rxml_raise(&xmlLastError);
|
219
|
+
|
220
|
+
return rxml_node_wrap(xnode);
|
221
|
+
}
|
222
|
+
|
223
|
+
/*
|
224
|
+
* call-seq:
|
225
|
+
* XML::Node.new_text(content) -> XML::Node
|
226
|
+
*
|
227
|
+
* Create a new text node.
|
228
|
+
*
|
229
|
+
*/
|
230
|
+
static VALUE rxml_node_new_text(VALUE klass, VALUE content)
|
231
|
+
{
|
232
|
+
xmlNodePtr xnode;
|
233
|
+
Check_Type(content, T_STRING);
|
234
|
+
content = rb_obj_as_string(content);
|
235
|
+
|
236
|
+
xnode = xmlNewText((xmlChar*) StringValueCStr(content));
|
237
|
+
|
238
|
+
if (xnode == NULL)
|
239
|
+
rxml_raise(&xmlLastError);
|
240
|
+
|
241
|
+
return rxml_node_wrap(xnode);
|
242
|
+
}
|
243
|
+
|
244
|
+
static VALUE rxml_node_content_set(VALUE self, VALUE content);
|
245
|
+
|
246
|
+
/*
|
247
|
+
* call-seq:
|
248
|
+
* XML::Node.initialize(name, content = nil, namespace = nil) -> XML::Node
|
249
|
+
*
|
250
|
+
* Creates a new element with the specified name, content and
|
251
|
+
* namespace. The content and namespace may be nil.
|
252
|
+
*/
|
253
|
+
static VALUE rxml_node_initialize(int argc, VALUE *argv, VALUE self)
|
254
|
+
{
|
255
|
+
VALUE name;
|
256
|
+
VALUE content;
|
257
|
+
VALUE ns;
|
258
|
+
xmlNodePtr xnode = NULL;
|
259
|
+
xmlNsPtr xns = NULL;
|
260
|
+
|
261
|
+
rb_scan_args(argc, argv, "12", &name, &content, &ns);
|
262
|
+
|
263
|
+
name = rb_obj_as_string(name);
|
264
|
+
|
265
|
+
if (!NIL_P(ns))
|
266
|
+
Data_Get_Struct(ns, xmlNs, xns);
|
267
|
+
|
268
|
+
xnode = xmlNewNode(xns, (xmlChar*) StringValuePtr(name));
|
269
|
+
|
270
|
+
if (xnode == NULL)
|
271
|
+
rxml_raise(&xmlLastError);
|
272
|
+
|
273
|
+
/* Link the Ruby object to the libxml object and vice-versa. */
|
274
|
+
rxml_register_node(xnode, self);
|
275
|
+
DATA_PTR(self) = xnode;
|
276
|
+
|
277
|
+
if (!NIL_P(content))
|
278
|
+
rxml_node_content_set(self, content);
|
279
|
+
|
280
|
+
return self;
|
281
|
+
}
|
282
|
+
|
283
|
+
static VALUE rxml_node_modify_dom(VALUE self, VALUE target,
|
284
|
+
xmlNodePtr (*xmlFunc)(xmlNodePtr, xmlNodePtr))
|
285
|
+
{
|
286
|
+
xmlNodePtr xnode, xtarget, xresult;
|
287
|
+
|
288
|
+
if (rb_obj_is_kind_of(target, cXMLNode) == Qfalse)
|
289
|
+
rb_raise(rb_eTypeError, "Must pass an XML::Node object");
|
290
|
+
|
291
|
+
xnode = rxml_get_xnode(self);
|
292
|
+
xtarget = rxml_get_xnode(target);
|
293
|
+
|
294
|
+
if (xtarget->doc != NULL && xtarget->doc != xnode->doc)
|
295
|
+
rb_raise(eXMLError, "Nodes belong to different documents. You must first import the node by calling XML::Document.import");
|
296
|
+
|
297
|
+
xmlUnlinkNode(xtarget);
|
298
|
+
|
299
|
+
/* This target node could be freed here. */
|
300
|
+
xresult = xmlFunc(xnode, xtarget);
|
301
|
+
|
302
|
+
if (!xresult)
|
303
|
+
rxml_raise(&xmlLastError);
|
304
|
+
|
305
|
+
/* Was the target freed? If yes, then wrap the new node */
|
306
|
+
if (xresult != xtarget)
|
307
|
+
{
|
308
|
+
RDATA(target)->data = xresult;
|
309
|
+
rxml_register_node(xresult, target);
|
310
|
+
}
|
311
|
+
|
312
|
+
return target;
|
313
|
+
}
|
314
|
+
|
315
|
+
/*
|
316
|
+
* call-seq:
|
317
|
+
* node.base_uri -> "uri"
|
318
|
+
*
|
319
|
+
* Obtain this node's base URI.
|
320
|
+
*/
|
321
|
+
static VALUE rxml_node_base_uri_get(VALUE self)
|
322
|
+
{
|
323
|
+
xmlNodePtr xnode;
|
324
|
+
xmlChar* base_uri;
|
325
|
+
VALUE result = Qnil;
|
326
|
+
|
327
|
+
xnode = rxml_get_xnode(self);
|
328
|
+
|
329
|
+
if (xnode->doc == NULL)
|
330
|
+
return (result);
|
331
|
+
|
332
|
+
base_uri = xmlNodeGetBase(xnode->doc, xnode);
|
333
|
+
if (base_uri)
|
334
|
+
{
|
335
|
+
result = rxml_new_cstr( base_uri, NULL);
|
336
|
+
xmlFree(base_uri);
|
337
|
+
}
|
338
|
+
|
339
|
+
return (result);
|
340
|
+
}
|
341
|
+
|
342
|
+
// TODO node_base_set should support setting back to nil
|
343
|
+
|
344
|
+
/*
|
345
|
+
* call-seq:
|
346
|
+
* node.base_uri = "uri"
|
347
|
+
*
|
348
|
+
* Set this node's base URI.
|
349
|
+
*/
|
350
|
+
static VALUE rxml_node_base_uri_set(VALUE self, VALUE uri)
|
351
|
+
{
|
352
|
+
xmlNodePtr xnode;
|
353
|
+
|
354
|
+
Check_Type(uri, T_STRING);
|
355
|
+
xnode = rxml_get_xnode(self);
|
356
|
+
if (xnode->doc == NULL)
|
357
|
+
return (Qnil);
|
358
|
+
|
359
|
+
xmlNodeSetBase(xnode, (xmlChar*) StringValuePtr(uri));
|
360
|
+
return (Qtrue);
|
361
|
+
}
|
362
|
+
|
363
|
+
/*
|
364
|
+
* call-seq:
|
365
|
+
* node.content -> "string"
|
366
|
+
*
|
367
|
+
* Obtain this node's content as a string.
|
368
|
+
*/
|
369
|
+
static VALUE rxml_node_content_get(VALUE self)
|
370
|
+
{
|
371
|
+
xmlNodePtr xnode;
|
372
|
+
xmlChar *content;
|
373
|
+
VALUE result = Qnil;
|
374
|
+
|
375
|
+
xnode = rxml_get_xnode(self);
|
376
|
+
content = xmlNodeGetContent(xnode);
|
377
|
+
if (content)
|
378
|
+
{
|
379
|
+
result = rxml_new_cstr(content, NULL);
|
380
|
+
xmlFree(content);
|
381
|
+
}
|
382
|
+
|
383
|
+
return result;
|
384
|
+
}
|
385
|
+
|
386
|
+
/*
|
387
|
+
* call-seq:
|
388
|
+
* node.content = "string"
|
389
|
+
*
|
390
|
+
* Set this node's content to the specified string.
|
391
|
+
*/
|
392
|
+
static VALUE rxml_node_content_set(VALUE self, VALUE content)
|
393
|
+
{
|
394
|
+
xmlNodePtr xnode;
|
395
|
+
xmlChar* encoded_content;
|
396
|
+
|
397
|
+
Check_Type(content, T_STRING);
|
398
|
+
xnode = rxml_get_xnode(self);
|
399
|
+
encoded_content = xmlEncodeSpecialChars(xnode->doc, (xmlChar*) StringValuePtr(content));
|
400
|
+
xmlNodeSetContent(xnode, encoded_content);
|
401
|
+
xmlFree(encoded_content);
|
402
|
+
return (Qtrue);
|
403
|
+
}
|
404
|
+
|
405
|
+
/*
|
406
|
+
* call-seq:
|
407
|
+
* node.content_stripped -> "string"
|
408
|
+
*
|
409
|
+
* Obtain this node's stripped content.
|
410
|
+
*
|
411
|
+
* *Deprecated*: Stripped content can be obtained via the
|
412
|
+
* +content+ method.
|
413
|
+
*/
|
414
|
+
static VALUE rxml_node_content_stripped_get(VALUE self)
|
415
|
+
{
|
416
|
+
xmlNodePtr xnode;
|
417
|
+
xmlChar* content;
|
418
|
+
VALUE result = Qnil;
|
419
|
+
|
420
|
+
xnode = rxml_get_xnode(self);
|
421
|
+
|
422
|
+
if (!xnode->content)
|
423
|
+
return result;
|
424
|
+
|
425
|
+
content = xmlNodeGetContent(xnode);
|
426
|
+
if (content)
|
427
|
+
{
|
428
|
+
result = rxml_new_cstr( content, NULL);
|
429
|
+
xmlFree(content);
|
430
|
+
}
|
431
|
+
return (result);
|
432
|
+
}
|
433
|
+
|
434
|
+
/*
|
435
|
+
* call-seq:
|
436
|
+
* node.debug -> true|false
|
437
|
+
*
|
438
|
+
* Print libxml debugging information to stdout.
|
439
|
+
* Requires that libxml was compiled with debugging enabled.
|
440
|
+
*/
|
441
|
+
static VALUE rxml_node_debug(VALUE self)
|
442
|
+
{
|
443
|
+
#ifdef LIBXML_DEBUG_ENABLED
|
444
|
+
xmlNodePtr xnode;
|
445
|
+
xnode = rxml_get_xnode(self);
|
446
|
+
xmlDebugDumpNode(NULL, xnode, 2);
|
447
|
+
return Qtrue;
|
448
|
+
#else
|
449
|
+
rb_warn("libxml was compiled without debugging support.");
|
450
|
+
return Qfalse;
|
451
|
+
#endif
|
452
|
+
}
|
453
|
+
|
454
|
+
/*
|
455
|
+
* call-seq:
|
456
|
+
* node.first -> XML::Node
|
457
|
+
*
|
458
|
+
* Returns this node's first child node if any.
|
459
|
+
*/
|
460
|
+
static VALUE rxml_node_first_get(VALUE self)
|
461
|
+
{
|
462
|
+
xmlNodePtr xnode;
|
463
|
+
|
464
|
+
xnode = rxml_get_xnode(self);
|
465
|
+
|
466
|
+
if (xnode->children)
|
467
|
+
return (rxml_node_wrap(xnode->children));
|
468
|
+
else
|
469
|
+
return (Qnil);
|
470
|
+
}
|
471
|
+
|
472
|
+
|
473
|
+
/*
|
474
|
+
* call-seq:
|
475
|
+
* curr_node << "Some text"
|
476
|
+
* curr_node << node
|
477
|
+
*
|
478
|
+
* Add the specified text or XML::Node as a new child node to the
|
479
|
+
* current node.
|
480
|
+
*
|
481
|
+
* If the specified argument is a string, it should be a raw string
|
482
|
+
* that contains unescaped XML special characters. Entity references
|
483
|
+
* are not supported.
|
484
|
+
*
|
485
|
+
* The method will return the current node.
|
486
|
+
*/
|
487
|
+
static VALUE rxml_node_content_add(VALUE self, VALUE obj)
|
488
|
+
{
|
489
|
+
xmlNodePtr xnode;
|
490
|
+
VALUE str;
|
491
|
+
|
492
|
+
xnode = rxml_get_xnode(self);
|
493
|
+
|
494
|
+
/* XXX This should only be legal for a CDATA type node, I think,
|
495
|
+
* resulting in a merge of content, as if a string were passed
|
496
|
+
* danj 070827
|
497
|
+
*/
|
498
|
+
if (rb_obj_is_kind_of(obj, cXMLNode))
|
499
|
+
{
|
500
|
+
rxml_node_modify_dom(self, obj, xmlAddChild);
|
501
|
+
}
|
502
|
+
else
|
503
|
+
{
|
504
|
+
str = rb_obj_as_string(obj);
|
505
|
+
if (NIL_P(str) || TYPE(str) != T_STRING)
|
506
|
+
rb_raise(rb_eTypeError, "invalid argument: must be string or XML::Node");
|
507
|
+
|
508
|
+
xmlNodeAddContent(xnode, (xmlChar*) StringValuePtr(str));
|
509
|
+
}
|
510
|
+
return self;
|
511
|
+
}
|
512
|
+
|
513
|
+
/*
|
514
|
+
* call-seq:
|
515
|
+
* node.doc -> document
|
516
|
+
*
|
517
|
+
* Obtain the XML::Document this node belongs to.
|
518
|
+
*/
|
519
|
+
static VALUE rxml_node_doc(VALUE self)
|
520
|
+
{
|
521
|
+
xmlDocPtr xdoc = NULL;
|
522
|
+
xmlNodePtr xnode = rxml_get_xnode(self);
|
523
|
+
|
524
|
+
switch (xnode->type)
|
525
|
+
{
|
526
|
+
case XML_DOCUMENT_NODE:
|
527
|
+
#ifdef LIBXML_DOCB_ENABLED
|
528
|
+
case XML_DOCB_DOCUMENT_NODE:
|
529
|
+
#endif
|
530
|
+
case XML_HTML_DOCUMENT_NODE:
|
531
|
+
case XML_NAMESPACE_DECL:
|
532
|
+
break;
|
533
|
+
case XML_ATTRIBUTE_NODE:
|
534
|
+
xdoc = (xmlDocPtr)((xmlAttrPtr) xnode->doc);
|
535
|
+
break;
|
536
|
+
default:
|
537
|
+
xdoc = xnode->doc;
|
538
|
+
}
|
539
|
+
|
540
|
+
if (xdoc == NULL)
|
541
|
+
return (Qnil);
|
542
|
+
|
543
|
+
return rxml_lookup_doc(xdoc);
|
544
|
+
}
|
545
|
+
|
546
|
+
/*
|
547
|
+
* call-seq:
|
548
|
+
* node.to_s -> "string"
|
549
|
+
* node.to_s(:indent => true, :encoding => 'UTF-8', :level => 0) -> "string"
|
550
|
+
*
|
551
|
+
* Converts a node, and all of its children, to a string representation.
|
552
|
+
* To include only the node's children, use the the XML::Node#inner_xml
|
553
|
+
* method.
|
554
|
+
*
|
555
|
+
* You may provide an optional hash table to control how the string is
|
556
|
+
* generated. Valid options are:
|
557
|
+
*
|
558
|
+
* :indent - Specifies if the string should be indented. The default value
|
559
|
+
* is true. Note that indentation is only added if both :indent is
|
560
|
+
* true and XML.indent_tree_output is true. If :indent is set to false,
|
561
|
+
* then both indentation and line feeds are removed from the result.
|
562
|
+
*
|
563
|
+
* :level - Specifies the indentation level. The amount of indentation
|
564
|
+
* is equal to the (level * number_spaces) + number_spaces, where libxml
|
565
|
+
* defaults the number of spaces to 2. Thus a level of 0 results in
|
566
|
+
* 2 spaces, level 1 results in 4 spaces, level 2 results in 6 spaces, etc.
|
567
|
+
*
|
568
|
+
* :encoding - Specifies the output encoding of the string. It
|
569
|
+
* defaults to XML::Encoding::UTF8. To change it, use one of the
|
570
|
+
* XML::Encoding encoding constants. */
|
571
|
+
|
572
|
+
static VALUE rxml_node_to_s(int argc, VALUE *argv, VALUE self)
|
573
|
+
{
|
574
|
+
VALUE result = Qnil;
|
575
|
+
VALUE options = Qnil;
|
576
|
+
xmlNodePtr xnode;
|
577
|
+
xmlCharEncodingHandlerPtr encodingHandler;
|
578
|
+
xmlOutputBufferPtr output;
|
579
|
+
|
580
|
+
int level = 0;
|
581
|
+
int indent = 1;
|
582
|
+
const xmlChar *xencoding = (const xmlChar*)"UTF-8";
|
583
|
+
|
584
|
+
rb_scan_args(argc, argv, "01", &options);
|
585
|
+
|
586
|
+
if (!NIL_P(options))
|
587
|
+
{
|
588
|
+
VALUE rencoding, rindent, rlevel;
|
589
|
+
Check_Type(options, T_HASH);
|
590
|
+
rencoding = rb_hash_aref(options, ID2SYM(rb_intern("encoding")));
|
591
|
+
rindent = rb_hash_aref(options, ID2SYM(rb_intern("indent")));
|
592
|
+
rlevel = rb_hash_aref(options, ID2SYM(rb_intern("level")));
|
593
|
+
|
594
|
+
if (rindent == Qfalse)
|
595
|
+
indent = 0;
|
596
|
+
|
597
|
+
if (rlevel != Qnil)
|
598
|
+
level = NUM2INT(rlevel);
|
599
|
+
|
600
|
+
if (rencoding != Qnil)
|
601
|
+
{
|
602
|
+
xencoding = (const xmlChar*)xmlGetCharEncodingName((xmlCharEncoding)NUM2INT(rencoding));
|
603
|
+
if (!xencoding)
|
604
|
+
rb_raise(rb_eArgError, "Unknown encoding value: %d", NUM2INT(rencoding));
|
605
|
+
}
|
606
|
+
}
|
607
|
+
|
608
|
+
encodingHandler = xmlFindCharEncodingHandler((const char*)xencoding);
|
609
|
+
output = xmlAllocOutputBuffer(encodingHandler);
|
610
|
+
|
611
|
+
xnode = rxml_get_xnode(self);
|
612
|
+
|
613
|
+
xmlNodeDumpOutput(output, xnode->doc, xnode, level, indent, (const char*)xencoding);
|
614
|
+
xmlOutputBufferFlush(output);
|
615
|
+
|
616
|
+
#ifdef LIBXML2_NEW_BUFFER
|
617
|
+
if (output->conv)
|
618
|
+
result = rxml_new_cstr(xmlBufContent(output->conv), xencoding);
|
619
|
+
else
|
620
|
+
result = rxml_new_cstr(xmlBufContent(output->buffer), xencoding);
|
621
|
+
#else
|
622
|
+
if (output->conv)
|
623
|
+
result = rxml_new_cstr(xmlBufferContent(output->conv), xencoding);
|
624
|
+
else
|
625
|
+
result = rxml_new_cstr(xmlBufferContent(output->buffer), xencoding);
|
626
|
+
#endif
|
627
|
+
|
628
|
+
xmlOutputBufferClose(output);
|
629
|
+
|
630
|
+
return result;
|
631
|
+
}
|
632
|
+
|
633
|
+
|
634
|
+
/*
|
635
|
+
* call-seq:
|
636
|
+
* node.each -> XML::Node
|
637
|
+
*
|
638
|
+
* Iterates over this node's children, including text
|
639
|
+
* nodes, element nodes, etc. If you wish to iterate
|
640
|
+
* only over child elements, use XML::Node#each_element.
|
641
|
+
*
|
642
|
+
* doc = XML::Document.new('model/books.xml')
|
643
|
+
* doc.root.each {|node| puts node}
|
644
|
+
*/
|
645
|
+
static VALUE rxml_node_each(VALUE self)
|
646
|
+
{
|
647
|
+
xmlNodePtr xnode;
|
648
|
+
xmlNodePtr xcurrent;
|
649
|
+
xnode = rxml_get_xnode(self);
|
650
|
+
|
651
|
+
xcurrent = xnode->children;
|
652
|
+
|
653
|
+
while (xcurrent)
|
654
|
+
{
|
655
|
+
/* The user could remove this node, so first stache
|
656
|
+
away the next node. */
|
657
|
+
xmlNodePtr xnext = xcurrent->next;
|
658
|
+
|
659
|
+
rb_yield(rxml_node_wrap(xcurrent));
|
660
|
+
xcurrent = xnext;
|
661
|
+
}
|
662
|
+
return Qnil;
|
663
|
+
}
|
664
|
+
|
665
|
+
/*
|
666
|
+
* call-seq:
|
667
|
+
* node.empty? -> (true|false)
|
668
|
+
*
|
669
|
+
* Determine whether this node is an empty or whitespace only text-node.
|
670
|
+
*/
|
671
|
+
static VALUE rxml_node_empty_q(VALUE self)
|
672
|
+
{
|
673
|
+
xmlNodePtr xnode;
|
674
|
+
xnode = rxml_get_xnode(self);
|
675
|
+
if (xnode == NULL)
|
676
|
+
return (Qnil);
|
677
|
+
|
678
|
+
return ((xmlIsBlankNode(xnode) == 1) ? Qtrue : Qfalse);
|
679
|
+
}
|
680
|
+
|
681
|
+
|
682
|
+
/*
|
683
|
+
* call-seq:
|
684
|
+
* node.eql?(other_node) => (true|false)
|
685
|
+
*
|
686
|
+
* Test equality between the two nodes. Two nodes are equal
|
687
|
+
* if they are the same node or have the same XML representation.*/
|
688
|
+
static VALUE rxml_node_eql_q(VALUE self, VALUE other)
|
689
|
+
{
|
690
|
+
if(self == other)
|
691
|
+
{
|
692
|
+
return Qtrue;
|
693
|
+
}
|
694
|
+
else if (NIL_P(other))
|
695
|
+
{
|
696
|
+
return Qfalse;
|
697
|
+
}
|
698
|
+
else
|
699
|
+
{
|
700
|
+
VALUE self_xml;
|
701
|
+
VALUE other_xml;
|
702
|
+
|
703
|
+
if (rb_obj_is_kind_of(other, cXMLNode) == Qfalse)
|
704
|
+
rb_raise(rb_eTypeError, "Nodes can only be compared against other nodes");
|
705
|
+
|
706
|
+
self_xml = rxml_node_to_s(0, NULL, self);
|
707
|
+
other_xml = rxml_node_to_s(0, NULL, other);
|
708
|
+
return(rb_funcall(self_xml, rb_intern("=="), 1, other_xml));
|
709
|
+
}
|
710
|
+
}
|
711
|
+
|
712
|
+
/*
|
713
|
+
* call-seq:
|
714
|
+
* node.lang -> "string"
|
715
|
+
*
|
716
|
+
* Obtain the language set for this node, if any.
|
717
|
+
* This is set in XML via the xml:lang attribute.
|
718
|
+
*/
|
719
|
+
static VALUE rxml_node_lang_get(VALUE self)
|
720
|
+
{
|
721
|
+
xmlNodePtr xnode;
|
722
|
+
xmlChar *lang;
|
723
|
+
VALUE result = Qnil;
|
724
|
+
|
725
|
+
xnode = rxml_get_xnode(self);
|
726
|
+
lang = xmlNodeGetLang(xnode);
|
727
|
+
|
728
|
+
if (lang)
|
729
|
+
{
|
730
|
+
result = rxml_new_cstr( lang, NULL);
|
731
|
+
xmlFree(lang);
|
732
|
+
}
|
733
|
+
|
734
|
+
return (result);
|
735
|
+
}
|
736
|
+
|
737
|
+
// TODO node_lang_set should support setting back to nil
|
738
|
+
|
739
|
+
/*
|
740
|
+
* call-seq:
|
741
|
+
* node.lang = "string"
|
742
|
+
*
|
743
|
+
* Set the language for this node. This affects the value
|
744
|
+
* of the xml:lang attribute.
|
745
|
+
*/
|
746
|
+
static VALUE rxml_node_lang_set(VALUE self, VALUE lang)
|
747
|
+
{
|
748
|
+
xmlNodePtr xnode;
|
749
|
+
|
750
|
+
Check_Type(lang, T_STRING);
|
751
|
+
xnode = rxml_get_xnode(self);
|
752
|
+
xmlNodeSetLang(xnode, (xmlChar*) StringValuePtr(lang));
|
753
|
+
|
754
|
+
return (Qtrue);
|
755
|
+
}
|
756
|
+
|
757
|
+
/*
|
758
|
+
* call-seq:
|
759
|
+
* node.last -> XML::Node
|
760
|
+
*
|
761
|
+
* Obtain the last child node of this node, if any.
|
762
|
+
*/
|
763
|
+
static VALUE rxml_node_last_get(VALUE self)
|
764
|
+
{
|
765
|
+
xmlNodePtr xnode;
|
766
|
+
|
767
|
+
xnode = rxml_get_xnode(self);
|
768
|
+
|
769
|
+
if (xnode->last)
|
770
|
+
return (rxml_node_wrap(xnode->last));
|
771
|
+
else
|
772
|
+
return (Qnil);
|
773
|
+
}
|
774
|
+
|
775
|
+
/*
|
776
|
+
* call-seq:
|
777
|
+
* node.line_num -> num
|
778
|
+
*
|
779
|
+
* Obtain the line number (in the XML document) that this
|
780
|
+
* node was read from. If +default_line_numbers+ is set
|
781
|
+
* false (the default), this method returns zero.
|
782
|
+
*/
|
783
|
+
static VALUE rxml_node_line_num(VALUE self)
|
784
|
+
{
|
785
|
+
xmlNodePtr xnode;
|
786
|
+
long line_num;
|
787
|
+
xnode = rxml_get_xnode(self);
|
788
|
+
|
789
|
+
if (!xmlLineNumbersDefaultValue)
|
790
|
+
rb_warn(
|
791
|
+
"Line numbers were not retained: use XML::Parser::default_line_numbers=true");
|
792
|
+
|
793
|
+
line_num = xmlGetLineNo(xnode);
|
794
|
+
if (line_num == -1)
|
795
|
+
return (Qnil);
|
796
|
+
else
|
797
|
+
return (INT2NUM((long) line_num));
|
798
|
+
}
|
799
|
+
|
800
|
+
/*
|
801
|
+
* call-seq:
|
802
|
+
* node.xlink? -> (true|false)
|
803
|
+
*
|
804
|
+
* Determine whether this node is an xlink node.
|
805
|
+
*/
|
806
|
+
static VALUE rxml_node_xlink_q(VALUE self)
|
807
|
+
{
|
808
|
+
xmlNodePtr xnode;
|
809
|
+
xlinkType xlt;
|
810
|
+
|
811
|
+
xnode = rxml_get_xnode(self);
|
812
|
+
xlt = xlinkIsLink(xnode->doc, xnode);
|
813
|
+
|
814
|
+
if (xlt == XLINK_TYPE_NONE)
|
815
|
+
return (Qfalse);
|
816
|
+
else
|
817
|
+
return (Qtrue);
|
818
|
+
}
|
819
|
+
|
820
|
+
/*
|
821
|
+
* call-seq:
|
822
|
+
* node.xlink_type -> num
|
823
|
+
*
|
824
|
+
* Obtain the type identifier for this xlink, if applicable.
|
825
|
+
* If this is not an xlink node (see +xlink?+), will return
|
826
|
+
* nil.
|
827
|
+
*/
|
828
|
+
static VALUE rxml_node_xlink_type(VALUE self)
|
829
|
+
{
|
830
|
+
xmlNodePtr xnode;
|
831
|
+
xlinkType xlt;
|
832
|
+
|
833
|
+
xnode = rxml_get_xnode(self);
|
834
|
+
xlt = xlinkIsLink(xnode->doc, xnode);
|
835
|
+
|
836
|
+
if (xlt == XLINK_TYPE_NONE)
|
837
|
+
return (Qnil);
|
838
|
+
else
|
839
|
+
return (INT2NUM(xlt));
|
840
|
+
}
|
841
|
+
|
842
|
+
/*
|
843
|
+
* call-seq:
|
844
|
+
* node.xlink_type_name -> "string"
|
845
|
+
*
|
846
|
+
* Obtain the type name for this xlink, if applicable.
|
847
|
+
* If this is not an xlink node (see +xlink?+), will return
|
848
|
+
* nil.
|
849
|
+
*/
|
850
|
+
static VALUE rxml_node_xlink_type_name(VALUE self)
|
851
|
+
{
|
852
|
+
xmlNodePtr xnode;
|
853
|
+
xlinkType xlt;
|
854
|
+
|
855
|
+
xnode = rxml_get_xnode(self);
|
856
|
+
xlt = xlinkIsLink(xnode->doc, xnode);
|
857
|
+
|
858
|
+
switch (xlt)
|
859
|
+
{
|
860
|
+
case XLINK_TYPE_NONE:
|
861
|
+
return (Qnil);
|
862
|
+
case XLINK_TYPE_SIMPLE:
|
863
|
+
return (rxml_new_cstr((const xmlChar*)"simple", NULL));
|
864
|
+
case XLINK_TYPE_EXTENDED:
|
865
|
+
return (rxml_new_cstr((const xmlChar*)"extended", NULL));
|
866
|
+
case XLINK_TYPE_EXTENDED_SET:
|
867
|
+
return (rxml_new_cstr((const xmlChar*)"extended_set", NULL));
|
868
|
+
default:
|
869
|
+
rb_fatal("Unknowng xlink type, %d", xlt);
|
870
|
+
}
|
871
|
+
}
|
872
|
+
|
873
|
+
/*
|
874
|
+
* call-seq:
|
875
|
+
* node.name -> "string"
|
876
|
+
*
|
877
|
+
* Obtain this node's name.
|
878
|
+
*/
|
879
|
+
static VALUE rxml_node_name_get(VALUE self)
|
880
|
+
{
|
881
|
+
xmlNodePtr xnode;
|
882
|
+
const xmlChar *name;
|
883
|
+
|
884
|
+
xnode = rxml_get_xnode(self);
|
885
|
+
|
886
|
+
switch (xnode->type)
|
887
|
+
{
|
888
|
+
case XML_DOCUMENT_NODE:
|
889
|
+
#ifdef LIBXML_DOCB_ENABLED
|
890
|
+
case XML_DOCB_DOCUMENT_NODE:
|
891
|
+
#endif
|
892
|
+
case XML_HTML_DOCUMENT_NODE:
|
893
|
+
{
|
894
|
+
xmlDocPtr doc = (xmlDocPtr) xnode;
|
895
|
+
name = doc->URL;
|
896
|
+
break;
|
897
|
+
}
|
898
|
+
case XML_ATTRIBUTE_NODE:
|
899
|
+
{
|
900
|
+
xmlAttrPtr attr = (xmlAttrPtr) xnode;
|
901
|
+
name = attr->name;
|
902
|
+
break;
|
903
|
+
}
|
904
|
+
case XML_NAMESPACE_DECL:
|
905
|
+
{
|
906
|
+
xmlNsPtr ns = (xmlNsPtr) xnode;
|
907
|
+
name = ns->prefix;
|
908
|
+
break;
|
909
|
+
}
|
910
|
+
default:
|
911
|
+
name = xnode->name;
|
912
|
+
break;
|
913
|
+
}
|
914
|
+
|
915
|
+
if (xnode->name == NULL)
|
916
|
+
return (Qnil);
|
917
|
+
else
|
918
|
+
return (rxml_new_cstr( name, NULL));
|
919
|
+
}
|
920
|
+
|
921
|
+
/*
|
922
|
+
* call-seq:
|
923
|
+
* node.name = "string"
|
924
|
+
*
|
925
|
+
* Set this node's name.
|
926
|
+
*/
|
927
|
+
static VALUE rxml_node_name_set(VALUE self, VALUE name)
|
928
|
+
{
|
929
|
+
xmlNodePtr xnode;
|
930
|
+
const xmlChar *xname;
|
931
|
+
|
932
|
+
Check_Type(name, T_STRING);
|
933
|
+
xnode = rxml_get_xnode(self);
|
934
|
+
xname = (const xmlChar*)StringValuePtr(name);
|
935
|
+
|
936
|
+
/* Note: calling xmlNodeSetName() for a text node is ignored by libXML. */
|
937
|
+
xmlNodeSetName(xnode, xname);
|
938
|
+
|
939
|
+
return (Qtrue);
|
940
|
+
}
|
941
|
+
|
942
|
+
/*
|
943
|
+
* call-seq:
|
944
|
+
* node.next -> XML::Node
|
945
|
+
*
|
946
|
+
* Returns the next sibling node if one exists.
|
947
|
+
*/
|
948
|
+
static VALUE rxml_node_next_get(VALUE self)
|
949
|
+
{
|
950
|
+
xmlNodePtr xnode;
|
951
|
+
|
952
|
+
xnode = rxml_get_xnode(self);
|
953
|
+
|
954
|
+
if (xnode->next)
|
955
|
+
return (rxml_node_wrap(xnode->next));
|
956
|
+
else
|
957
|
+
return (Qnil);
|
958
|
+
}
|
959
|
+
|
960
|
+
/*
|
961
|
+
* call-seq:
|
962
|
+
* curr_node.next = node
|
963
|
+
*
|
964
|
+
* Adds the specified node as the next sibling of the current node.
|
965
|
+
* If the node already exists in the document, it is first removed
|
966
|
+
* from its existing context. Any adjacent text nodes will be
|
967
|
+
* merged together, meaning the returned node may be different
|
968
|
+
* than the original node.
|
969
|
+
*/
|
970
|
+
static VALUE rxml_node_next_set(VALUE self, VALUE next)
|
971
|
+
{
|
972
|
+
return rxml_node_modify_dom(self, next, xmlAddNextSibling);
|
973
|
+
}
|
974
|
+
|
975
|
+
/*
|
976
|
+
* call-seq:
|
977
|
+
* node.parent -> XML::Node
|
978
|
+
*
|
979
|
+
* Obtain this node's parent node, if any.
|
980
|
+
*/
|
981
|
+
static VALUE rxml_node_parent_get(VALUE self)
|
982
|
+
{
|
983
|
+
xmlNodePtr xnode;
|
984
|
+
|
985
|
+
xnode = rxml_get_xnode(self);
|
986
|
+
|
987
|
+
if (xnode->parent)
|
988
|
+
return (rxml_node_wrap(xnode->parent));
|
989
|
+
else
|
990
|
+
return (Qnil);
|
991
|
+
}
|
992
|
+
|
993
|
+
/*
|
994
|
+
* call-seq:
|
995
|
+
* node.path -> path
|
996
|
+
*
|
997
|
+
* Obtain this node's path.
|
998
|
+
*/
|
999
|
+
static VALUE rxml_node_path(VALUE self)
|
1000
|
+
{
|
1001
|
+
xmlNodePtr xnode;
|
1002
|
+
xmlChar *path;
|
1003
|
+
|
1004
|
+
xnode = rxml_get_xnode(self);
|
1005
|
+
path = xmlGetNodePath(xnode);
|
1006
|
+
|
1007
|
+
if (path == NULL)
|
1008
|
+
return (Qnil);
|
1009
|
+
else
|
1010
|
+
return (rxml_new_cstr( path, NULL));
|
1011
|
+
}
|
1012
|
+
|
1013
|
+
/*
|
1014
|
+
* call-seq:
|
1015
|
+
* node.pointer -> XML::NodeSet
|
1016
|
+
*
|
1017
|
+
* Evaluates an XPointer expression relative to this node.
|
1018
|
+
*/
|
1019
|
+
static VALUE rxml_node_pointer(VALUE self, VALUE xptr_str)
|
1020
|
+
{
|
1021
|
+
return (rxml_xpointer_point2(self, xptr_str));
|
1022
|
+
}
|
1023
|
+
|
1024
|
+
/*
|
1025
|
+
* call-seq:
|
1026
|
+
* node.prev -> XML::Node
|
1027
|
+
*
|
1028
|
+
* Obtain the previous sibling, if any.
|
1029
|
+
*/
|
1030
|
+
static VALUE rxml_node_prev_get(VALUE self)
|
1031
|
+
{
|
1032
|
+
xmlNodePtr xnode;
|
1033
|
+
xmlNodePtr node;
|
1034
|
+
xnode = rxml_get_xnode(self);
|
1035
|
+
|
1036
|
+
switch (xnode->type)
|
1037
|
+
{
|
1038
|
+
case XML_DOCUMENT_NODE:
|
1039
|
+
#ifdef LIBXML_DOCB_ENABLED
|
1040
|
+
case XML_DOCB_DOCUMENT_NODE:
|
1041
|
+
#endif
|
1042
|
+
case XML_HTML_DOCUMENT_NODE:
|
1043
|
+
case XML_NAMESPACE_DECL:
|
1044
|
+
node = NULL;
|
1045
|
+
break;
|
1046
|
+
case XML_ATTRIBUTE_NODE:
|
1047
|
+
{
|
1048
|
+
xmlAttrPtr attr = (xmlAttrPtr) xnode;
|
1049
|
+
node = (xmlNodePtr) attr->prev;
|
1050
|
+
}
|
1051
|
+
break;
|
1052
|
+
default:
|
1053
|
+
node = xnode->prev;
|
1054
|
+
break;
|
1055
|
+
}
|
1056
|
+
|
1057
|
+
if (node == NULL)
|
1058
|
+
return (Qnil);
|
1059
|
+
else
|
1060
|
+
return (rxml_node_wrap(node));
|
1061
|
+
}
|
1062
|
+
|
1063
|
+
/*
|
1064
|
+
* call-seq:
|
1065
|
+
* curr_node.prev = node
|
1066
|
+
*
|
1067
|
+
* Adds the specified node as the previous sibling of the current node.
|
1068
|
+
* If the node already exists in the document, it is first removed
|
1069
|
+
* from its existing context. Any adjacent text nodes will be
|
1070
|
+
* merged together, meaning the returned node may be different
|
1071
|
+
* than the original node.
|
1072
|
+
*/
|
1073
|
+
static VALUE rxml_node_prev_set(VALUE self, VALUE prev)
|
1074
|
+
{
|
1075
|
+
return rxml_node_modify_dom(self, prev, xmlAddPrevSibling);
|
1076
|
+
}
|
1077
|
+
|
1078
|
+
/*
|
1079
|
+
* call-seq:
|
1080
|
+
* node.attributes -> attributes
|
1081
|
+
*
|
1082
|
+
* Returns the XML::Attributes for this node.
|
1083
|
+
*/
|
1084
|
+
static VALUE rxml_node_attributes_get(VALUE self)
|
1085
|
+
{
|
1086
|
+
xmlNodePtr xnode;
|
1087
|
+
|
1088
|
+
xnode = rxml_get_xnode(self);
|
1089
|
+
return rxml_attributes_new(xnode);
|
1090
|
+
}
|
1091
|
+
|
1092
|
+
/*
|
1093
|
+
* call-seq:
|
1094
|
+
* node.property("name") -> "string"
|
1095
|
+
* node["name"] -> "string"
|
1096
|
+
*
|
1097
|
+
* Obtain the named property.
|
1098
|
+
*/
|
1099
|
+
static VALUE rxml_node_attribute_get(VALUE self, VALUE name)
|
1100
|
+
{
|
1101
|
+
VALUE attributes = rxml_node_attributes_get(self);
|
1102
|
+
return rxml_attributes_attribute_get(attributes, name);
|
1103
|
+
}
|
1104
|
+
|
1105
|
+
/*
|
1106
|
+
* call-seq:
|
1107
|
+
* node["name"] = "string"
|
1108
|
+
*
|
1109
|
+
* Set the named property.
|
1110
|
+
*/
|
1111
|
+
static VALUE rxml_node_property_set(VALUE self, VALUE name, VALUE value)
|
1112
|
+
{
|
1113
|
+
VALUE attributes = rxml_node_attributes_get(self);
|
1114
|
+
return rxml_attributes_attribute_set(attributes, name, value);
|
1115
|
+
}
|
1116
|
+
|
1117
|
+
/*
|
1118
|
+
* call-seq:
|
1119
|
+
* node.remove! -> node
|
1120
|
+
*
|
1121
|
+
* Removes this node and its children from the document tree by setting its document,
|
1122
|
+
* parent and siblings to nil. You can add the returned node back into a document.
|
1123
|
+
* Otherwise, the node will be freed once any references to it go out of scope.
|
1124
|
+
*/
|
1125
|
+
|
1126
|
+
static VALUE rxml_node_remove_ex(VALUE self)
|
1127
|
+
{
|
1128
|
+
xmlNodePtr xnode, xresult;
|
1129
|
+
xnode = rxml_get_xnode(self);
|
1130
|
+
|
1131
|
+
/* First unlink the node from its parent. */
|
1132
|
+
xmlUnlinkNode(xnode);
|
1133
|
+
|
1134
|
+
/* Now copy the node we want to remove and make the
|
1135
|
+
current Ruby object point to it. We do this because
|
1136
|
+
a node has a number of dependencies on its parent
|
1137
|
+
document - its name (if using a dictionary), entities,
|
1138
|
+
namespaces, etc. For a node to live on its own, it
|
1139
|
+
needs to get its own copies of this information.*/
|
1140
|
+
xresult = xmlDocCopyNode(xnode, NULL, 1);
|
1141
|
+
|
1142
|
+
/* This ruby node object no longer points at the node.*/
|
1143
|
+
rxml_unregister_node(xnode);
|
1144
|
+
RDATA(self)->data = NULL;
|
1145
|
+
|
1146
|
+
/* Now free the original node. This will call the deregister node
|
1147
|
+
callback which would reset the mark and free function except for
|
1148
|
+
the fact we already removed it from the private hashtable above */
|
1149
|
+
xmlFreeNode(xnode);
|
1150
|
+
|
1151
|
+
/* Now wrap the new node */
|
1152
|
+
RDATA(self)->data = xresult;
|
1153
|
+
rxml_register_node(xresult, self);
|
1154
|
+
|
1155
|
+
/* Now return the removed node so the user can
|
1156
|
+
do something with it.*/
|
1157
|
+
return self;
|
1158
|
+
}
|
1159
|
+
|
1160
|
+
/*
|
1161
|
+
* call-seq:
|
1162
|
+
* curr_node.sibling = node
|
1163
|
+
*
|
1164
|
+
* Adds the specified node as the end of the current node's list
|
1165
|
+
* of siblings. If the node already exists in the document, it
|
1166
|
+
* is first removed from its existing context. Any adjacent text
|
1167
|
+
* nodes will be merged together, meaning the returned node may
|
1168
|
+
* be different than the original node.
|
1169
|
+
*/
|
1170
|
+
static VALUE rxml_node_sibling_set(VALUE self, VALUE sibling)
|
1171
|
+
{
|
1172
|
+
return rxml_node_modify_dom(self, sibling, xmlAddSibling);
|
1173
|
+
}
|
1174
|
+
|
1175
|
+
/*
|
1176
|
+
* call-seq:
|
1177
|
+
* text_node.output_escaping? -> (true|false)
|
1178
|
+
* element_node.output_escaping? -> (true|false|nil)
|
1179
|
+
* attribute_node.output_escaping? -> (true|false|nil)
|
1180
|
+
* other_node.output_escaping? -> (nil)
|
1181
|
+
*
|
1182
|
+
* Determine whether this node escapes it's output or not.
|
1183
|
+
*
|
1184
|
+
* Text nodes return only +true+ or +false+. Element and attribute nodes
|
1185
|
+
* examine their immediate text node children to determine the value.
|
1186
|
+
* Any other type of node always returns +nil+.
|
1187
|
+
*
|
1188
|
+
* If an element or attribute node has at least one immediate child text node
|
1189
|
+
* and all the immediate text node children have the same +output_escaping?+
|
1190
|
+
* value, that value is returned. Otherwise, +nil+ is returned.
|
1191
|
+
*/
|
1192
|
+
static VALUE rxml_node_output_escaping_q(VALUE self)
|
1193
|
+
{
|
1194
|
+
xmlNodePtr xnode;
|
1195
|
+
xnode = rxml_get_xnode(self);
|
1196
|
+
|
1197
|
+
switch (xnode->type) {
|
1198
|
+
case XML_TEXT_NODE:
|
1199
|
+
return xnode->name==xmlStringTextNoenc ? Qfalse : Qtrue;
|
1200
|
+
case XML_ELEMENT_NODE:
|
1201
|
+
case XML_ATTRIBUTE_NODE:
|
1202
|
+
{
|
1203
|
+
xmlNodePtr tmp = xnode->children;
|
1204
|
+
const xmlChar *match = NULL;
|
1205
|
+
|
1206
|
+
/* Find the first text node and use it as the reference. */
|
1207
|
+
while (tmp && tmp->type != XML_TEXT_NODE)
|
1208
|
+
tmp = tmp->next;
|
1209
|
+
if (! tmp)
|
1210
|
+
return Qnil;
|
1211
|
+
match = tmp->name;
|
1212
|
+
|
1213
|
+
/* Walk the remaining text nodes until we run out or one doesn't match. */
|
1214
|
+
while (tmp && (tmp->type != XML_TEXT_NODE || match == tmp->name))
|
1215
|
+
tmp = tmp->next;
|
1216
|
+
|
1217
|
+
/* We're left with either the mismatched node or the aggregate result. */
|
1218
|
+
return tmp ? Qnil : (match==xmlStringTextNoenc ? Qfalse : Qtrue);
|
1219
|
+
}
|
1220
|
+
break;
|
1221
|
+
default:
|
1222
|
+
return Qnil;
|
1223
|
+
}
|
1224
|
+
}
|
1225
|
+
|
1226
|
+
/*
|
1227
|
+
* call-seq:
|
1228
|
+
* text_node.output_escaping = true|false
|
1229
|
+
* element_node.output_escaping = true|false
|
1230
|
+
* attribute_node.output_escaping = true|false
|
1231
|
+
*
|
1232
|
+
* Controls whether this text node or the immediate text node children of an
|
1233
|
+
* element or attribute node escapes their output. Any other type of node
|
1234
|
+
* will simply ignore this operation.
|
1235
|
+
*
|
1236
|
+
* Text nodes which are added to an element or attribute node will be affected
|
1237
|
+
* by any previous setting of this property.
|
1238
|
+
*/
|
1239
|
+
static VALUE rxml_node_output_escaping_set(VALUE self, VALUE value)
|
1240
|
+
{
|
1241
|
+
xmlNodePtr xnode;
|
1242
|
+
xnode = rxml_get_xnode(self);
|
1243
|
+
|
1244
|
+
switch (xnode->type) {
|
1245
|
+
case XML_TEXT_NODE:
|
1246
|
+
xnode->name = (value != Qfalse && value != Qnil) ? xmlStringText : xmlStringTextNoenc;
|
1247
|
+
break;
|
1248
|
+
case XML_ELEMENT_NODE:
|
1249
|
+
case XML_ATTRIBUTE_NODE:
|
1250
|
+
{
|
1251
|
+
const xmlChar *name = (value != Qfalse && value != Qnil) ? xmlStringText : xmlStringTextNoenc;
|
1252
|
+
xmlNodePtr tmp;
|
1253
|
+
for (tmp = xnode->children; tmp; tmp = tmp->next)
|
1254
|
+
if (tmp->type == XML_TEXT_NODE)
|
1255
|
+
tmp->name = name;
|
1256
|
+
}
|
1257
|
+
break;
|
1258
|
+
default:
|
1259
|
+
return Qnil;
|
1260
|
+
}
|
1261
|
+
|
1262
|
+
return (value!=Qfalse && value!=Qnil) ? Qtrue : Qfalse;
|
1263
|
+
}
|
1264
|
+
|
1265
|
+
/*
|
1266
|
+
* call-seq:
|
1267
|
+
* node.space_preserve -> (true|false)
|
1268
|
+
*
|
1269
|
+
* Determine whether this node preserves whitespace.
|
1270
|
+
*/
|
1271
|
+
static VALUE rxml_node_space_preserve_get(VALUE self)
|
1272
|
+
{
|
1273
|
+
xmlNodePtr xnode;
|
1274
|
+
|
1275
|
+
xnode = rxml_get_xnode(self);
|
1276
|
+
return (INT2NUM(xmlNodeGetSpacePreserve(xnode)));
|
1277
|
+
}
|
1278
|
+
|
1279
|
+
/*
|
1280
|
+
* call-seq:
|
1281
|
+
* node.space_preserve = true|false
|
1282
|
+
*
|
1283
|
+
* Control whether this node preserves whitespace.
|
1284
|
+
*/
|
1285
|
+
static VALUE rxml_node_space_preserve_set(VALUE self, VALUE value)
|
1286
|
+
{
|
1287
|
+
xmlNodePtr xnode;
|
1288
|
+
xnode = rxml_get_xnode(self);
|
1289
|
+
|
1290
|
+
if (value == Qfalse)
|
1291
|
+
xmlNodeSetSpacePreserve(xnode, 0);
|
1292
|
+
else
|
1293
|
+
xmlNodeSetSpacePreserve(xnode, 1);
|
1294
|
+
|
1295
|
+
return (Qnil);
|
1296
|
+
}
|
1297
|
+
|
1298
|
+
/*
|
1299
|
+
* call-seq:
|
1300
|
+
* node.type -> num
|
1301
|
+
*
|
1302
|
+
* Obtain this node's type identifier.
|
1303
|
+
*/
|
1304
|
+
static VALUE rxml_node_type(VALUE self)
|
1305
|
+
{
|
1306
|
+
xmlNodePtr xnode;
|
1307
|
+
xnode = rxml_get_xnode(self);
|
1308
|
+
return (INT2NUM(xnode->type));
|
1309
|
+
}
|
1310
|
+
|
1311
|
+
/*
|
1312
|
+
* call-seq:
|
1313
|
+
* node.copy -> XML::Node
|
1314
|
+
*
|
1315
|
+
* Creates a copy of this node. To create a
|
1316
|
+
* shallow copy set the deep parameter to false.
|
1317
|
+
* To create a deep copy set the deep parameter
|
1318
|
+
* to true.
|
1319
|
+
*
|
1320
|
+
*/
|
1321
|
+
static VALUE rxml_node_copy(VALUE self, VALUE deep)
|
1322
|
+
{
|
1323
|
+
xmlNodePtr xnode;
|
1324
|
+
xmlNodePtr xcopy;
|
1325
|
+
int recursive = (deep == Qnil || deep == Qfalse) ? 0 : 1;
|
1326
|
+
xnode = rxml_get_xnode(self);
|
1327
|
+
|
1328
|
+
xcopy = xmlCopyNode(xnode, recursive);
|
1329
|
+
|
1330
|
+
if (xcopy)
|
1331
|
+
return rxml_node_wrap(xcopy);
|
1332
|
+
else
|
1333
|
+
return Qnil;
|
1334
|
+
}
|
1335
|
+
|
1336
|
+
void rxml_init_node(void)
|
1337
|
+
{
|
1338
|
+
/* Register callback for main thread */
|
1339
|
+
xmlDeregisterNodeDefault(rxml_node_deregisterNode);
|
1340
|
+
|
1341
|
+
/* Register callback for all other threads */
|
1342
|
+
xmlThrDefDeregisterNodeDefault(rxml_node_deregisterNode);
|
1343
|
+
|
1344
|
+
cXMLNode = rb_define_class_under(mXML, "Node", rb_cObject);
|
1345
|
+
|
1346
|
+
rb_define_const(cXMLNode, "SPACE_DEFAULT", INT2NUM(0));
|
1347
|
+
rb_define_const(cXMLNode, "SPACE_PRESERVE", INT2NUM(1));
|
1348
|
+
rb_define_const(cXMLNode, "SPACE_NOT_INHERIT", INT2NUM(-1));
|
1349
|
+
rb_define_const(cXMLNode, "XLINK_ACTUATE_AUTO", INT2NUM(1));
|
1350
|
+
rb_define_const(cXMLNode, "XLINK_ACTUATE_NONE", INT2NUM(0));
|
1351
|
+
rb_define_const(cXMLNode, "XLINK_ACTUATE_ONREQUEST", INT2NUM(2));
|
1352
|
+
rb_define_const(cXMLNode, "XLINK_SHOW_EMBED", INT2NUM(2));
|
1353
|
+
rb_define_const(cXMLNode, "XLINK_SHOW_NEW", INT2NUM(1));
|
1354
|
+
rb_define_const(cXMLNode, "XLINK_SHOW_NONE", INT2NUM(0));
|
1355
|
+
rb_define_const(cXMLNode, "XLINK_SHOW_REPLACE", INT2NUM(3));
|
1356
|
+
rb_define_const(cXMLNode, "XLINK_TYPE_EXTENDED", INT2NUM(2));
|
1357
|
+
rb_define_const(cXMLNode, "XLINK_TYPE_EXTENDED_SET", INT2NUM(3));
|
1358
|
+
rb_define_const(cXMLNode, "XLINK_TYPE_NONE", INT2NUM(0));
|
1359
|
+
rb_define_const(cXMLNode, "XLINK_TYPE_SIMPLE", INT2NUM(1));
|
1360
|
+
|
1361
|
+
rb_define_const(cXMLNode, "ELEMENT_NODE", INT2FIX(XML_ELEMENT_NODE));
|
1362
|
+
rb_define_const(cXMLNode, "ATTRIBUTE_NODE", INT2FIX(XML_ATTRIBUTE_NODE));
|
1363
|
+
rb_define_const(cXMLNode, "TEXT_NODE", INT2FIX(XML_TEXT_NODE));
|
1364
|
+
rb_define_const(cXMLNode, "CDATA_SECTION_NODE", INT2FIX(XML_CDATA_SECTION_NODE));
|
1365
|
+
rb_define_const(cXMLNode, "ENTITY_REF_NODE", INT2FIX(XML_ENTITY_REF_NODE));
|
1366
|
+
rb_define_const(cXMLNode, "ENTITY_NODE", INT2FIX(XML_ENTITY_NODE));
|
1367
|
+
rb_define_const(cXMLNode, "PI_NODE", INT2FIX(XML_PI_NODE));
|
1368
|
+
rb_define_const(cXMLNode, "COMMENT_NODE", INT2FIX(XML_COMMENT_NODE));
|
1369
|
+
rb_define_const(cXMLNode, "DOCUMENT_NODE", INT2FIX(XML_DOCUMENT_NODE));
|
1370
|
+
rb_define_const(cXMLNode, "DOCUMENT_TYPE_NODE", INT2FIX(XML_DOCUMENT_TYPE_NODE));
|
1371
|
+
rb_define_const(cXMLNode, "DOCUMENT_FRAG_NODE", INT2FIX(XML_DOCUMENT_FRAG_NODE));
|
1372
|
+
rb_define_const(cXMLNode, "NOTATION_NODE", INT2FIX(XML_NOTATION_NODE));
|
1373
|
+
rb_define_const(cXMLNode, "HTML_DOCUMENT_NODE", INT2FIX(XML_HTML_DOCUMENT_NODE));
|
1374
|
+
rb_define_const(cXMLNode, "DTD_NODE", INT2FIX(XML_DTD_NODE));
|
1375
|
+
rb_define_const(cXMLNode, "ELEMENT_DECL", INT2FIX(XML_ELEMENT_DECL));
|
1376
|
+
rb_define_const(cXMLNode, "ATTRIBUTE_DECL", INT2FIX(XML_ATTRIBUTE_DECL));
|
1377
|
+
rb_define_const(cXMLNode, "ENTITY_DECL", INT2FIX(XML_ENTITY_DECL));
|
1378
|
+
rb_define_const(cXMLNode, "NAMESPACE_DECL", INT2FIX(XML_NAMESPACE_DECL));
|
1379
|
+
rb_define_const(cXMLNode, "XINCLUDE_START", INT2FIX(XML_XINCLUDE_START));
|
1380
|
+
rb_define_const(cXMLNode, "XINCLUDE_END", INT2FIX(XML_XINCLUDE_END));
|
1381
|
+
|
1382
|
+
#ifdef LIBXML_DOCB_ENABLED
|
1383
|
+
rb_define_const(cXMLNode, "DOCB_DOCUMENT_NODE", INT2FIX(XML_DOCB_DOCUMENT_NODE));
|
1384
|
+
#else
|
1385
|
+
rb_define_const(cXMLNode, "DOCB_DOCUMENT_NODE", Qnil);
|
1386
|
+
#endif
|
1387
|
+
|
1388
|
+
rb_define_singleton_method(cXMLNode, "new_cdata", rxml_node_new_cdata, -1);
|
1389
|
+
rb_define_singleton_method(cXMLNode, "new_comment", rxml_node_new_comment, -1);
|
1390
|
+
rb_define_singleton_method(cXMLNode, "new_pi", rxml_node_new_pi, -1);
|
1391
|
+
rb_define_singleton_method(cXMLNode, "new_text", rxml_node_new_text, 1);
|
1392
|
+
|
1393
|
+
/* Initialization */
|
1394
|
+
rb_define_alloc_func(cXMLNode, rxml_node_alloc);
|
1395
|
+
rb_define_method(cXMLNode, "initialize", rxml_node_initialize, -1);
|
1396
|
+
|
1397
|
+
/* Traversal */
|
1398
|
+
rb_include_module(cXMLNode, rb_mEnumerable);
|
1399
|
+
rb_define_method(cXMLNode, "[]", rxml_node_attribute_get, 1);
|
1400
|
+
rb_define_method(cXMLNode, "each", rxml_node_each, 0);
|
1401
|
+
rb_define_method(cXMLNode, "first", rxml_node_first_get, 0);
|
1402
|
+
rb_define_method(cXMLNode, "last", rxml_node_last_get, 0);
|
1403
|
+
rb_define_method(cXMLNode, "next", rxml_node_next_get, 0);
|
1404
|
+
rb_define_method(cXMLNode, "parent", rxml_node_parent_get, 0);
|
1405
|
+
rb_define_method(cXMLNode, "prev", rxml_node_prev_get, 0);
|
1406
|
+
|
1407
|
+
/* Modification */
|
1408
|
+
rb_define_method(cXMLNode, "[]=", rxml_node_property_set, 2);
|
1409
|
+
rb_define_method(cXMLNode, "<<", rxml_node_content_add, 1);
|
1410
|
+
rb_define_method(cXMLNode, "sibling=", rxml_node_sibling_set, 1);
|
1411
|
+
rb_define_method(cXMLNode, "next=", rxml_node_next_set, 1);
|
1412
|
+
rb_define_method(cXMLNode, "prev=", rxml_node_prev_set, 1);
|
1413
|
+
|
1414
|
+
/* Rest of the node api */
|
1415
|
+
rb_define_method(cXMLNode, "attributes", rxml_node_attributes_get, 0);
|
1416
|
+
rb_define_method(cXMLNode, "base_uri", rxml_node_base_uri_get, 0);
|
1417
|
+
rb_define_method(cXMLNode, "base_uri=", rxml_node_base_uri_set, 1);
|
1418
|
+
rb_define_method(cXMLNode, "blank?", rxml_node_empty_q, 0);
|
1419
|
+
rb_define_method(cXMLNode, "copy", rxml_node_copy, 1);
|
1420
|
+
rb_define_method(cXMLNode, "content", rxml_node_content_get, 0);
|
1421
|
+
rb_define_method(cXMLNode, "content=", rxml_node_content_set, 1);
|
1422
|
+
rb_define_method(cXMLNode, "content_stripped", rxml_node_content_stripped_get, 0);
|
1423
|
+
rb_define_method(cXMLNode, "debug", rxml_node_debug, 0);
|
1424
|
+
rb_define_method(cXMLNode, "doc", rxml_node_doc, 0);
|
1425
|
+
rb_define_method(cXMLNode, "empty?", rxml_node_empty_q, 0);
|
1426
|
+
rb_define_method(cXMLNode, "eql?", rxml_node_eql_q, 1);
|
1427
|
+
rb_define_method(cXMLNode, "lang", rxml_node_lang_get, 0);
|
1428
|
+
rb_define_method(cXMLNode, "lang=", rxml_node_lang_set, 1);
|
1429
|
+
rb_define_method(cXMLNode, "line_num", rxml_node_line_num, 0);
|
1430
|
+
rb_define_method(cXMLNode, "name", rxml_node_name_get, 0);
|
1431
|
+
rb_define_method(cXMLNode, "name=", rxml_node_name_set, 1);
|
1432
|
+
rb_define_method(cXMLNode, "node_type", rxml_node_type, 0);
|
1433
|
+
rb_define_method(cXMLNode, "output_escaping?", rxml_node_output_escaping_q, 0);
|
1434
|
+
rb_define_method(cXMLNode, "output_escaping=", rxml_node_output_escaping_set, 1);
|
1435
|
+
rb_define_method(cXMLNode, "path", rxml_node_path, 0);
|
1436
|
+
rb_define_method(cXMLNode, "pointer", rxml_node_pointer, 1);
|
1437
|
+
rb_define_method(cXMLNode, "remove!", rxml_node_remove_ex, 0);
|
1438
|
+
rb_define_method(cXMLNode, "space_preserve", rxml_node_space_preserve_get, 0);
|
1439
|
+
rb_define_method(cXMLNode, "space_preserve=", rxml_node_space_preserve_set, 1);
|
1440
|
+
rb_define_method(cXMLNode, "to_s", rxml_node_to_s, -1);
|
1441
|
+
rb_define_method(cXMLNode, "xlink?", rxml_node_xlink_q, 0);
|
1442
|
+
rb_define_method(cXMLNode, "xlink_type", rxml_node_xlink_type, 0);
|
1443
|
+
rb_define_method(cXMLNode, "xlink_type_name", rxml_node_xlink_type_name, 0);
|
1444
|
+
|
1445
|
+
rb_define_alias(cXMLNode, "==", "eql?");
|
1446
|
+
}
|