libxml-ruby 0.9.3-x86-mswin32-60 → 0.9.4-x86-mswin32-60
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +9 -0
- data/README +61 -128
- data/doc/css/normal.css +182 -0
- data/doc/img/raze-tiny.png +0 -0
- data/doc/img/red-cube.jpg +0 -0
- data/doc/img/xml-ruby.png +0 -0
- data/doc/index.xml +43 -0
- data/doc/install.xml +77 -0
- data/doc/layout.rhtml +38 -0
- data/doc/layout.xsl +67 -0
- data/doc/license.xml +32 -0
- data/doc/log/changelog.xml +1324 -0
- data/doc/log/changelog.xsl +42 -0
- data/ext/libxml/ruby_xml_document.c +1084 -1057
- data/ext/libxml/ruby_xml_html_parser.c +37 -40
- data/ext/libxml/ruby_xml_input.c +17 -40
- data/ext/libxml/ruby_xml_input.h +2 -2
- data/ext/libxml/ruby_xml_parser.c +151 -151
- data/ext/libxml/ruby_xml_reader.c +910 -893
- data/ext/libxml/ruby_xml_sax_parser.c +174 -174
- data/ext/libxml/ruby_xml_sax_parser.h +12 -12
- data/ext/libxml/ruby_xml_xpointer.h +13 -25
- data/ext/libxml/version.h +2 -2
- data/ext/mingw/libxml_ruby.dll.a +0 -0
- data/ext/mingw/libxml_ruby.so +0 -0
- data/ext/vc/libxml_ruby.vcproj +1 -1
- data/test/model/ruby-lang.html +238 -0
- data/test/tc_html_parser.rb +2 -12
- data/test/tc_reader.rb +87 -87
- metadata +17 -3
- data/test/test.rb +0 -8
@@ -1,893 +1,910 @@
|
|
1
|
-
/* Copyright (c) 2006-2007 Apple Inc.
|
2
|
-
* Please see the LICENSE file for copyright and distribution information. */
|
3
|
-
|
4
|
-
#include "ruby_libxml.h"
|
5
|
-
#include "ruby_xml_reader.h"
|
6
|
-
|
7
|
-
VALUE cXMLReader;
|
8
|
-
|
9
|
-
/*
|
10
|
-
* Document-class: LibXML::XML::Reader
|
11
|
-
*
|
12
|
-
* The XML::Reader class provides a simpler, alternative way of parsing an XML
|
13
|
-
* document in contrast to XML::Parser or XML::SaxParser. A XML::Reader instance
|
14
|
-
* acts like a cursor going forward in a document stream, stopping at each node
|
15
|
-
* it encounters. To advance to the next node, simply cadd XML::Reader#read.
|
16
|
-
*
|
17
|
-
* The XML::Reader API closely matches the DOM Core specification and supports
|
18
|
-
* namespaces, xml:base, entity handling and DTDs.
|
19
|
-
*
|
20
|
-
* To summarize, XML::Reader provides a far simpler API to use versus XML::SaxParser
|
21
|
-
* and is more memory efficient than using XML::Parser to create a DOM tree.
|
22
|
-
*
|
23
|
-
* Example:
|
24
|
-
*
|
25
|
-
* parser = XML::Reader.new("<foo><bar>1</bar><bar>2</bar><bar>3</bar></foo>")
|
26
|
-
* parser.read
|
27
|
-
* assert_equal('foo', parser.name)
|
28
|
-
* assert_equal(nil, parser.value)
|
29
|
-
*
|
30
|
-
* 3.times do |i|
|
31
|
-
* parser.read
|
32
|
-
* assert_equal(XML::Reader::TYPE_ELEMENT, parser.node_type)
|
33
|
-
* assert_equal('bar', parser.name)
|
34
|
-
* parser.read
|
35
|
-
* assert_equal(XML::Reader::TYPE_TEXT, parser.node_type)
|
36
|
-
* assert_equal((i + 1).to_s, parser.value)
|
37
|
-
* parser.read
|
38
|
-
* assert_equal(XML::Reader::TYPE_END_ELEMENT, parser.node_type)
|
39
|
-
* end
|
40
|
-
*
|
41
|
-
* For a more in depth tutorial, albeit in C, see http://xmlsoft.org/xmlreader.html.*/
|
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
|
-
|
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
|
-
|
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
|
-
* current
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
*
|
257
|
-
*
|
258
|
-
*
|
259
|
-
* the
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
*
|
270
|
-
*
|
271
|
-
*
|
272
|
-
* the
|
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
|
-
* read,
|
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
|
-
*
|
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
|
-
return
|
519
|
-
}
|
520
|
-
|
521
|
-
/*
|
522
|
-
* call-seq:
|
523
|
-
* reader.
|
524
|
-
*
|
525
|
-
*
|
526
|
-
*/
|
527
|
-
static VALUE
|
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
|
-
|
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
|
-
rb_define_method(cXMLReader, "
|
820
|
-
|
821
|
-
|
822
|
-
rb_define_method(cXMLReader, "
|
823
|
-
rb_define_method(cXMLReader, "
|
824
|
-
rb_define_method(cXMLReader, "
|
825
|
-
rb_define_method(cXMLReader, "
|
826
|
-
rb_define_method(cXMLReader, "
|
827
|
-
rb_define_method(cXMLReader, "
|
828
|
-
rb_define_method(cXMLReader, "
|
829
|
-
rb_define_method(cXMLReader, "
|
830
|
-
rb_define_method(cXMLReader, "
|
831
|
-
rb_define_method(cXMLReader, "
|
832
|
-
rb_define_method(cXMLReader, "
|
833
|
-
|
834
|
-
rb_define_method(cXMLReader, "
|
835
|
-
|
836
|
-
|
837
|
-
|
838
|
-
|
839
|
-
rb_define_method(cXMLReader, "
|
840
|
-
rb_define_method(cXMLReader, "
|
841
|
-
|
842
|
-
rb_define_method(cXMLReader, "
|
843
|
-
rb_define_method(cXMLReader, "
|
844
|
-
|
845
|
-
|
846
|
-
rb_define_method(cXMLReader, "
|
847
|
-
|
848
|
-
|
849
|
-
rb_define_method(cXMLReader, "
|
850
|
-
rb_define_method(cXMLReader, "
|
851
|
-
|
852
|
-
rb_define_method(cXMLReader, "
|
853
|
-
|
854
|
-
rb_define_method(cXMLReader, "
|
855
|
-
rb_define_method(cXMLReader, "
|
856
|
-
|
857
|
-
|
858
|
-
|
859
|
-
|
860
|
-
|
861
|
-
|
862
|
-
|
863
|
-
|
864
|
-
|
865
|
-
|
866
|
-
|
867
|
-
|
868
|
-
|
869
|
-
|
870
|
-
|
871
|
-
|
872
|
-
|
873
|
-
|
874
|
-
rb_define_const(cXMLReader, "
|
875
|
-
rb_define_const(cXMLReader, "
|
876
|
-
rb_define_const(cXMLReader, "
|
877
|
-
rb_define_const(cXMLReader, "
|
878
|
-
|
879
|
-
rb_define_const(cXMLReader, "
|
880
|
-
rb_define_const(cXMLReader, "
|
881
|
-
rb_define_const(cXMLReader, "
|
882
|
-
rb_define_const(cXMLReader, "
|
883
|
-
|
884
|
-
rb_define_const(cXMLReader, "
|
885
|
-
|
886
|
-
|
887
|
-
rb_define_const(cXMLReader, "
|
888
|
-
rb_define_const(cXMLReader, "
|
889
|
-
rb_define_const(cXMLReader, "
|
890
|
-
rb_define_const(cXMLReader, "
|
891
|
-
rb_define_const(cXMLReader, "
|
892
|
-
rb_define_const(cXMLReader, "
|
893
|
-
|
1
|
+
/* Copyright (c) 2006-2007 Apple Inc.
|
2
|
+
* Please see the LICENSE file for copyright and distribution information. */
|
3
|
+
|
4
|
+
#include "ruby_libxml.h"
|
5
|
+
#include "ruby_xml_reader.h"
|
6
|
+
|
7
|
+
VALUE cXMLReader;
|
8
|
+
|
9
|
+
/*
|
10
|
+
* Document-class: LibXML::XML::Reader
|
11
|
+
*
|
12
|
+
* The XML::Reader class provides a simpler, alternative way of parsing an XML
|
13
|
+
* document in contrast to XML::Parser or XML::SaxParser. A XML::Reader instance
|
14
|
+
* acts like a cursor going forward in a document stream, stopping at each node
|
15
|
+
* it encounters. To advance to the next node, simply cadd XML::Reader#read.
|
16
|
+
*
|
17
|
+
* The XML::Reader API closely matches the DOM Core specification and supports
|
18
|
+
* namespaces, xml:base, entity handling and DTDs.
|
19
|
+
*
|
20
|
+
* To summarize, XML::Reader provides a far simpler API to use versus XML::SaxParser
|
21
|
+
* and is more memory efficient than using XML::Parser to create a DOM tree.
|
22
|
+
*
|
23
|
+
* Example:
|
24
|
+
*
|
25
|
+
* parser = XML::Reader.new("<foo><bar>1</bar><bar>2</bar><bar>3</bar></foo>")
|
26
|
+
* parser.read
|
27
|
+
* assert_equal('foo', parser.name)
|
28
|
+
* assert_equal(nil, parser.value)
|
29
|
+
*
|
30
|
+
* 3.times do |i|
|
31
|
+
* parser.read
|
32
|
+
* assert_equal(XML::Reader::TYPE_ELEMENT, parser.node_type)
|
33
|
+
* assert_equal('bar', parser.name)
|
34
|
+
* parser.read
|
35
|
+
* assert_equal(XML::Reader::TYPE_TEXT, parser.node_type)
|
36
|
+
* assert_equal((i + 1).to_s, parser.value)
|
37
|
+
* parser.read
|
38
|
+
* assert_equal(XML::Reader::TYPE_END_ELEMENT, parser.node_type)
|
39
|
+
* end
|
40
|
+
*
|
41
|
+
* For a more in depth tutorial, albeit in C, see http://xmlsoft.org/xmlreader.html.*/
|
42
|
+
|
43
|
+
|
44
|
+
static VALUE
|
45
|
+
rxml_reader_new(VALUE class, xmlTextReaderPtr reader)
|
46
|
+
{
|
47
|
+
return Data_Wrap_Struct(class, NULL, xmlFreeTextReader, reader);
|
48
|
+
}
|
49
|
+
|
50
|
+
static xmlTextReaderPtr
|
51
|
+
rxml_text_reader_get(VALUE obj)
|
52
|
+
{
|
53
|
+
xmlTextReaderPtr xreader;
|
54
|
+
Data_Get_Struct(obj, xmlTextReader, xreader);
|
55
|
+
return xreader;
|
56
|
+
}
|
57
|
+
|
58
|
+
/*
|
59
|
+
* call-seq:
|
60
|
+
* XML::Reader.file(path, encoding=nil, options=0) -> reader
|
61
|
+
*
|
62
|
+
* Parse an XML file from the filesystem or the network. The parsing flags
|
63
|
+
* options are a combination of xmlParserOption.
|
64
|
+
*/
|
65
|
+
static VALUE
|
66
|
+
rxml_reader_new_file(int argc, VALUE *argv, VALUE self)
|
67
|
+
{
|
68
|
+
xmlTextReaderPtr xreader;
|
69
|
+
VALUE rpath, rencoding, roptions;
|
70
|
+
char *xpath;
|
71
|
+
char *xencoding;
|
72
|
+
int options;
|
73
|
+
|
74
|
+
rb_scan_args(argc, argv, "12", &rpath, &rencoding, &roptions);
|
75
|
+
|
76
|
+
xpath = NIL_P(rpath) ? NULL : StringValueCStr(rpath);
|
77
|
+
xencoding = NIL_P(rencoding) ? NULL : StringValueCStr(rencoding);
|
78
|
+
options = NIL_P(roptions) ? 0 : FIX2INT(roptions);
|
79
|
+
|
80
|
+
xreader = xmlReaderForFile(xpath, xencoding, options);
|
81
|
+
|
82
|
+
if (xreader == NULL)
|
83
|
+
rxml_raise(&xmlLastError);
|
84
|
+
|
85
|
+
return rxml_reader_new(self, xreader);
|
86
|
+
}
|
87
|
+
|
88
|
+
/*
|
89
|
+
* call-seq:
|
90
|
+
* XML::Reader.io(io, url=nil, encoding=nil, options=0) -> reader
|
91
|
+
*
|
92
|
+
* Parse an XML file from a file handle. The parsing flags options are
|
93
|
+
* a combination of xmlParserOption.
|
94
|
+
*/
|
95
|
+
static VALUE
|
96
|
+
rxml_reader_new_io(int argc, VALUE *argv, VALUE self)
|
97
|
+
{
|
98
|
+
xmlTextReaderPtr xreader;
|
99
|
+
VALUE rio, rurl, rencoding, roptions;
|
100
|
+
char *xurl;
|
101
|
+
char *xencoding;
|
102
|
+
int options;
|
103
|
+
|
104
|
+
rb_scan_args(argc, argv, "13", &rio, &rurl, &rencoding, &roptions);
|
105
|
+
|
106
|
+
xurl = NIL_P(rurl) ? NULL : StringValueCStr(rurl);
|
107
|
+
xencoding = NIL_P(rencoding) ? NULL : StringValueCStr(rencoding);
|
108
|
+
options = NIL_P(roptions) ? 0 : FIX2INT(roptions);
|
109
|
+
|
110
|
+
xreader = xmlReaderForIO((xmlInputReadCallback) rxml_read_callback, NULL,
|
111
|
+
(void *)rio,
|
112
|
+
xurl, xencoding, options);
|
113
|
+
|
114
|
+
if (xreader == NULL)
|
115
|
+
rxml_raise(&xmlLastError);
|
116
|
+
|
117
|
+
return rxml_reader_new(self, xreader);
|
118
|
+
}
|
119
|
+
|
120
|
+
/*
|
121
|
+
* call-seq:
|
122
|
+
* XML::Reader.walker(doc) -> reader
|
123
|
+
* XML::Reader.document(doc) -> reader
|
124
|
+
*
|
125
|
+
* Create an XML text reader for a preparsed document.
|
126
|
+
*/
|
127
|
+
VALUE
|
128
|
+
rxml_reader_new_walker(VALUE self, VALUE doc)
|
129
|
+
{
|
130
|
+
xmlDocPtr xdoc;
|
131
|
+
xmlTextReaderPtr xreader;
|
132
|
+
|
133
|
+
Data_Get_Struct(doc, xmlDoc, xdoc);
|
134
|
+
|
135
|
+
xreader = xmlReaderWalker(xdoc);
|
136
|
+
|
137
|
+
if (xreader == NULL)
|
138
|
+
rxml_raise(&xmlLastError);
|
139
|
+
|
140
|
+
return rxml_reader_new(self, xreader);
|
141
|
+
}
|
142
|
+
|
143
|
+
/*
|
144
|
+
* call-seq:
|
145
|
+
* XML::Reader.new(data, url=nil, encoding=nil, options=0) -> reader
|
146
|
+
* XML::Reader.string(data, url=nil, encoding=nil, options=0) -> reader
|
147
|
+
*
|
148
|
+
* Create an XML text reader for an XML in-memory document. The parsing flags
|
149
|
+
* options are a combination of xmlParserOption.
|
150
|
+
*/
|
151
|
+
static VALUE
|
152
|
+
rxml_reader_new_data(int argc, VALUE *argv, VALUE self)
|
153
|
+
{
|
154
|
+
xmlTextReaderPtr xreader;
|
155
|
+
VALUE rdata, rurl, rencoding, roptions;
|
156
|
+
char *xdata;
|
157
|
+
char *xurl;
|
158
|
+
char *xencoding;
|
159
|
+
int options;
|
160
|
+
|
161
|
+
rb_scan_args(argc, argv, "13", &rdata, &rurl, &rencoding, &roptions);
|
162
|
+
|
163
|
+
xdata = NIL_P(rdata) ? NULL : StringValueCStr(rdata);
|
164
|
+
xurl = NIL_P(rurl) ? NULL : StringValueCStr(rurl);
|
165
|
+
xencoding = NIL_P(rencoding) ? NULL : StringValueCStr(rencoding);
|
166
|
+
options = NIL_P(roptions) ? 0 : FIX2INT(roptions);
|
167
|
+
|
168
|
+
xreader = xmlReaderForMemory(xdata, strlen(xdata),
|
169
|
+
xurl, xencoding, options);
|
170
|
+
|
171
|
+
if (xreader == NULL)
|
172
|
+
rxml_raise(&xmlLastError);
|
173
|
+
|
174
|
+
return rxml_reader_new(self, xreader);
|
175
|
+
}
|
176
|
+
|
177
|
+
/*
|
178
|
+
* call-seq:
|
179
|
+
* parser.close -> code
|
180
|
+
*
|
181
|
+
* This method releases any resources allocated by the current instance
|
182
|
+
* changes the state to Closed and close any underlying input.
|
183
|
+
*/
|
184
|
+
static VALUE
|
185
|
+
rxml_reader_close(VALUE self)
|
186
|
+
{
|
187
|
+
return INT2FIX(xmlTextReaderClose(rxml_text_reader_get(self)));
|
188
|
+
}
|
189
|
+
|
190
|
+
/*
|
191
|
+
* call-seq:
|
192
|
+
* parser.move_to_attribute(val) -> code
|
193
|
+
*
|
194
|
+
* Move the position of the current instance to the attribute with the
|
195
|
+
* specified index (if +val+ is an integer) or name (if +val+ is a string)
|
196
|
+
* relative to the containing element.
|
197
|
+
*/
|
198
|
+
static VALUE
|
199
|
+
rxml_reader_move_to_attr(VALUE self, VALUE val)
|
200
|
+
{
|
201
|
+
xmlTextReaderPtr xreader;
|
202
|
+
int ret;
|
203
|
+
|
204
|
+
xreader = rxml_text_reader_get(self);
|
205
|
+
|
206
|
+
if (TYPE(val) == T_FIXNUM) {
|
207
|
+
ret = xmlTextReaderMoveToAttributeNo(xreader, FIX2INT(val));
|
208
|
+
}
|
209
|
+
else {
|
210
|
+
ret = xmlTextReaderMoveToAttribute(xreader, (const xmlChar *)StringValueCStr(val));
|
211
|
+
}
|
212
|
+
|
213
|
+
return INT2FIX(ret);
|
214
|
+
}
|
215
|
+
|
216
|
+
/*
|
217
|
+
* call-seq:
|
218
|
+
* reader.move_to_first_attribute -> code
|
219
|
+
*
|
220
|
+
* Move the position of the current instance to the first attribute associated
|
221
|
+
* with the current node.
|
222
|
+
*/
|
223
|
+
static VALUE
|
224
|
+
rxml_reader_move_to_first_attr(VALUE self)
|
225
|
+
{
|
226
|
+
return INT2FIX(xmlTextReaderMoveToFirstAttribute(rxml_text_reader_get(self)));
|
227
|
+
}
|
228
|
+
|
229
|
+
/*
|
230
|
+
* call-seq:
|
231
|
+
* reader.move_to_next_attribute -> code
|
232
|
+
*
|
233
|
+
* Move the position of the current instance to the next attribute associated
|
234
|
+
* with the current node.
|
235
|
+
*/
|
236
|
+
static VALUE
|
237
|
+
rxml_reader_move_to_next_attr(VALUE self)
|
238
|
+
{
|
239
|
+
return INT2FIX(xmlTextReaderMoveToNextAttribute(rxml_text_reader_get(self)));
|
240
|
+
}
|
241
|
+
|
242
|
+
/*
|
243
|
+
* call-seq:
|
244
|
+
* reader.move_to_element -> code
|
245
|
+
*
|
246
|
+
* Move the position of the current instance to the node that contains the
|
247
|
+
* current attribute node.
|
248
|
+
*/
|
249
|
+
static VALUE
|
250
|
+
rxml_reader_move_to_element(VALUE self)
|
251
|
+
{
|
252
|
+
return INT2FIX(xmlTextReaderMoveToElement(rxml_text_reader_get(self)));
|
253
|
+
}
|
254
|
+
|
255
|
+
/*
|
256
|
+
* call-seq:
|
257
|
+
* reader.next -> code
|
258
|
+
*
|
259
|
+
* Skip to the node following the current one in document order while avoiding
|
260
|
+
* the subtree if any.
|
261
|
+
*/
|
262
|
+
static VALUE
|
263
|
+
rxml_reader_next(VALUE self)
|
264
|
+
{
|
265
|
+
return INT2FIX(xmlTextReaderNext(rxml_text_reader_get(self)));
|
266
|
+
}
|
267
|
+
|
268
|
+
/*
|
269
|
+
* call-seq:
|
270
|
+
* reader.next_sibling -> code
|
271
|
+
*
|
272
|
+
* Skip to the node following the current one in document order while avoiding
|
273
|
+
* the subtree if any. Currently implemented only for Readers built on a
|
274
|
+
* document.
|
275
|
+
*/
|
276
|
+
static VALUE
|
277
|
+
rxml_reader_next_sibling(VALUE self)
|
278
|
+
{
|
279
|
+
return INT2FIX(xmlTextReaderNextSibling(rxml_text_reader_get(self)));
|
280
|
+
}
|
281
|
+
|
282
|
+
/*
|
283
|
+
* call-seq:
|
284
|
+
* reader.node_type -> type
|
285
|
+
*
|
286
|
+
* Get the node type of the current node. Reference:
|
287
|
+
* http://dotgnu.org/pnetlib-doc/System/Xml/XmlNodeType.html
|
288
|
+
*/
|
289
|
+
static VALUE
|
290
|
+
rxml_reader_node_type(VALUE self)
|
291
|
+
{
|
292
|
+
return INT2FIX(xmlTextReaderNodeType(rxml_text_reader_get(self)));
|
293
|
+
}
|
294
|
+
|
295
|
+
/*
|
296
|
+
* call-seq:
|
297
|
+
* reader.normalization -> value
|
298
|
+
*
|
299
|
+
* The value indicating whether to normalize white space and attribute values.
|
300
|
+
* Since attribute value and end of line normalizations are a MUST in the XML
|
301
|
+
* specification only the value true is accepted. The broken bahaviour of
|
302
|
+
* accepting out of range character entities like � is of course not
|
303
|
+
* supported either.
|
304
|
+
*
|
305
|
+
* Return 1 or -1 in case of error.
|
306
|
+
*/
|
307
|
+
static VALUE
|
308
|
+
rxml_reader_normalization(VALUE self)
|
309
|
+
{
|
310
|
+
return INT2FIX(xmlTextReaderNormalization(rxml_text_reader_get(self)));
|
311
|
+
}
|
312
|
+
|
313
|
+
/*
|
314
|
+
* call-seq:
|
315
|
+
* reader.read -> code
|
316
|
+
*
|
317
|
+
* Move the position of the current instance to the next node in the stream,
|
318
|
+
* exposing its properties.
|
319
|
+
*
|
320
|
+
* Return 1 if the node was read successfully, 0 if there is no more nodes to
|
321
|
+
* read, or -1 in case of error.
|
322
|
+
*/
|
323
|
+
static VALUE
|
324
|
+
rxml_reader_read(VALUE self)
|
325
|
+
{
|
326
|
+
return INT2FIX(xmlTextReaderRead(rxml_text_reader_get(self)));
|
327
|
+
}
|
328
|
+
|
329
|
+
/*
|
330
|
+
* call-seq:
|
331
|
+
* reader.read_attribute_value -> code
|
332
|
+
*
|
333
|
+
* Parse an attribute value into one or more Text and EntityReference nodes.
|
334
|
+
*
|
335
|
+
* Return 1 in case of success, 0 if the reader was not positionned on an
|
336
|
+
* attribute node or all the attribute values have been read, or -1 in case of
|
337
|
+
* error.
|
338
|
+
*/
|
339
|
+
static VALUE
|
340
|
+
rxml_reader_read_attr_value(VALUE self)
|
341
|
+
{
|
342
|
+
return INT2FIX(xmlTextReaderReadAttributeValue(rxml_text_reader_get(self)));
|
343
|
+
}
|
344
|
+
|
345
|
+
/*
|
346
|
+
* call-seq:
|
347
|
+
* reader.read_inner_xml -> data
|
348
|
+
*
|
349
|
+
* Read the contents of the current node, including child nodes and markup.
|
350
|
+
*
|
351
|
+
* Return a string containing the XML content, or nil if the current node is
|
352
|
+
* neither an element nor attribute, or has no child nodes.
|
353
|
+
*/
|
354
|
+
static VALUE
|
355
|
+
rxml_reader_read_inner_xml(VALUE self)
|
356
|
+
{
|
357
|
+
const xmlChar *result = xmlTextReaderReadInnerXml(rxml_text_reader_get(self));
|
358
|
+
return (result == NULL ? Qnil : rb_str_new2(result));
|
359
|
+
}
|
360
|
+
|
361
|
+
/*
|
362
|
+
* call-seq:
|
363
|
+
* reader.read_outer_xml -> data
|
364
|
+
*
|
365
|
+
* Read the contents of the current node, including child nodes and markup.
|
366
|
+
*
|
367
|
+
* Return a string containing the XML content, or nil if the current node is
|
368
|
+
* neither an element nor attribute, or has no child nodes.
|
369
|
+
*/
|
370
|
+
static VALUE
|
371
|
+
rxml_reader_read_outer_xml(VALUE self)
|
372
|
+
{
|
373
|
+
const xmlChar *result = xmlTextReaderReadOuterXml(rxml_text_reader_get(self));
|
374
|
+
return (result == NULL ? Qnil : rb_str_new2(result));
|
375
|
+
}
|
376
|
+
|
377
|
+
/*
|
378
|
+
* call-seq:
|
379
|
+
* reader.read_state -> state
|
380
|
+
*
|
381
|
+
* Get the read state of the reader.
|
382
|
+
*/
|
383
|
+
static VALUE
|
384
|
+
rxml_reader_read_state(VALUE self)
|
385
|
+
{
|
386
|
+
return INT2FIX(xmlTextReaderReadState(rxml_text_reader_get(self)));
|
387
|
+
}
|
388
|
+
|
389
|
+
/*
|
390
|
+
* call-seq:
|
391
|
+
* reader.read_string -> string
|
392
|
+
*
|
393
|
+
* Read the contents of an element or a text node as a string.
|
394
|
+
*
|
395
|
+
* Return a string containing the contents of the Element or Text node, or nil
|
396
|
+
* if the reader is positioned on any other type of node.
|
397
|
+
*/
|
398
|
+
static VALUE
|
399
|
+
rxml_reader_read_string(VALUE self)
|
400
|
+
{
|
401
|
+
const xmlChar *result = xmlTextReaderReadString(rxml_text_reader_get(self));
|
402
|
+
return (result == NULL ? Qnil : rb_str_new2(result));
|
403
|
+
}
|
404
|
+
|
405
|
+
/*
|
406
|
+
* call-seq:
|
407
|
+
* reader.relax_ng_validate(rng) -> code
|
408
|
+
*
|
409
|
+
* Use RelaxNG to validate the document as it is processed. Activation is only
|
410
|
+
* possible before the first read. If +rng+ is nil, the RelaxNG validation is
|
411
|
+
* desactivated.
|
412
|
+
*
|
413
|
+
* Return 0 in case the RelaxNG validation could be (des)activated and -1 in
|
414
|
+
* case of error.
|
415
|
+
*/
|
416
|
+
static VALUE
|
417
|
+
rxml_reader_relax_ng_validate(VALUE self, VALUE rng)
|
418
|
+
{
|
419
|
+
char *xrng = NIL_P(rng) ? NULL : StringValueCStr(rng);
|
420
|
+
return INT2FIX(xmlTextReaderRelaxNGValidate(rxml_text_reader_get(self), xrng));
|
421
|
+
}
|
422
|
+
|
423
|
+
#if LIBXML_VERSION >= 20620
|
424
|
+
/*
|
425
|
+
* call-seq:
|
426
|
+
* reader.schema_validate(schema) -> code
|
427
|
+
*
|
428
|
+
* Use W3C XSD schema to validate the document as it is processed. Activation
|
429
|
+
* is only possible before the first read. If +schema+ is nil, then XML Schema
|
430
|
+
* validation is desactivated.
|
431
|
+
*
|
432
|
+
* Return 0 in case the schemas validation could be (de)activated and -1 in
|
433
|
+
* case of error.
|
434
|
+
*/
|
435
|
+
static VALUE
|
436
|
+
rxml_reader_schema_validate(VALUE self, VALUE xsd)
|
437
|
+
{
|
438
|
+
char *xxsd = NIL_P(xsd) ? NULL : StringValueCStr(xsd);
|
439
|
+
int status = xmlTextReaderSchemaValidate(rxml_text_reader_get(self), xxsd);
|
440
|
+
return INT2FIX(status);
|
441
|
+
}
|
442
|
+
#endif
|
443
|
+
|
444
|
+
/*
|
445
|
+
* call-seq:
|
446
|
+
* reader.name -> name
|
447
|
+
*
|
448
|
+
* Return the qualified name of the node.
|
449
|
+
*/
|
450
|
+
static VALUE
|
451
|
+
rxml_reader_name(VALUE self)
|
452
|
+
{
|
453
|
+
const xmlChar *result = xmlTextReaderConstName(rxml_text_reader_get(self));
|
454
|
+
return (result == NULL ? Qnil : rb_str_new2(result));
|
455
|
+
}
|
456
|
+
|
457
|
+
/*
|
458
|
+
* call-seq:
|
459
|
+
* reader.local_name -> name
|
460
|
+
*
|
461
|
+
* Return the local name of the node.
|
462
|
+
*/
|
463
|
+
static VALUE
|
464
|
+
rxml_reader_local_name(VALUE self)
|
465
|
+
{
|
466
|
+
const xmlChar *result = xmlTextReaderConstLocalName(rxml_text_reader_get(self));
|
467
|
+
return (result == NULL ? Qnil : rb_str_new2(result));
|
468
|
+
}
|
469
|
+
|
470
|
+
/*
|
471
|
+
* call-seq:
|
472
|
+
* reader.attribute_count -> count
|
473
|
+
*
|
474
|
+
* Provide the number of attributes of the current node.
|
475
|
+
*/
|
476
|
+
static VALUE
|
477
|
+
rxml_reader_attr_count(VALUE self)
|
478
|
+
{
|
479
|
+
return INT2FIX(xmlTextReaderAttributeCount(rxml_text_reader_get(self)));
|
480
|
+
}
|
481
|
+
|
482
|
+
/*
|
483
|
+
* call-seq:
|
484
|
+
* reader.encoding -> encoding
|
485
|
+
*
|
486
|
+
* Determine the encoding of the document being read.
|
487
|
+
*/
|
488
|
+
static VALUE
|
489
|
+
rxml_reader_encoding(VALUE self)
|
490
|
+
{
|
491
|
+
const xmlChar *result = xmlTextReaderConstEncoding(rxml_text_reader_get(self));
|
492
|
+
return (result == NULL ? Qnil : rb_str_new2(result));
|
493
|
+
}
|
494
|
+
|
495
|
+
/*
|
496
|
+
* call-seq:
|
497
|
+
* reader.base_uri -> URI
|
498
|
+
*
|
499
|
+
* Determine the base URI of the node.
|
500
|
+
*/
|
501
|
+
static VALUE
|
502
|
+
rxml_reader_base_uri(VALUE self)
|
503
|
+
{
|
504
|
+
const xmlChar *result = xmlTextReaderConstBaseUri(rxml_text_reader_get(self));
|
505
|
+
return (result == NULL ? Qnil : rb_str_new2(result));
|
506
|
+
}
|
507
|
+
|
508
|
+
/*
|
509
|
+
* call-seq:
|
510
|
+
* reader.namespace_uri -> URI
|
511
|
+
*
|
512
|
+
* Determine the namespace URI of the node.
|
513
|
+
*/
|
514
|
+
static VALUE
|
515
|
+
rxml_reader_namespace_uri(VALUE self)
|
516
|
+
{
|
517
|
+
const xmlChar *result = xmlTextReaderConstNamespaceUri(rxml_text_reader_get(self));
|
518
|
+
return (result == NULL ? Qnil : rb_str_new2(result));
|
519
|
+
}
|
520
|
+
|
521
|
+
/*
|
522
|
+
* call-seq:
|
523
|
+
* reader.value -> text
|
524
|
+
*
|
525
|
+
* Provide the text value of the node if present.
|
526
|
+
*/
|
527
|
+
static VALUE
|
528
|
+
rxml_reader_value(VALUE self)
|
529
|
+
{
|
530
|
+
const xmlChar *result = xmlTextReaderConstValue(rxml_text_reader_get(self));
|
531
|
+
return (result == NULL ? Qnil : rb_str_new2(result));
|
532
|
+
}
|
533
|
+
|
534
|
+
/*
|
535
|
+
* call-seq:
|
536
|
+
* reader.prefix -> prefix
|
537
|
+
*
|
538
|
+
* Get a shorthand reference to the namespace associated with the node.
|
539
|
+
*/
|
540
|
+
static VALUE
|
541
|
+
rxml_reader_prefix(VALUE self)
|
542
|
+
{
|
543
|
+
const xmlChar *result = xmlTextReaderConstPrefix(rxml_text_reader_get(self));
|
544
|
+
return (result == NULL ? Qnil : rb_str_new2(result));
|
545
|
+
}
|
546
|
+
|
547
|
+
/*
|
548
|
+
* call-seq:
|
549
|
+
* reader.depth -> depth
|
550
|
+
*
|
551
|
+
* Get the depth of the node in the tree.
|
552
|
+
*/
|
553
|
+
static VALUE
|
554
|
+
rxml_reader_depth(VALUE self)
|
555
|
+
{
|
556
|
+
return INT2FIX(xmlTextReaderDepth(rxml_text_reader_get(self)));
|
557
|
+
}
|
558
|
+
|
559
|
+
/*
|
560
|
+
* call-seq:
|
561
|
+
* reader.quote_char -> char
|
562
|
+
*
|
563
|
+
* Get the quotation mark character used to enclose the value of an attribute,
|
564
|
+
* as an integer value (and -1 in case of error).
|
565
|
+
*/
|
566
|
+
static VALUE
|
567
|
+
rxml_reader_quote_char(VALUE self)
|
568
|
+
{
|
569
|
+
return INT2FIX(xmlTextReaderQuoteChar(rxml_text_reader_get(self)));
|
570
|
+
}
|
571
|
+
|
572
|
+
/*
|
573
|
+
* call-seq:
|
574
|
+
* reader.standalone -> code
|
575
|
+
*
|
576
|
+
* Determine the standalone status of the document being read.
|
577
|
+
*
|
578
|
+
* Return 1 if the document was declared to be standalone, 0 if it was
|
579
|
+
* declared to be not standalone, or -1 if the document did not specify its
|
580
|
+
* standalone status or in case of error.
|
581
|
+
*/
|
582
|
+
static VALUE
|
583
|
+
rxml_reader_standalone(VALUE self)
|
584
|
+
{
|
585
|
+
return INT2FIX(xmlTextReaderStandalone(rxml_text_reader_get(self)));
|
586
|
+
}
|
587
|
+
|
588
|
+
/*
|
589
|
+
* call-seq:
|
590
|
+
* reader.xml_lang -> value
|
591
|
+
*
|
592
|
+
* Get the xml:lang scope within which the node resides.
|
593
|
+
*/
|
594
|
+
static VALUE
|
595
|
+
rxml_reader_xml_lang(VALUE self)
|
596
|
+
{
|
597
|
+
const xmlChar *result = xmlTextReaderConstXmlLang(rxml_text_reader_get(self));
|
598
|
+
return (result == NULL ? Qnil : rb_str_new2(result));
|
599
|
+
}
|
600
|
+
|
601
|
+
/*
|
602
|
+
* call-seq:
|
603
|
+
* reader.xml_version -> version
|
604
|
+
*
|
605
|
+
* Determine the XML version of the document being read.
|
606
|
+
*/
|
607
|
+
static VALUE
|
608
|
+
rxml_reader_xml_version(VALUE self)
|
609
|
+
{
|
610
|
+
const xmlChar *result = xmlTextReaderConstXmlVersion(rxml_text_reader_get(self));
|
611
|
+
return (result == NULL ? Qnil : rb_str_new2(result));
|
612
|
+
}
|
613
|
+
|
614
|
+
/*
|
615
|
+
* call-seq:
|
616
|
+
* reader.has_attributes? -> bool
|
617
|
+
*
|
618
|
+
* Get whether the node has attributes.
|
619
|
+
*/
|
620
|
+
static VALUE
|
621
|
+
rxml_reader_has_attributes(VALUE self)
|
622
|
+
{
|
623
|
+
return xmlTextReaderHasAttributes(rxml_text_reader_get(self)) ? Qtrue : Qfalse;
|
624
|
+
}
|
625
|
+
|
626
|
+
/*
|
627
|
+
* call-seq:
|
628
|
+
* reader.has_value? -> bool
|
629
|
+
*
|
630
|
+
* Get whether the node can have a text value.
|
631
|
+
*/
|
632
|
+
static VALUE
|
633
|
+
rxml_reader_has_value(VALUE self)
|
634
|
+
{
|
635
|
+
return xmlTextReaderHasValue(rxml_text_reader_get(self)) ? Qtrue : Qfalse;
|
636
|
+
}
|
637
|
+
|
638
|
+
/*
|
639
|
+
* call-seq:
|
640
|
+
* reader[key] -> value
|
641
|
+
*
|
642
|
+
* Provide the value of the attribute with the specified index (if +key+ is an
|
643
|
+
* integer) or with the specified name (if +key+ is a string) relative to the
|
644
|
+
* containing element, as a string.
|
645
|
+
*/
|
646
|
+
static VALUE
|
647
|
+
rxml_reader_attribute(VALUE self, VALUE key)
|
648
|
+
{
|
649
|
+
xmlTextReaderPtr reader;
|
650
|
+
xmlChar *attr;
|
651
|
+
|
652
|
+
reader = rxml_text_reader_get(self);
|
653
|
+
|
654
|
+
if (TYPE(key) == T_FIXNUM) {
|
655
|
+
attr = xmlTextReaderGetAttributeNo(reader, FIX2INT(key));
|
656
|
+
}
|
657
|
+
else {
|
658
|
+
attr = xmlTextReaderGetAttribute(reader, (const xmlChar *)StringValueCStr(key));
|
659
|
+
}
|
660
|
+
return (attr == NULL ? Qnil : rb_str_new2(attr));
|
661
|
+
}
|
662
|
+
|
663
|
+
/*
|
664
|
+
* call-seq:
|
665
|
+
* reader.lookup_namespace(prefix) -> value
|
666
|
+
*
|
667
|
+
* Resolve a namespace prefix in the scope of the current element.
|
668
|
+
* To return the default namespace, specify nil as +prefix+.
|
669
|
+
*/
|
670
|
+
static VALUE
|
671
|
+
rxml_reader_lookup_namespace(VALUE self, VALUE prefix)
|
672
|
+
{
|
673
|
+
const xmlChar *result = xmlTextReaderLookupNamespace(rxml_text_reader_get(self), (const xmlChar *)StringValueCStr(prefix));
|
674
|
+
return (result == NULL ? Qnil : rb_str_new2(result));
|
675
|
+
}
|
676
|
+
|
677
|
+
/*
|
678
|
+
* call-seq:
|
679
|
+
* reader.expand -> node
|
680
|
+
*
|
681
|
+
* Read the contents of the current node and the full subtree. It then makes
|
682
|
+
* the subtree available until the next read call.
|
683
|
+
*
|
684
|
+
* Return an XML::Node object, or nil in case of error.
|
685
|
+
*/
|
686
|
+
static VALUE
|
687
|
+
rxml_reader_expand(VALUE self)
|
688
|
+
{
|
689
|
+
xmlNodePtr node;
|
690
|
+
xmlDocPtr doc;
|
691
|
+
xmlTextReaderPtr reader = rxml_text_reader_get(self);
|
692
|
+
node = xmlTextReaderExpand(reader);
|
693
|
+
|
694
|
+
if (!node)
|
695
|
+
return Qnil;
|
696
|
+
|
697
|
+
/* Okay this is tricky. By accessing the returned node, we
|
698
|
+
take ownership of the reader's document. Thus we need to
|
699
|
+
tell the reader to not free it. Otherwise it will be
|
700
|
+
freed twice - once when the Ruby document wrapper goes
|
701
|
+
out of scope and once when the reader goes out of scope. */
|
702
|
+
|
703
|
+
xmlTextReaderPreserve(reader);
|
704
|
+
doc = xmlTextReaderCurrentDoc(reader);
|
705
|
+
rxml_document_wrap(doc);
|
706
|
+
|
707
|
+
return rxml_node2_wrap(cXMLNode, node);
|
708
|
+
}
|
709
|
+
|
710
|
+
#if LIBXML_VERSION >= 20618
|
711
|
+
/*
|
712
|
+
* call-seq:
|
713
|
+
* reader.byte_consumed -> value
|
714
|
+
*
|
715
|
+
* This method provides the current index of the parser used by the reader,
|
716
|
+
* relative to the start of the current entity.
|
717
|
+
*/
|
718
|
+
static VALUE
|
719
|
+
rxml_reader_byte_consumed(VALUE self)
|
720
|
+
{
|
721
|
+
return INT2NUM(xmlTextReaderByteConsumed(rxml_text_reader_get(self)));
|
722
|
+
}
|
723
|
+
#endif
|
724
|
+
|
725
|
+
#if LIBXML_VERSION >= 20617
|
726
|
+
/*
|
727
|
+
* call-seq:
|
728
|
+
* reader.column_number -> number
|
729
|
+
*
|
730
|
+
* Provide the column number of the current parsing point.
|
731
|
+
*/
|
732
|
+
static VALUE
|
733
|
+
rxml_reader_column_number(VALUE self)
|
734
|
+
{
|
735
|
+
return INT2NUM(xmlTextReaderGetParserColumnNumber(rxml_text_reader_get(self)));
|
736
|
+
}
|
737
|
+
|
738
|
+
/*
|
739
|
+
* call-seq:
|
740
|
+
* reader.line_number -> number
|
741
|
+
*
|
742
|
+
* Provide the line number of the current parsing point.
|
743
|
+
*/
|
744
|
+
static VALUE
|
745
|
+
rxml_reader_line_number(VALUE self)
|
746
|
+
{
|
747
|
+
return INT2NUM(xmlTextReaderGetParserLineNumber(rxml_text_reader_get(self)));
|
748
|
+
}
|
749
|
+
#endif
|
750
|
+
|
751
|
+
/*
|
752
|
+
* call-seq:
|
753
|
+
* reader.default? -> bool
|
754
|
+
*
|
755
|
+
* Return whether an Attribute node was generated from the default value
|
756
|
+
* defined in the DTD or schema.
|
757
|
+
*/
|
758
|
+
static VALUE
|
759
|
+
rxml_reader_default(VALUE self)
|
760
|
+
{
|
761
|
+
return xmlTextReaderIsDefault(rxml_text_reader_get(self)) ? Qtrue : Qfalse;
|
762
|
+
}
|
763
|
+
|
764
|
+
/*
|
765
|
+
* call-seq:
|
766
|
+
* reader.namespace_declaration? -> bool
|
767
|
+
*
|
768
|
+
* Determine whether the current node is a namespace declaration rather than a
|
769
|
+
* regular attribute.
|
770
|
+
*/
|
771
|
+
static VALUE
|
772
|
+
rxml_reader_namespace_declaration(VALUE self)
|
773
|
+
{
|
774
|
+
return xmlTextReaderIsNamespaceDecl(rxml_text_reader_get(self)) ? Qtrue : Qfalse;
|
775
|
+
}
|
776
|
+
|
777
|
+
/*
|
778
|
+
* call-seq:
|
779
|
+
* reader.empty_element? -> bool
|
780
|
+
*
|
781
|
+
* Check if the current node is empty.
|
782
|
+
*/
|
783
|
+
static VALUE
|
784
|
+
rxml_reader_empty_element(VALUE self)
|
785
|
+
{
|
786
|
+
return xmlTextReaderIsEmptyElement(rxml_text_reader_get(self)) ? Qtrue : Qfalse;
|
787
|
+
}
|
788
|
+
|
789
|
+
/*
|
790
|
+
* call-seq:
|
791
|
+
* reader.valid? -> bool
|
792
|
+
*
|
793
|
+
* Retrieve the validity status from the parser context.
|
794
|
+
*/
|
795
|
+
static VALUE
|
796
|
+
rxml_reader_valid(VALUE self)
|
797
|
+
{
|
798
|
+
return xmlTextReaderIsValid(rxml_text_reader_get(self)) ? Qtrue : Qfalse;
|
799
|
+
}
|
800
|
+
|
801
|
+
/* Rdoc needs to know. */
|
802
|
+
#ifdef RDOC_NEVER_DEFINED
|
803
|
+
mLibXML = rb_define_module("LibXML");
|
804
|
+
mXML = rb_define_module_under(mLibXML, "XML");
|
805
|
+
#endif
|
806
|
+
|
807
|
+
void
|
808
|
+
ruby_init_xml_reader(void)
|
809
|
+
{
|
810
|
+
cXMLReader = rb_define_class_under(mXML, "Reader", rb_cObject);
|
811
|
+
|
812
|
+
rb_define_singleton_method(cXMLReader, "file", rxml_reader_new_file, -1);
|
813
|
+
rb_define_singleton_method(cXMLReader, "io", rxml_reader_new_io, -1);
|
814
|
+
rb_define_singleton_method(cXMLReader, "walker", rxml_reader_new_walker, 1);
|
815
|
+
rb_define_alias(CLASS_OF(cXMLReader), "document", "walker");
|
816
|
+
rb_define_singleton_method(cXMLReader, "new", rxml_reader_new_data, -1);
|
817
|
+
rb_define_alias(CLASS_OF(cXMLReader), "string", "new");
|
818
|
+
|
819
|
+
rb_define_method(cXMLReader, "close", rxml_reader_close, 0);
|
820
|
+
|
821
|
+
rb_define_method(cXMLReader, "move_to_attribute", rxml_reader_move_to_attr, 1);
|
822
|
+
rb_define_method(cXMLReader, "move_to_first_attribute", rxml_reader_move_to_first_attr, 0);
|
823
|
+
rb_define_method(cXMLReader, "move_to_next_attribute", rxml_reader_move_to_next_attr, 0);
|
824
|
+
rb_define_method(cXMLReader, "move_to_element", rxml_reader_move_to_element, 0);
|
825
|
+
rb_define_method(cXMLReader, "next", rxml_reader_next, 0);
|
826
|
+
rb_define_method(cXMLReader, "next_sibling", rxml_reader_next_sibling, 0);
|
827
|
+
rb_define_method(cXMLReader, "read", rxml_reader_read, 0);
|
828
|
+
rb_define_method(cXMLReader, "read_attribute_value", rxml_reader_read_attr_value, 0);
|
829
|
+
rb_define_method(cXMLReader, "read_inner_xml", rxml_reader_read_inner_xml, 0);
|
830
|
+
rb_define_method(cXMLReader, "read_outer_xml", rxml_reader_read_outer_xml, 0);
|
831
|
+
rb_define_method(cXMLReader, "read_state", rxml_reader_read_state, 0);
|
832
|
+
rb_define_method(cXMLReader, "read_string", rxml_reader_read_string, 0);
|
833
|
+
|
834
|
+
rb_define_method(cXMLReader, "relax_ng_validate", rxml_reader_relax_ng_validate, 1);
|
835
|
+
#if LIBXML_VERSION >= 20620
|
836
|
+
rb_define_method(cXMLReader, "schema_validate", rxml_reader_schema_validate, 1);
|
837
|
+
#endif
|
838
|
+
|
839
|
+
rb_define_method(cXMLReader, "node_type", rxml_reader_node_type, 0);
|
840
|
+
rb_define_method(cXMLReader, "normalization", rxml_reader_normalization, 0);
|
841
|
+
rb_define_method(cXMLReader, "attribute_count", rxml_reader_attr_count, 0);
|
842
|
+
rb_define_method(cXMLReader, "name", rxml_reader_name, 0);
|
843
|
+
rb_define_method(cXMLReader, "local_name", rxml_reader_local_name, 0);
|
844
|
+
rb_define_method(cXMLReader, "encoding", rxml_reader_encoding, 0);
|
845
|
+
rb_define_method(cXMLReader, "base_uri", rxml_reader_base_uri, 0);
|
846
|
+
rb_define_method(cXMLReader, "namespace_uri", rxml_reader_namespace_uri, 0);
|
847
|
+
rb_define_method(cXMLReader, "xml_lang", rxml_reader_xml_lang, 0);
|
848
|
+
rb_define_method(cXMLReader, "xml_version", rxml_reader_xml_version, 0);
|
849
|
+
rb_define_method(cXMLReader, "prefix", rxml_reader_prefix, 0);
|
850
|
+
rb_define_method(cXMLReader, "depth", rxml_reader_depth, 0);
|
851
|
+
rb_define_method(cXMLReader, "quote_char", rxml_reader_quote_char, 0);
|
852
|
+
rb_define_method(cXMLReader, "standalone", rxml_reader_standalone, 0);
|
853
|
+
|
854
|
+
rb_define_method(cXMLReader, "has_attributes?", rxml_reader_has_attributes, 0);
|
855
|
+
rb_define_method(cXMLReader, "[]", rxml_reader_attribute, 1);
|
856
|
+
rb_define_method(cXMLReader, "has_value?", rxml_reader_has_value, 0);
|
857
|
+
rb_define_method(cXMLReader, "value", rxml_reader_value, 0);
|
858
|
+
|
859
|
+
rb_define_method(cXMLReader, "lookup_namespace", rxml_reader_lookup_namespace, 1);
|
860
|
+
rb_define_method(cXMLReader, "expand", rxml_reader_expand, 0);
|
861
|
+
|
862
|
+
#if LIBXML_VERSION >= 20618
|
863
|
+
rb_define_method(cXMLReader, "byte_consumed", rxml_reader_byte_consumed, 0);
|
864
|
+
#endif
|
865
|
+
#if LIBXML_VERSION >= 20617
|
866
|
+
rb_define_method(cXMLReader, "column_number", rxml_reader_column_number, 0);
|
867
|
+
rb_define_method(cXMLReader, "line_number", rxml_reader_line_number, 0);
|
868
|
+
#endif
|
869
|
+
rb_define_method(cXMLReader, "default?", rxml_reader_default, 0);
|
870
|
+
rb_define_method(cXMLReader, "empty_element?", rxml_reader_empty_element, 0);
|
871
|
+
rb_define_method(cXMLReader, "namespace_declaration?", rxml_reader_namespace_declaration, 0);
|
872
|
+
rb_define_method(cXMLReader, "valid?", rxml_reader_valid, 0);
|
873
|
+
|
874
|
+
rb_define_const(cXMLReader, "LOADDTD", INT2FIX(XML_PARSER_LOADDTD));
|
875
|
+
rb_define_const(cXMLReader, "DEFAULTATTRS", INT2FIX(XML_PARSER_DEFAULTATTRS));
|
876
|
+
rb_define_const(cXMLReader, "VALIDATE", INT2FIX(XML_PARSER_VALIDATE));
|
877
|
+
rb_define_const(cXMLReader, "SUBST_ENTITIES", INT2FIX(XML_PARSER_SUBST_ENTITIES));
|
878
|
+
|
879
|
+
rb_define_const(cXMLReader, "SEVERITY_VALIDITY_WARNING", INT2FIX(XML_PARSER_SEVERITY_VALIDITY_WARNING));
|
880
|
+
rb_define_const(cXMLReader, "SEVERITY_VALIDITY_ERROR", INT2FIX(XML_PARSER_SEVERITY_VALIDITY_ERROR));
|
881
|
+
rb_define_const(cXMLReader, "SEVERITY_WARNING", INT2FIX(XML_PARSER_SEVERITY_WARNING));
|
882
|
+
rb_define_const(cXMLReader, "SEVERITY_ERROR", INT2FIX(XML_PARSER_SEVERITY_ERROR));
|
883
|
+
|
884
|
+
rb_define_const(cXMLReader, "TYPE_NONE", INT2FIX(XML_READER_TYPE_NONE));
|
885
|
+
rb_define_const(cXMLReader, "TYPE_ELEMENT", INT2FIX(XML_READER_TYPE_ELEMENT));
|
886
|
+
rb_define_const(cXMLReader, "TYPE_ATTRIBUTE", INT2FIX(XML_READER_TYPE_ATTRIBUTE));
|
887
|
+
rb_define_const(cXMLReader, "TYPE_TEXT", INT2FIX(XML_READER_TYPE_TEXT));
|
888
|
+
rb_define_const(cXMLReader, "TYPE_CDATA", INT2FIX(XML_READER_TYPE_CDATA));
|
889
|
+
rb_define_const(cXMLReader, "TYPE_ENTITY_REFERENCE", INT2FIX(XML_READER_TYPE_ENTITY_REFERENCE));
|
890
|
+
rb_define_const(cXMLReader, "TYPE_ENTITY", INT2FIX(XML_READER_TYPE_ENTITY));
|
891
|
+
rb_define_const(cXMLReader, "TYPE_PROCESSING_INSTRUCTION", INT2FIX(XML_READER_TYPE_PROCESSING_INSTRUCTION));
|
892
|
+
rb_define_const(cXMLReader, "TYPE_COMMENT", INT2FIX(XML_READER_TYPE_COMMENT));
|
893
|
+
rb_define_const(cXMLReader, "TYPE_DOCUMENT", INT2FIX(XML_READER_TYPE_DOCUMENT));
|
894
|
+
rb_define_const(cXMLReader, "TYPE_DOCUMENT_TYPE", INT2FIX(XML_READER_TYPE_DOCUMENT_TYPE));
|
895
|
+
rb_define_const(cXMLReader, "TYPE_DOCUMENT_FRAGMENT", INT2FIX(XML_READER_TYPE_DOCUMENT_FRAGMENT));
|
896
|
+
rb_define_const(cXMLReader, "TYPE_NOTATION", INT2FIX(XML_READER_TYPE_NOTATION));
|
897
|
+
rb_define_const(cXMLReader, "TYPE_WHITESPACE", INT2FIX(XML_READER_TYPE_WHITESPACE));
|
898
|
+
rb_define_const(cXMLReader, "TYPE_SIGNIFICANT_WHITESPACE", INT2FIX(XML_READER_TYPE_SIGNIFICANT_WHITESPACE));
|
899
|
+
rb_define_const(cXMLReader, "TYPE_END_ELEMENT", INT2FIX(XML_READER_TYPE_END_ELEMENT));
|
900
|
+
rb_define_const(cXMLReader, "TYPE_END_ENTITY", INT2FIX(XML_READER_TYPE_END_ENTITY));
|
901
|
+
rb_define_const(cXMLReader, "TYPE_XML_DECLARATION", INT2FIX(XML_READER_TYPE_XML_DECLARATION));
|
902
|
+
|
903
|
+
/* Read states */
|
904
|
+
rb_define_const(cXMLReader, "MODE_INITIAL", INT2FIX(XML_TEXTREADER_MODE_INITIAL));
|
905
|
+
rb_define_const(cXMLReader, "MODE_INTERACTIVE", INT2FIX(XML_TEXTREADER_MODE_INTERACTIVE));
|
906
|
+
rb_define_const(cXMLReader, "MODE_ERROR", INT2FIX(XML_TEXTREADER_MODE_ERROR));
|
907
|
+
rb_define_const(cXMLReader, "MODE_EOF", INT2FIX(XML_TEXTREADER_MODE_EOF));
|
908
|
+
rb_define_const(cXMLReader, "MODE_CLOSED", INT2FIX(XML_TEXTREADER_MODE_CLOSED));
|
909
|
+
rb_define_const(cXMLReader, "MODE_READING", INT2FIX(XML_TEXTREADER_MODE_READING));
|
910
|
+
}
|