libxml-ruby 0.3.8.4 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +6 -0
- data/LICENSE +1 -1
- data/README +1 -1
- data/Rakefile +8 -5
- data/TODO +1 -1
- data/ext/xml/extconf.rb +4 -5
- data/ext/xml/libxml.c +5 -2
- data/ext/xml/libxml.h +16 -7
- data/ext/xml/libxml.rb +3 -3
- data/ext/xml/ruby_xml_attr.c +118 -99
- data/ext/xml/ruby_xml_attr.h +4 -7
- data/ext/xml/ruby_xml_document.c +131 -170
- data/ext/xml/ruby_xml_document.h +5 -9
- data/ext/xml/ruby_xml_html_parser.c +453 -0
- data/ext/xml/ruby_xml_html_parser.h +29 -0
- data/ext/xml/ruby_xml_node.c +219 -253
- data/ext/xml/ruby_xml_node.h +4 -7
- data/ext/xml/ruby_xml_node_set.c +6 -6
- data/ext/xml/ruby_xml_node_set.h +1 -1
- data/ext/xml/ruby_xml_ns.c +1 -1
- data/ext/xml/ruby_xml_ns.h +1 -1
- data/ext/xml/ruby_xml_parser.c +5 -8
- data/ext/xml/ruby_xml_parser.h +1 -1
- data/ext/xml/ruby_xml_parser_context.c +3 -4
- data/ext/xml/ruby_xml_parser_context.h +1 -1
- data/ext/xml/ruby_xml_reader.c +893 -0
- data/ext/xml/ruby_xml_reader.h +14 -0
- data/ext/xml/ruby_xml_sax_parser.c +255 -204
- data/ext/xml/ruby_xml_sax_parser.h +6 -2
- data/ext/xml/ruby_xml_tree.c +1 -1
- data/ext/xml/ruby_xml_tree.h +1 -1
- data/ext/xml/ruby_xml_xinclude.c +1 -1
- data/ext/xml/ruby_xml_xinclude.h +1 -1
- data/ext/xml/ruby_xml_xpath.c +3 -2
- data/ext/xml/ruby_xml_xpath.h +1 -1
- data/ext/xml/ruby_xml_xpath_context.c +4 -4
- data/ext/xml/ruby_xml_xpath_context.h +1 -1
- data/ext/xml/ruby_xml_xpointer.c +10 -4
- data/ext/xml/ruby_xml_xpointer.h +1 -1
- data/ext/xml/ruby_xml_xpointer_context.c +1 -1
- data/ext/xml/ruby_xml_xpointer_context.h +1 -1
- data/ext/xml/sax_parser_callbacks.inc +55 -54
- data/tests/model/rubynet_project +1 -1
- data/tests/model/simple.xml +7 -0
- data/tests/tc_xml_document.rb +1 -1
- data/tests/tc_xml_document_write.rb +1 -1
- data/tests/tc_xml_document_write2.rb +1 -1
- data/tests/tc_xml_document_write3.rb +1 -1
- data/tests/tc_xml_html_parser.rb +60 -0
- data/tests/tc_xml_node.rb +1 -1
- data/tests/tc_xml_node2.rb +1 -1
- data/tests/tc_xml_node3.rb +1 -1
- data/tests/tc_xml_node4.rb +8 -5
- data/tests/tc_xml_node5.rb +1 -1
- data/tests/tc_xml_node6.rb +1 -1
- data/tests/tc_xml_node7.rb +1 -1
- data/tests/tc_xml_node_set.rb +1 -1
- data/tests/tc_xml_node_set2.rb +1 -1
- data/tests/tc_xml_node_xlink.rb +1 -1
- data/tests/tc_xml_parser.rb +5 -1
- data/tests/tc_xml_parser2.rb +1 -1
- data/tests/tc_xml_parser3.rb +1 -1
- data/tests/tc_xml_parser4.rb +1 -1
- data/tests/tc_xml_parser5.rb +1 -1
- data/tests/tc_xml_parser6.rb +1 -1
- data/tests/tc_xml_parser7.rb +1 -1
- data/tests/tc_xml_parser8.rb +1 -1
- data/tests/tc_xml_parser_context.rb +1 -1
- data/tests/tc_xml_reader.rb +101 -0
- data/tests/tc_xml_sax_parser.rb +95 -0
- data/tests/tc_xml_xinclude.rb +1 -1
- data/tests/tc_xml_xpath.rb +1 -1
- data/tests/tc_xml_xpointer.rb +1 -1
- metadata +79 -73
- data/ext/xml/ruby_xml_attribute.c +0 -224
- data/ext/xml/ruby_xml_attribute.h +0 -21
- data/tests/test_xml_sax_parser.rb +0 -64
data/ext/xml/ruby_xml_document.c
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* $Id: ruby_xml_document.c
|
|
1
|
+
/* $Id: ruby_xml_document.c 140 2007-08-29 18:28:40Z danj $ */
|
|
2
2
|
|
|
3
3
|
/* Please see the LICENSE file for copyright and distribution information */
|
|
4
4
|
|
|
@@ -17,9 +17,9 @@ VALUE cXMLDocument;
|
|
|
17
17
|
VALUE
|
|
18
18
|
ruby_xml_document_compression_get(VALUE self) {
|
|
19
19
|
#ifdef HAVE_ZLIB_H
|
|
20
|
-
|
|
20
|
+
ruby_xml_document_t *rxd;
|
|
21
21
|
int compmode;
|
|
22
|
-
Data_Get_Struct(self,
|
|
22
|
+
Data_Get_Struct(self, ruby_xml_document_t, rxd);
|
|
23
23
|
|
|
24
24
|
compmode = xmlGetDocCompressMode(rxd->doc);
|
|
25
25
|
if (compmode == -1)
|
|
@@ -42,10 +42,10 @@ ruby_xml_document_compression_get(VALUE self) {
|
|
|
42
42
|
VALUE
|
|
43
43
|
ruby_xml_document_compression_set(VALUE self, VALUE num) {
|
|
44
44
|
#ifdef HAVE_ZLIB_H
|
|
45
|
-
|
|
45
|
+
ruby_xml_document_t *rxd;
|
|
46
46
|
int compmode;
|
|
47
47
|
Check_Type(num, T_FIXNUM);
|
|
48
|
-
Data_Get_Struct(self,
|
|
48
|
+
Data_Get_Struct(self, ruby_xml_document_t, rxd);
|
|
49
49
|
|
|
50
50
|
if (rxd->doc == NULL) {
|
|
51
51
|
return(Qnil);
|
|
@@ -74,8 +74,8 @@ ruby_xml_document_compression_set(VALUE self, VALUE num) {
|
|
|
74
74
|
VALUE
|
|
75
75
|
ruby_xml_document_compression_q(VALUE self) {
|
|
76
76
|
#ifdef HAVE_ZLIB_H
|
|
77
|
-
|
|
78
|
-
Data_Get_Struct(self,
|
|
77
|
+
ruby_xml_document_t *rxd;
|
|
78
|
+
Data_Get_Struct(self, ruby_xml_document_t, rxd);
|
|
79
79
|
|
|
80
80
|
if (rxd->doc->compression != -1)
|
|
81
81
|
return(Qtrue);
|
|
@@ -96,19 +96,14 @@ ruby_xml_document_compression_q(VALUE self) {
|
|
|
96
96
|
*/
|
|
97
97
|
VALUE
|
|
98
98
|
ruby_xml_document_child_get(VALUE self) {
|
|
99
|
-
|
|
100
|
-
ruby_xml_node *rxn;
|
|
101
|
-
VALUE node;
|
|
99
|
+
ruby_xml_document_t *rxd;
|
|
102
100
|
|
|
103
|
-
Data_Get_Struct(self,
|
|
101
|
+
Data_Get_Struct(self, ruby_xml_document_t, rxd);
|
|
104
102
|
|
|
105
103
|
if (rxd->doc->children == NULL)
|
|
106
104
|
return(Qnil);
|
|
107
105
|
|
|
108
|
-
|
|
109
|
-
Data_Get_Struct(node, ruby_xml_node, rxn);
|
|
110
|
-
rxn->xd = self;
|
|
111
|
-
return(node);
|
|
106
|
+
return ruby_xml_node2_wrap(cXMLNode, rxd->doc->children);
|
|
112
107
|
}
|
|
113
108
|
|
|
114
109
|
|
|
@@ -120,8 +115,8 @@ ruby_xml_document_child_get(VALUE self) {
|
|
|
120
115
|
*/
|
|
121
116
|
VALUE
|
|
122
117
|
ruby_xml_document_child_q(VALUE self) {
|
|
123
|
-
|
|
124
|
-
Data_Get_Struct(self,
|
|
118
|
+
ruby_xml_document_t *rxd;
|
|
119
|
+
Data_Get_Struct(self, ruby_xml_document_t, rxd);
|
|
125
120
|
|
|
126
121
|
if (rxd->doc->children == NULL)
|
|
127
122
|
return(Qfalse);
|
|
@@ -142,9 +137,9 @@ ruby_xml_document_dump(int argc, VALUE *argv, VALUE self) {
|
|
|
142
137
|
OpenFile *fptr;
|
|
143
138
|
VALUE io;
|
|
144
139
|
FILE *out;
|
|
145
|
-
|
|
140
|
+
ruby_xml_document_t *rxd;
|
|
146
141
|
|
|
147
|
-
Data_Get_Struct(self,
|
|
142
|
+
Data_Get_Struct(self, ruby_xml_document_t, rxd);
|
|
148
143
|
if (rxd->doc == NULL)
|
|
149
144
|
return(Qnil);
|
|
150
145
|
|
|
@@ -181,9 +176,9 @@ ruby_xml_document_debug_dump(int argc, VALUE *argv, VALUE self) {
|
|
|
181
176
|
OpenFile *fptr;
|
|
182
177
|
VALUE io;
|
|
183
178
|
FILE *out;
|
|
184
|
-
|
|
179
|
+
ruby_xml_document_t *rxd;
|
|
185
180
|
|
|
186
|
-
Data_Get_Struct(self,
|
|
181
|
+
Data_Get_Struct(self, ruby_xml_document_t, rxd);
|
|
187
182
|
if (rxd->doc == NULL)
|
|
188
183
|
return(Qnil);
|
|
189
184
|
|
|
@@ -225,9 +220,9 @@ ruby_xml_document_debug_dump_head(int argc, VALUE *argv, VALUE self) {
|
|
|
225
220
|
OpenFile *fptr;
|
|
226
221
|
VALUE io;
|
|
227
222
|
FILE *out;
|
|
228
|
-
|
|
223
|
+
ruby_xml_document_t *rxd;
|
|
229
224
|
|
|
230
|
-
Data_Get_Struct(self,
|
|
225
|
+
Data_Get_Struct(self, ruby_xml_document_t, rxd);
|
|
231
226
|
if (rxd->doc == NULL)
|
|
232
227
|
return(Qnil);
|
|
233
228
|
|
|
@@ -270,10 +265,10 @@ ruby_xml_document_format_dump(int argc, VALUE *argv, VALUE self) {
|
|
|
270
265
|
OpenFile *fptr;
|
|
271
266
|
VALUE bool, io;
|
|
272
267
|
FILE *out;
|
|
273
|
-
|
|
268
|
+
ruby_xml_document_t *rxd;
|
|
274
269
|
int size, spacing;
|
|
275
270
|
|
|
276
|
-
Data_Get_Struct(self,
|
|
271
|
+
Data_Get_Struct(self, ruby_xml_document_t, rxd);
|
|
277
272
|
if (rxd->doc == NULL)
|
|
278
273
|
return(Qnil);
|
|
279
274
|
|
|
@@ -334,8 +329,8 @@ ruby_xml_document_debug_format_dump(int argc, VALUE *argv, VALUE self) {
|
|
|
334
329
|
*/
|
|
335
330
|
VALUE
|
|
336
331
|
ruby_xml_document_encoding_get(VALUE self) {
|
|
337
|
-
|
|
338
|
-
Data_Get_Struct(self,
|
|
332
|
+
ruby_xml_document_t *rxd;
|
|
333
|
+
Data_Get_Struct(self, ruby_xml_document_t, rxd);
|
|
339
334
|
if (rxd->doc->encoding == NULL)
|
|
340
335
|
return(Qnil);
|
|
341
336
|
else
|
|
@@ -351,10 +346,10 @@ ruby_xml_document_encoding_get(VALUE self) {
|
|
|
351
346
|
*/
|
|
352
347
|
VALUE
|
|
353
348
|
ruby_xml_document_encoding_set(VALUE self, VALUE encoding) {
|
|
354
|
-
|
|
349
|
+
ruby_xml_document_t *rxd;
|
|
355
350
|
|
|
356
351
|
Check_Type(encoding, T_STRING);
|
|
357
|
-
Data_Get_Struct(self,
|
|
352
|
+
Data_Get_Struct(self, ruby_xml_document_t, rxd);
|
|
358
353
|
rxd->doc->encoding = (xmlChar*)ruby_strdup(StringValuePtr(encoding));
|
|
359
354
|
return(ruby_xml_document_encoding_get(self));
|
|
360
355
|
}
|
|
@@ -368,10 +363,10 @@ ruby_xml_document_encoding_set(VALUE self, VALUE encoding) {
|
|
|
368
363
|
*/
|
|
369
364
|
VALUE
|
|
370
365
|
ruby_xml_document_filename_get(VALUE self) {
|
|
371
|
-
|
|
366
|
+
ruby_xml_document_t *rxd;
|
|
372
367
|
rx_file_data *data;
|
|
373
368
|
|
|
374
|
-
Data_Get_Struct(self,
|
|
369
|
+
Data_Get_Struct(self, ruby_xml_document_t, rxd);
|
|
375
370
|
if (rxd->data == NULL)
|
|
376
371
|
return(Qnil);
|
|
377
372
|
|
|
@@ -415,15 +410,16 @@ ruby_xml_document_find(int argc, VALUE *argv, VALUE self) {
|
|
|
415
410
|
|
|
416
411
|
|
|
417
412
|
void
|
|
418
|
-
ruby_xml_document_free(
|
|
413
|
+
ruby_xml_document_free(ruby_xml_document_t *rxd) {
|
|
419
414
|
void *data;
|
|
420
415
|
|
|
421
|
-
if (rxd->doc
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
416
|
+
if (rxd->doc == NULL) return;
|
|
417
|
+
rxd->doc->_private=NULL;
|
|
418
|
+
xmlFreeDoc(rxd->doc);
|
|
419
|
+
ruby_xml_parser_count--;
|
|
420
|
+
rxd->doc = NULL;
|
|
426
421
|
|
|
422
|
+
// All this should be replaced by VALUE objects that GC can work
|
|
427
423
|
if (ruby_xml_parser_count == 0)
|
|
428
424
|
xmlCleanupParser();
|
|
429
425
|
|
|
@@ -449,6 +445,11 @@ ruby_xml_document_free(ruby_xml_document *rxd) {
|
|
|
449
445
|
free(rxd);
|
|
450
446
|
}
|
|
451
447
|
|
|
448
|
+
void
|
|
449
|
+
ruby_xml_document_mark(ruby_xml_document_t *rxd) {
|
|
450
|
+
// will mark parsers and source types
|
|
451
|
+
// I do not thing doc->parent has anything useful in it.
|
|
452
|
+
}
|
|
452
453
|
|
|
453
454
|
/*
|
|
454
455
|
* call-seq:
|
|
@@ -458,7 +459,7 @@ ruby_xml_document_free(ruby_xml_document *rxd) {
|
|
|
458
459
|
* XML version.
|
|
459
460
|
*/
|
|
460
461
|
VALUE
|
|
461
|
-
|
|
462
|
+
ruby_xml_document_new(int argc, VALUE *argv, VALUE class) {
|
|
462
463
|
VALUE docobj, xmlver;
|
|
463
464
|
|
|
464
465
|
switch (argc) {
|
|
@@ -472,7 +473,7 @@ ruby_xml_document_initialize(int argc, VALUE *argv, VALUE class) {
|
|
|
472
473
|
rb_raise(rb_eArgError, "wrong number of arguments (need 0 or 1)");
|
|
473
474
|
}
|
|
474
475
|
|
|
475
|
-
docobj =
|
|
476
|
+
docobj = ruby_xml_document_new_native(cXMLDocument, xmlver);
|
|
476
477
|
return(docobj);
|
|
477
478
|
}
|
|
478
479
|
|
|
@@ -485,19 +486,14 @@ ruby_xml_document_initialize(int argc, VALUE *argv, VALUE class) {
|
|
|
485
486
|
*/
|
|
486
487
|
VALUE
|
|
487
488
|
ruby_xml_document_last_get(VALUE self) {
|
|
488
|
-
|
|
489
|
-
ruby_xml_node *rxn;
|
|
490
|
-
VALUE node;
|
|
489
|
+
ruby_xml_document_t *rxd;
|
|
491
490
|
|
|
492
|
-
Data_Get_Struct(self,
|
|
491
|
+
Data_Get_Struct(self, ruby_xml_document_t, rxd);
|
|
493
492
|
|
|
494
493
|
if (rxd->doc->last == NULL)
|
|
495
494
|
return(Qnil);
|
|
496
495
|
|
|
497
|
-
|
|
498
|
-
Data_Get_Struct(node, ruby_xml_node, rxn);
|
|
499
|
-
rxn->xd = self;
|
|
500
|
-
return(node);
|
|
496
|
+
return ruby_xml_node2_wrap(cXMLNode, rxd->doc->last);
|
|
501
497
|
}
|
|
502
498
|
|
|
503
499
|
|
|
@@ -509,8 +505,8 @@ ruby_xml_document_last_get(VALUE self) {
|
|
|
509
505
|
*/
|
|
510
506
|
VALUE
|
|
511
507
|
ruby_xml_document_last_q(VALUE self) {
|
|
512
|
-
|
|
513
|
-
Data_Get_Struct(self,
|
|
508
|
+
ruby_xml_document_t *rxd;
|
|
509
|
+
Data_Get_Struct(self, ruby_xml_document_t, rxd);
|
|
514
510
|
|
|
515
511
|
if (rxd->doc->last == NULL)
|
|
516
512
|
return(Qfalse);
|
|
@@ -518,74 +514,43 @@ ruby_xml_document_last_q(VALUE self) {
|
|
|
518
514
|
return(Qtrue);
|
|
519
515
|
}
|
|
520
516
|
|
|
521
|
-
|
|
522
|
-
static void
|
|
523
|
-
ruby_xml_document_mark(ruby_xml_document *rxd) {
|
|
524
|
-
if (rxd == NULL) return;
|
|
525
|
-
if (!NIL_P(rxd->xmlver)) rb_gc_mark(rxd->xmlver);
|
|
526
|
-
}
|
|
527
|
-
|
|
528
|
-
|
|
529
517
|
VALUE
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
518
|
+
ruby_xml_document_wrap(VALUE class, xmlDocPtr xnode) {
|
|
519
|
+
VALUE obj;
|
|
520
|
+
ruby_xml_document_t *rx;
|
|
521
|
+
|
|
522
|
+
// This node is already wrapped
|
|
523
|
+
if (xnode->_private != NULL)
|
|
524
|
+
return (VALUE)xnode->_private;
|
|
525
|
+
|
|
526
|
+
/*
|
|
527
|
+
* XXX This is bad and needs to be replaced with
|
|
528
|
+
* something that interacts with the GC. I did not do all this
|
|
529
|
+
* to have reference counting still around. -danj
|
|
530
|
+
*/
|
|
534
531
|
ruby_xml_parser_count++;
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
532
|
+
obj=Data_Make_Struct(class,ruby_xml_document_t,
|
|
533
|
+
ruby_xml_document_mark,
|
|
534
|
+
ruby_xml_document_free,rx);
|
|
535
|
+
rx->doc=xnode;
|
|
536
|
+
xnode->_private=(void*)obj;
|
|
537
|
+
rx->data = NULL;
|
|
538
|
+
rx->data_type = RUBY_LIBXML_SRC_TYPE_NULL;
|
|
539
|
+
|
|
540
|
+
#ifdef NODE_DEBUG
|
|
541
|
+
fprintf(stderr,"wrap rxn=0x%x xn=0x%x o=0x%x\n",(long)rxn,(long)xnode,(long)obj);
|
|
542
|
+
#endif
|
|
543
|
+
return obj;
|
|
544
544
|
}
|
|
545
545
|
|
|
546
|
-
|
|
547
546
|
VALUE
|
|
548
|
-
|
|
549
|
-
|
|
547
|
+
ruby_xml_document_new_native(VALUE class, VALUE xmlver) {
|
|
548
|
+
xmlDocPtr rx;
|
|
550
549
|
|
|
551
550
|
Check_Type(xmlver, T_STRING);
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
rxd->data = NULL;
|
|
556
|
-
rxd->data_type = RUBY_LIBXML_SRC_TYPE_NULL;
|
|
557
|
-
rxd->doc = xmlNewDoc((xmlChar*)StringValuePtr(xmlver));
|
|
558
|
-
rxd->is_ptr = 0;
|
|
559
|
-
rxd->xmlver = xmlver;
|
|
560
|
-
|
|
561
|
-
if (rxd->doc == NULL)
|
|
562
|
-
rb_fatal("bad");
|
|
563
|
-
|
|
564
|
-
return(Data_Wrap_Struct(cXMLDocument, ruby_xml_document_mark,
|
|
565
|
-
ruby_xml_document_free, rxd));
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
VALUE
|
|
570
|
-
ruby_xml_document_new3(VALUE class) {
|
|
571
|
-
return(ruby_xml_document_new2(class, rb_str_new2("1.0")));
|
|
572
|
-
}
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
VALUE
|
|
576
|
-
ruby_xml_document_new4(VALUE class, xmlDocPtr doc) {
|
|
577
|
-
ruby_xml_document *rxd;
|
|
578
|
-
|
|
579
|
-
rxd = ALLOC(ruby_xml_document);
|
|
580
|
-
|
|
581
|
-
rxd->data = NULL;
|
|
582
|
-
rxd->data_type = RUBY_LIBXML_SRC_TYPE_NULL;
|
|
583
|
-
rxd->doc = doc;
|
|
584
|
-
rxd->is_ptr = 1;
|
|
585
|
-
rxd->xmlver = Qnil;
|
|
586
|
-
|
|
587
|
-
return(Data_Wrap_Struct(cXMLDocument, ruby_xml_document_mark,
|
|
588
|
-
ruby_xml_document_free, rxd));
|
|
551
|
+
rx=xmlNewDoc((xmlChar*)StringValuePtr(xmlver));
|
|
552
|
+
rx->_private=NULL;
|
|
553
|
+
return ruby_xml_document_wrap(class,rx);
|
|
589
554
|
}
|
|
590
555
|
|
|
591
556
|
|
|
@@ -614,19 +579,14 @@ ruby_xml_document_new_file(VALUE class, VALUE filename) {
|
|
|
614
579
|
*/
|
|
615
580
|
VALUE
|
|
616
581
|
ruby_xml_document_next_get(VALUE self) {
|
|
617
|
-
|
|
618
|
-
ruby_xml_node *rxn;
|
|
619
|
-
VALUE node;
|
|
582
|
+
ruby_xml_document_t *rxd;
|
|
620
583
|
|
|
621
|
-
Data_Get_Struct(self,
|
|
584
|
+
Data_Get_Struct(self, ruby_xml_document_t, rxd);
|
|
622
585
|
|
|
623
586
|
if (rxd->doc->next == NULL)
|
|
624
587
|
return(Qnil);
|
|
625
588
|
|
|
626
|
-
|
|
627
|
-
Data_Get_Struct(node, ruby_xml_node, rxn);
|
|
628
|
-
rxn->xd = self;
|
|
629
|
-
return(node);
|
|
589
|
+
return ruby_xml_node2_wrap(cXMLNode, rxd->doc->next);
|
|
630
590
|
}
|
|
631
591
|
|
|
632
592
|
|
|
@@ -638,8 +598,8 @@ ruby_xml_document_next_get(VALUE self) {
|
|
|
638
598
|
*/
|
|
639
599
|
VALUE
|
|
640
600
|
ruby_xml_document_next_q(VALUE self) {
|
|
641
|
-
|
|
642
|
-
Data_Get_Struct(self,
|
|
601
|
+
ruby_xml_document_t *rxd;
|
|
602
|
+
Data_Get_Struct(self, ruby_xml_document_t, rxd);
|
|
643
603
|
|
|
644
604
|
if (rxd->doc->next == NULL)
|
|
645
605
|
return(Qfalse);
|
|
@@ -656,19 +616,14 @@ ruby_xml_document_next_q(VALUE self) {
|
|
|
656
616
|
*/
|
|
657
617
|
VALUE
|
|
658
618
|
ruby_xml_document_parent_get(VALUE self) {
|
|
659
|
-
|
|
660
|
-
ruby_xml_node *rxn;
|
|
661
|
-
VALUE node;
|
|
619
|
+
ruby_xml_document_t *rxd;
|
|
662
620
|
|
|
663
|
-
Data_Get_Struct(self,
|
|
621
|
+
Data_Get_Struct(self, ruby_xml_document_t, rxd);
|
|
664
622
|
|
|
665
623
|
if (rxd->doc->parent == NULL)
|
|
666
624
|
return(Qnil);
|
|
667
625
|
|
|
668
|
-
|
|
669
|
-
Data_Get_Struct(node, ruby_xml_node, rxn);
|
|
670
|
-
rxn->xd = self;
|
|
671
|
-
return(node);
|
|
626
|
+
return ruby_xml_node2_wrap(cXMLNode, rxd->doc->parent);
|
|
672
627
|
}
|
|
673
628
|
|
|
674
629
|
|
|
@@ -680,8 +635,8 @@ ruby_xml_document_parent_get(VALUE self) {
|
|
|
680
635
|
*/
|
|
681
636
|
VALUE
|
|
682
637
|
ruby_xml_document_parent_q(VALUE self) {
|
|
683
|
-
|
|
684
|
-
Data_Get_Struct(self,
|
|
638
|
+
ruby_xml_document_t *rxd;
|
|
639
|
+
Data_Get_Struct(self, ruby_xml_document_t, rxd);
|
|
685
640
|
|
|
686
641
|
if (rxd->doc->parent == NULL)
|
|
687
642
|
return(Qfalse);
|
|
@@ -698,19 +653,14 @@ ruby_xml_document_parent_q(VALUE self) {
|
|
|
698
653
|
*/
|
|
699
654
|
VALUE
|
|
700
655
|
ruby_xml_document_prev_get(VALUE self) {
|
|
701
|
-
|
|
702
|
-
ruby_xml_node *rxn;
|
|
703
|
-
VALUE node;
|
|
656
|
+
ruby_xml_document_t *rxd;
|
|
704
657
|
|
|
705
|
-
Data_Get_Struct(self,
|
|
658
|
+
Data_Get_Struct(self, ruby_xml_document_t, rxd);
|
|
706
659
|
|
|
707
660
|
if (rxd->doc->prev == NULL)
|
|
708
661
|
return(Qnil);
|
|
709
662
|
|
|
710
|
-
|
|
711
|
-
Data_Get_Struct(node, ruby_xml_node, rxn);
|
|
712
|
-
rxn->xd = self;
|
|
713
|
-
return(node);
|
|
663
|
+
return ruby_xml_node2_wrap(cXMLNode, rxd->doc->prev);
|
|
714
664
|
}
|
|
715
665
|
|
|
716
666
|
|
|
@@ -722,8 +672,8 @@ ruby_xml_document_prev_get(VALUE self) {
|
|
|
722
672
|
*/
|
|
723
673
|
VALUE
|
|
724
674
|
ruby_xml_document_prev_q(VALUE self) {
|
|
725
|
-
|
|
726
|
-
Data_Get_Struct(self,
|
|
675
|
+
ruby_xml_document_t *rxd;
|
|
676
|
+
Data_Get_Struct(self, ruby_xml_document_t, rxd);
|
|
727
677
|
|
|
728
678
|
if (rxd->doc->prev == NULL)
|
|
729
679
|
return(Qfalse);
|
|
@@ -764,18 +714,16 @@ ruby_xml_document_property_set(VALUE self, VALUE key, VALUE val) {
|
|
|
764
714
|
*/
|
|
765
715
|
VALUE
|
|
766
716
|
ruby_xml_document_root_get(VALUE self) {
|
|
767
|
-
|
|
768
|
-
VALUE node;
|
|
717
|
+
ruby_xml_document_t *rxd;
|
|
769
718
|
xmlNodePtr root;
|
|
770
719
|
|
|
771
|
-
Data_Get_Struct(self,
|
|
720
|
+
Data_Get_Struct(self, ruby_xml_document_t, rxd);
|
|
772
721
|
root = xmlDocGetRootElement(rxd->doc);
|
|
773
722
|
|
|
774
723
|
if (root == NULL)
|
|
775
724
|
return(Qnil);
|
|
776
725
|
|
|
777
|
-
|
|
778
|
-
return(node);
|
|
726
|
+
return ruby_xml_node2_wrap(cXMLNode, root);
|
|
779
727
|
}
|
|
780
728
|
|
|
781
729
|
|
|
@@ -787,23 +735,20 @@ ruby_xml_document_root_get(VALUE self) {
|
|
|
787
735
|
*/
|
|
788
736
|
VALUE
|
|
789
737
|
ruby_xml_document_root_set(VALUE self, VALUE node) {
|
|
790
|
-
|
|
738
|
+
ruby_xml_document_t *rxd;
|
|
791
739
|
ruby_xml_node *rxn;
|
|
792
|
-
VALUE retnode;
|
|
793
740
|
xmlNodePtr root;
|
|
794
741
|
|
|
795
742
|
if (rb_obj_is_kind_of(node, cXMLNode) == Qfalse)
|
|
796
743
|
rb_raise(rb_eTypeError, "must pass an XML::Node type object");
|
|
797
744
|
|
|
798
|
-
Data_Get_Struct(self,
|
|
745
|
+
Data_Get_Struct(self, ruby_xml_document_t, rxd);
|
|
799
746
|
Data_Get_Struct(node, ruby_xml_node, rxn);
|
|
800
|
-
ruby_xml_node_set_ptr(node, 1);
|
|
801
747
|
root = xmlDocSetRootElement(rxd->doc, rxn->node);
|
|
802
748
|
if (root == NULL)
|
|
803
749
|
return(Qnil);
|
|
804
750
|
|
|
805
|
-
|
|
806
|
-
return(retnode);
|
|
751
|
+
return ruby_xml_node2_wrap(cXMLNode, root);
|
|
807
752
|
}
|
|
808
753
|
|
|
809
754
|
|
|
@@ -816,7 +761,7 @@ ruby_xml_document_root_set(VALUE self, VALUE node) {
|
|
|
816
761
|
*/
|
|
817
762
|
VALUE
|
|
818
763
|
ruby_xml_document_save(int argc, VALUE *argv, VALUE self) {
|
|
819
|
-
|
|
764
|
+
ruby_xml_document_t *rxd;
|
|
820
765
|
const char *filename;
|
|
821
766
|
int format, len;
|
|
822
767
|
|
|
@@ -839,7 +784,7 @@ ruby_xml_document_save(int argc, VALUE *argv, VALUE self) {
|
|
|
839
784
|
Check_Type(argv[0], T_STRING);
|
|
840
785
|
filename = StringValuePtr(argv[0]);
|
|
841
786
|
|
|
842
|
-
Data_Get_Struct(self,
|
|
787
|
+
Data_Get_Struct(self, ruby_xml_document_t, rxd);
|
|
843
788
|
len = xmlSaveFormatFileEnc(filename, rxd->doc, (const char*)rxd->doc->encoding, format);
|
|
844
789
|
if (len == -1)
|
|
845
790
|
rb_fatal("Unable to write out file");
|
|
@@ -856,8 +801,8 @@ ruby_xml_document_save(int argc, VALUE *argv, VALUE self) {
|
|
|
856
801
|
*/
|
|
857
802
|
VALUE
|
|
858
803
|
ruby_xml_document_standalone_q(VALUE self) {
|
|
859
|
-
|
|
860
|
-
Data_Get_Struct(self,
|
|
804
|
+
ruby_xml_document_t *rxd;
|
|
805
|
+
Data_Get_Struct(self, ruby_xml_document_t, rxd);
|
|
861
806
|
if (rxd->doc->standalone)
|
|
862
807
|
return(Qtrue);
|
|
863
808
|
else
|
|
@@ -874,9 +819,10 @@ ruby_xml_document_standalone_q(VALUE self) {
|
|
|
874
819
|
*/
|
|
875
820
|
VALUE
|
|
876
821
|
ruby_xml_document_to_s(int argc, VALUE *argv, VALUE self) {
|
|
877
|
-
|
|
822
|
+
ruby_xml_document_t *rxd;
|
|
878
823
|
xmlChar *result;
|
|
879
824
|
int format, len;
|
|
825
|
+
VALUE rresult;
|
|
880
826
|
|
|
881
827
|
switch (argc) {
|
|
882
828
|
case 0:
|
|
@@ -894,7 +840,7 @@ ruby_xml_document_to_s(int argc, VALUE *argv, VALUE self) {
|
|
|
894
840
|
rb_raise(rb_eArgError, "wrong number of arguments (0 or 1)");
|
|
895
841
|
}
|
|
896
842
|
|
|
897
|
-
Data_Get_Struct(self,
|
|
843
|
+
Data_Get_Struct(self, ruby_xml_document_t, rxd);
|
|
898
844
|
if (rxd->doc == NULL) {
|
|
899
845
|
return(Qnil);
|
|
900
846
|
} else if (rxd->doc->encoding != NULL) {
|
|
@@ -911,8 +857,9 @@ ruby_xml_document_to_s(int argc, VALUE *argv, VALUE self) {
|
|
|
911
857
|
else
|
|
912
858
|
xmlDocDumpMemory(rxd->doc, &result, &len);
|
|
913
859
|
}
|
|
914
|
-
|
|
915
|
-
|
|
860
|
+
rresult=rb_str_new2((const char*)result);
|
|
861
|
+
xmlFree(result);
|
|
862
|
+
return rresult;
|
|
916
863
|
}
|
|
917
864
|
|
|
918
865
|
|
|
@@ -924,8 +871,8 @@ ruby_xml_document_to_s(int argc, VALUE *argv, VALUE self) {
|
|
|
924
871
|
*/
|
|
925
872
|
VALUE
|
|
926
873
|
ruby_xml_document_url_get(VALUE self) {
|
|
927
|
-
|
|
928
|
-
Data_Get_Struct(self,
|
|
874
|
+
ruby_xml_document_t *rxd;
|
|
875
|
+
Data_Get_Struct(self, ruby_xml_document_t, rxd);
|
|
929
876
|
if (rxd->doc->URL == NULL)
|
|
930
877
|
return(Qnil);
|
|
931
878
|
else
|
|
@@ -941,8 +888,8 @@ ruby_xml_document_url_get(VALUE self) {
|
|
|
941
888
|
*/
|
|
942
889
|
VALUE
|
|
943
890
|
ruby_xml_document_version_get(VALUE self) {
|
|
944
|
-
|
|
945
|
-
Data_Get_Struct(self,
|
|
891
|
+
ruby_xml_document_t *rxd;
|
|
892
|
+
Data_Get_Struct(self, ruby_xml_document_t, rxd);
|
|
946
893
|
if (rxd->doc->version == NULL)
|
|
947
894
|
return(Qnil);
|
|
948
895
|
else
|
|
@@ -959,10 +906,10 @@ ruby_xml_document_version_get(VALUE self) {
|
|
|
959
906
|
VALUE
|
|
960
907
|
ruby_xml_document_xinclude(VALUE self) {
|
|
961
908
|
#ifdef LIBXML_XINCLUDE_ENABLED
|
|
962
|
-
|
|
909
|
+
ruby_xml_document_t *rxd;
|
|
963
910
|
int ret;
|
|
964
911
|
|
|
965
|
-
Data_Get_Struct(self,
|
|
912
|
+
Data_Get_Struct(self, ruby_xml_document_t, rxd);
|
|
966
913
|
ret = xmlXIncludeProcess(rxd->doc);
|
|
967
914
|
if (ret >= 0)
|
|
968
915
|
return(INT2NUM(ret));
|
|
@@ -1009,11 +956,11 @@ LibXML_validity_warning(void * ctxt, const char * msg, va_list ap)
|
|
|
1009
956
|
VALUE
|
|
1010
957
|
ruby_xml_document_validate_schema(VALUE self, VALUE schema) {
|
|
1011
958
|
xmlSchemaValidCtxtPtr vptr;
|
|
1012
|
-
|
|
959
|
+
ruby_xml_document_t *c_doc;
|
|
1013
960
|
ruby_xml_schema *c_schema;
|
|
1014
961
|
int is_invalid;
|
|
1015
962
|
|
|
1016
|
-
Data_Get_Struct(self,
|
|
963
|
+
Data_Get_Struct(self, ruby_xml_document_t, c_doc);
|
|
1017
964
|
Data_Get_Struct(schema, ruby_xml_schema, c_schema);
|
|
1018
965
|
|
|
1019
966
|
vptr = xmlSchemaNewValidCtxt(c_schema->schema);
|
|
@@ -1040,10 +987,10 @@ ruby_xml_document_validate_schema(VALUE self, VALUE schema) {
|
|
|
1040
987
|
VALUE
|
|
1041
988
|
ruby_xml_document_validate_dtd(VALUE self, VALUE dtd) {
|
|
1042
989
|
xmlValidCtxt cvp;
|
|
1043
|
-
|
|
990
|
+
ruby_xml_document_t *c_doc;
|
|
1044
991
|
ruby_xml_dtd *c_dtd;
|
|
1045
992
|
|
|
1046
|
-
Data_Get_Struct(self,
|
|
993
|
+
Data_Get_Struct(self, ruby_xml_document_t, c_doc);
|
|
1047
994
|
Data_Get_Struct(dtd, ruby_xml_dtd, c_dtd);
|
|
1048
995
|
|
|
1049
996
|
cvp.userData = NULL;
|
|
@@ -1106,6 +1053,19 @@ validate(self, ...)
|
|
|
1106
1053
|
*/
|
|
1107
1054
|
}
|
|
1108
1055
|
|
|
1056
|
+
/*
|
|
1057
|
+
* call-seq:
|
|
1058
|
+
* document.reader => reader
|
|
1059
|
+
*
|
|
1060
|
+
* Create a XML::Reader from the document. This is a shortcut to
|
|
1061
|
+
* XML::Reader.walker().
|
|
1062
|
+
*/
|
|
1063
|
+
static VALUE
|
|
1064
|
+
ruby_xml_document_reader(VALUE self)
|
|
1065
|
+
{
|
|
1066
|
+
return ruby_xml_reader_new_walker(cXMLReader, self);
|
|
1067
|
+
}
|
|
1068
|
+
|
|
1109
1069
|
// Rdoc needs to know
|
|
1110
1070
|
#ifdef RDOC_NEVER_DEFINED
|
|
1111
1071
|
mXML = rb_define_module("XML");
|
|
@@ -1115,7 +1075,7 @@ void
|
|
|
1115
1075
|
ruby_init_xml_document(void) {
|
|
1116
1076
|
cXMLDocument = rb_define_class_under(mXML, "Document", rb_cObject);
|
|
1117
1077
|
rb_define_singleton_method(cXMLDocument, "file", ruby_xml_document_new_file, 1);
|
|
1118
|
-
rb_define_singleton_method(cXMLDocument, "new",
|
|
1078
|
+
rb_define_singleton_method(cXMLDocument, "new", ruby_xml_document_new, -1);
|
|
1119
1079
|
|
|
1120
1080
|
//rb_raise(eXMLNodeFailedModify, "unable to add a child to the document");
|
|
1121
1081
|
//eDTDValidityWarning = rb_define_class_under(cXMLNode, "ValidityWarning", eXMLError);
|
|
@@ -1154,4 +1114,5 @@ ruby_init_xml_document(void) {
|
|
|
1154
1114
|
rb_define_method(cXMLDocument, "xinclude", ruby_xml_document_xinclude, 0);
|
|
1155
1115
|
rb_define_method(cXMLDocument, "validate", ruby_xml_document_validate_dtd, 1);
|
|
1156
1116
|
rb_define_method(cXMLDocument, "validate_schema", ruby_xml_document_validate_schema, 1);
|
|
1117
|
+
rb_define_method(cXMLDocument, "reader", ruby_xml_document_reader, 0);
|
|
1157
1118
|
}
|
data/ext/xml/ruby_xml_document.h
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* $Id: ruby_xml_document.h
|
|
1
|
+
/* $Id: ruby_xml_document.h 138 2007-08-29 18:00:35Z danj $ */
|
|
2
2
|
|
|
3
3
|
/* Please see the LICENSE file for copyright and distribution information */
|
|
4
4
|
|
|
@@ -11,16 +11,12 @@ typedef struct rxp_document {
|
|
|
11
11
|
xmlDocPtr doc; /* Tree/DOM interface */
|
|
12
12
|
int data_type; /* The data type referenced by *data */
|
|
13
13
|
void *data; /* Pointer to an external structure of options */
|
|
14
|
-
|
|
15
|
-
VALUE xmlver; /* T_STRING with the xml version */
|
|
16
|
-
} ruby_xml_document;
|
|
14
|
+
} ruby_xml_document_t;
|
|
17
15
|
|
|
18
16
|
VALUE ruby_xml_document_filename_get(VALUE self);
|
|
19
|
-
|
|
20
|
-
VALUE
|
|
21
|
-
|
|
22
|
-
VALUE ruby_xml_document_new3(VALUE class);
|
|
23
|
-
VALUE ruby_xml_document_new4(VALUE class, xmlDocPtr doc);
|
|
17
|
+
VALUE ruby_xml_document_new_native(VALUE class, VALUE xmlver);
|
|
18
|
+
VALUE ruby_xml_document_wrap(VALUE class, xmlDocPtr xnode);
|
|
19
|
+
void ruby_xml_document_free(ruby_xml_document_t *rxd);
|
|
24
20
|
VALUE ruby_xml_document_root_get(VALUE self);
|
|
25
21
|
void ruby_init_xml_document(void);
|
|
26
22
|
|