libxml-ruby 0.5.4 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (139) hide show
  1. data/LICENSE +23 -23
  2. data/README +144 -144
  3. data/ext/libxml/extconf.rb +26 -27
  4. data/ext/libxml/libxml.c +7 -37
  5. data/ext/libxml/{libxml.h → ruby_libxml.h} +93 -98
  6. data/ext/libxml/ruby_xml_attr.c +405 -387
  7. data/ext/libxml/ruby_xml_attr.h +19 -18
  8. data/ext/libxml/ruby_xml_document.c +1111 -1115
  9. data/ext/libxml/ruby_xml_document.h +27 -24
  10. data/ext/libxml/ruby_xml_dtd.c +168 -168
  11. data/ext/libxml/ruby_xml_html_parser.c +449 -450
  12. data/ext/libxml/ruby_xml_html_parser.h +1 -1
  13. data/ext/libxml/ruby_xml_input_cbg.c +158 -158
  14. data/ext/libxml/ruby_xml_node.c +2410 -2395
  15. data/ext/libxml/ruby_xml_node.h +1 -1
  16. data/ext/libxml/ruby_xml_node_set.c +170 -170
  17. data/ext/libxml/ruby_xml_node_set.h +1 -1
  18. data/ext/libxml/ruby_xml_ns.c +153 -153
  19. data/ext/libxml/ruby_xml_ns.h +1 -1
  20. data/ext/libxml/ruby_xml_parser.c +1425 -1422
  21. data/ext/libxml/ruby_xml_parser.h +1 -1
  22. data/ext/libxml/ruby_xml_parser_context.c +750 -716
  23. data/ext/libxml/ruby_xml_parser_context.h +1 -1
  24. data/ext/libxml/ruby_xml_reader.c +900 -896
  25. data/ext/libxml/ruby_xml_sax_parser.c +485 -485
  26. data/ext/libxml/ruby_xml_sax_parser.h +1 -1
  27. data/ext/libxml/ruby_xml_schema.c +146 -142
  28. data/ext/libxml/ruby_xml_state.c +5 -6
  29. data/ext/libxml/ruby_xml_state.h +1 -0
  30. data/ext/libxml/ruby_xml_tree.c +43 -43
  31. data/ext/libxml/ruby_xml_tree.h +1 -1
  32. data/ext/libxml/ruby_xml_xinclude.c +20 -20
  33. data/ext/libxml/ruby_xml_xinclude.h +1 -1
  34. data/ext/libxml/ruby_xml_xpath.c +243 -252
  35. data/ext/libxml/ruby_xml_xpath.h +1 -1
  36. data/ext/libxml/ruby_xml_xpath_context.c +118 -118
  37. data/ext/libxml/ruby_xml_xpath_context.h +1 -1
  38. data/ext/libxml/ruby_xml_xpath_object.c +43 -29
  39. data/ext/libxml/ruby_xml_xpath_object.h +0 -1
  40. data/ext/libxml/ruby_xml_xpointer.c +100 -100
  41. data/ext/libxml/ruby_xml_xpointer.h +1 -1
  42. data/ext/libxml/ruby_xml_xpointer_context.c +21 -21
  43. data/ext/libxml/ruby_xml_xpointer_context.h +1 -1
  44. data/ext/libxml/sax_parser_callbacks.inc +213 -213
  45. data/ext/libxml/version.h +9 -9
  46. data/lib/libxml.rb +24 -3
  47. data/mingw/libiconv-2.dll +0 -0
  48. data/mingw/libxml2-2.dll +0 -0
  49. data/mingw/libxml_ruby.so +0 -0
  50. data/mingw/mingw.rake +36 -0
  51. data/test/dtd-test.rb +24 -24
  52. data/test/etc_doc_to_s.rb +1 -3
  53. data/test/ets_copy_bug.rb +21 -21
  54. data/test/ets_copy_bug2.rb +32 -32
  55. data/test/ets_copy_bug3.rb +38 -0
  56. data/test/ets_doc_file.rb +1 -0
  57. data/test/{model/default_validation_bug.rb → gc.log} +0 -0
  58. data/test/merge_bug.rb +55 -55
  59. data/test/schema-test.rb +74 -74
  60. data/test/tc_well_formed.rb +11 -0
  61. data/test/tc_xml_document.rb +52 -52
  62. data/test/tc_xml_document_write.rb +24 -24
  63. data/test/tc_xml_document_write2.rb +54 -54
  64. data/test/tc_xml_document_write3.rb +96 -96
  65. data/test/tc_xml_html_parser.rb +63 -63
  66. data/test/tc_xml_node.rb +59 -59
  67. data/test/tc_xml_node2.rb +25 -25
  68. data/test/tc_xml_node3.rb +27 -27
  69. data/test/tc_xml_node4.rb +86 -86
  70. data/test/tc_xml_node5.rb +52 -52
  71. data/test/tc_xml_node6.rb +27 -27
  72. data/test/tc_xml_node7.rb +35 -35
  73. data/test/tc_xml_node8.rb +32 -32
  74. data/test/tc_xml_node9.rb +32 -32
  75. data/test/tc_xml_node_set.rb +24 -24
  76. data/test/tc_xml_node_set2.rb +37 -37
  77. data/test/tc_xml_node_xlink.rb +28 -28
  78. data/test/tc_xml_parser.rb +190 -178
  79. data/test/tc_xml_parser2.rb +16 -17
  80. data/test/tc_xml_parser3.rb +23 -23
  81. data/test/tc_xml_parser4.rb +33 -33
  82. data/test/tc_xml_parser5.rb +27 -27
  83. data/test/tc_xml_parser6.rb +23 -23
  84. data/test/tc_xml_parser7.rb +28 -28
  85. data/test/tc_xml_parser8.rb +32 -32
  86. data/test/tc_xml_parser9.rb +11 -0
  87. data/test/tc_xml_parser_context.rb +88 -88
  88. data/test/tc_xml_reader.rb +112 -109
  89. data/test/tc_xml_sax_parser.rb +104 -94
  90. data/test/tc_xml_sax_parser2.rb +51 -0
  91. data/test/tc_xml_xinclude.rb +30 -30
  92. data/test/tc_xml_xpath.rb +38 -38
  93. data/test/tc_xml_xpath2.rb +14 -0
  94. data/test/tc_xml_xpointer.rb +78 -78
  95. data/vc/libxml.sln +20 -0
  96. data/vc/libxml.vcproj +389 -0
  97. data/work/Rakefile +247 -0
  98. data/work/task/make +26 -0
  99. data/work/task/memory +37 -0
  100. data/work/task/rdoc +39 -0
  101. data/work/task/setup +1616 -0
  102. data/work/task/test +29 -0
  103. data/work/test/ets_runner.rb +33 -0
  104. data/work/test/libxml_test.rb +3 -0
  105. data/work/test/runner.rb +0 -0
  106. data/work/test/runner_ets.rb +33 -0
  107. data/work/vc/debug/libxml.exp +0 -0
  108. data/work/vc/debug/libxml.ilk +0 -0
  109. data/work/vc/debug/libxml.lib +0 -0
  110. data/work/vc/debug/libxml.pdb +0 -0
  111. data/work/vc/debug/libxml.so +0 -0
  112. metadata +158 -189
  113. data/MANIFEST +0 -138
  114. data/NOTES +0 -9
  115. data/Rakefile +0 -38
  116. data/TODO +0 -75
  117. data/VERSION +0 -1
  118. data/log/Changelog-0.txt +0 -426
  119. data/log/Changelog.txt +0 -435
  120. data/meta/project.yaml +0 -27
  121. data/meta/unixname +0 -1
  122. data/setup.rb +0 -1472
  123. data/site/css/normal.css +0 -182
  124. data/site/img/raze-tiny.png +0 -0
  125. data/site/img/red-cube.jpg +0 -0
  126. data/site/img/xml-ruby.png +0 -0
  127. data/site/index.xml +0 -43
  128. data/site/install.xml +0 -77
  129. data/site/layout.rhtml +0 -38
  130. data/site/layout.xsl +0 -67
  131. data/site/license.xml +0 -32
  132. data/site/log/changelog.xml +0 -1324
  133. data/site/log/changelog.xsl +0 -42
  134. data/test/model/merge_bug_data.xml +0 -58
  135. data/test/model/rubynet.xml +0 -78
  136. data/test/model/rubynet_project +0 -13
  137. data/test/model/saxtest.xml +0 -5
  138. data/test/model/simple.xml +0 -7
  139. data/test/model/xinclude.xml +0 -5
@@ -1,896 +1,900 @@
1
- /* Copyright (c) 2006-2007 Apple Inc.
2
- * Please see the LICENSE file for copyright and distribution information. */
3
-
4
- #include "libxml.h"
5
- #include "ruby_xml_reader.h"
6
-
7
- #define CSTR2RVAL(x) (x == NULL ? Qnil : rb_str_new2((const char *)x))
8
- #define RVAL2CSTR(x) (StringValueCStr(x))
9
-
10
- static inline VALUE
11
- __rb_str_new_and_free(xmlChar *x)
12
- {
13
- if (x != NULL) {
14
- VALUE v = rb_str_new2((const char *)x);
15
- xmlFree(x);
16
- return v;
17
- }
18
- return Qnil;
19
- }
20
-
21
- #define CSTR2RVAL2(x) (__rb_str_new_and_free(x))
22
-
23
- VALUE cXMLReader;
24
- static ID error_handler_block_ivar_id;
25
-
26
- static VALUE
27
- ruby_xml_reader_new(VALUE class, xmlTextReaderPtr reader)
28
- {
29
- return Data_Wrap_Struct(class, NULL, xmlFreeTextReader, reader);
30
- }
31
-
32
- static xmlTextReaderPtr
33
- __ruby_xml_parser_get(VALUE obj)
34
- {
35
- xmlTextReaderPtr ptr;
36
- Data_Get_Struct(obj, xmlTextReader, ptr);
37
- return ptr;
38
- }
39
-
40
- #if defined(_SELF)
41
- # undef _SELF
42
- #endif
43
- #define _SELF(x) (__ruby_xml_parser_get(x))
44
-
45
- /*
46
- * call-seq:
47
- * XML::Reader.file(path, encoding=nil, options=0) -> reader
48
- *
49
- * Parse an XML file from the filesystem or the network. The parsing flags
50
- * options are a combination of xmlParserOption.
51
- */
52
- static VALUE
53
- ruby_xml_reader_new_file(int argc, VALUE *argv, VALUE self)
54
- {
55
- xmlTextReaderPtr reader;
56
- VALUE path, encoding, options;
57
-
58
- rb_scan_args(argc, argv, "12", &path, &encoding, &options);
59
-
60
- reader = xmlReaderForFile(RVAL2CSTR(path),
61
- NIL_P(encoding) ? NULL : RVAL2CSTR(encoding),
62
- NIL_P(options) ? 0 : FIX2INT(options));
63
- if (reader == NULL)
64
- rb_raise(rb_eRuntimeError,
65
- "cannot create text reader for given XML file at path '%s'",
66
- RVAL2CSTR(path));
67
-
68
- return ruby_xml_reader_new(self, reader);
69
- }
70
-
71
- /*
72
- * call-seq:
73
- * XML::Reader.walker(doc) -> reader
74
- * XML::Reader.document(doc) -> reader
75
- *
76
- * Create an XML text reader for a preparsed document.
77
- */
78
- VALUE
79
- ruby_xml_reader_new_walker(VALUE self, VALUE doc)
80
- {
81
- ruby_xml_document_t *rxd;
82
- xmlTextReaderPtr reader;
83
-
84
- Data_Get_Struct(doc, ruby_xml_document_t, rxd);
85
-
86
- reader = xmlReaderWalker(rxd->doc);
87
- if (reader == NULL)
88
- rb_raise(rb_eRuntimeError, "cannot create text reader for given document");
89
-
90
- return ruby_xml_reader_new(self, reader);
91
- }
92
-
93
- /*
94
- * call-seq:
95
- * XML::Reader.new(data, url=nil, encoding=nil, options=0) -> reader
96
- * XML::Reader.string(data, url=nil, encoding=nil, options=0) -> reader
97
- *
98
- * Create an XML text reader for an XML in-memory document. The parsing flags
99
- * options are a combination of xmlParserOption.
100
- */
101
- static VALUE
102
- ruby_xml_reader_new_data(int argc, VALUE *argv, VALUE self)
103
- {
104
- xmlTextReaderPtr reader;
105
- VALUE data, url, encoding, options;
106
- char *c_data;
107
-
108
- rb_scan_args(argc, argv, "13", &data, &url, &encoding, &options);
109
-
110
- c_data = RVAL2CSTR(data);
111
- reader = xmlReaderForMemory(c_data,
112
- strlen(c_data),
113
- NIL_P(url) ? NULL : RVAL2CSTR(url),
114
- NIL_P(encoding) ? NULL : RVAL2CSTR(encoding),
115
- NIL_P(options) ? 0 : FIX2INT(options));
116
- if (reader == NULL)
117
- rb_raise(rb_eRuntimeError, "cannot create text reader for given data");
118
-
119
- return ruby_xml_reader_new(self, reader);
120
- }
121
-
122
- /*
123
- * call-seq:
124
- * parser.close -> code
125
- *
126
- * This method releases any resources allocated by the current instance
127
- * changes the state to Closed and close any underlying input.
128
- */
129
- static VALUE
130
- ruby_xml_reader_close(VALUE self)
131
- {
132
- return INT2FIX(xmlTextReaderClose(_SELF(self)));
133
- }
134
-
135
- /*
136
- * call-seq:
137
- * parser.move_to_attribute(val) -> code
138
- *
139
- * Move the position of the current instance to the attribute with the
140
- * specified index (if +val+ is an integer) or name (if +val+ is a string)
141
- * relative to the containing element.
142
- */
143
- static VALUE
144
- ruby_xml_reader_move_to_attr(VALUE self, VALUE val)
145
- {
146
- xmlTextReaderPtr reader;
147
- int ret;
148
-
149
- reader = _SELF(self);
150
-
151
- if (TYPE(val) == T_FIXNUM) {
152
- ret = xmlTextReaderMoveToAttributeNo(reader, FIX2INT(val));
153
- }
154
- else {
155
- ret = xmlTextReaderMoveToAttribute(reader, (const xmlChar *)RVAL2CSTR(val));
156
- }
157
-
158
- return INT2FIX(ret);
159
- }
160
-
161
- /*
162
- * call-seq:
163
- * reader.move_to_first_attribute -> code
164
- *
165
- * Move the position of the current instance to the first attribute associated
166
- * with the current node.
167
- */
168
- static VALUE
169
- ruby_xml_reader_move_to_first_attr(VALUE self)
170
- {
171
- return INT2FIX(xmlTextReaderMoveToFirstAttribute(_SELF(self)));
172
- }
173
-
174
- /*
175
- * call-seq:
176
- * reader.move_to_next_attribute -> code
177
- *
178
- * Move the position of the current instance to the next attribute associated
179
- * with the current node.
180
- */
181
- static VALUE
182
- ruby_xml_reader_move_to_next_attr(VALUE self)
183
- {
184
- return INT2FIX(xmlTextReaderMoveToNextAttribute(_SELF(self)));
185
- }
186
-
187
- /*
188
- * call-seq:
189
- * reader.move_to_element -> code
190
- *
191
- * Move the position of the current instance to the node that contains the
192
- * current attribute node.
193
- */
194
- static VALUE
195
- ruby_xml_reader_move_to_element(VALUE self)
196
- {
197
- return INT2FIX(xmlTextReaderMoveToElement(_SELF(self)));
198
- }
199
-
200
- /*
201
- * call-seq:
202
- * reader.next -> code
203
- *
204
- * Skip to the node following the current one in document order while avoiding
205
- * the subtree if any.
206
- */
207
- static VALUE
208
- ruby_xml_reader_next(VALUE self)
209
- {
210
- return INT2FIX(xmlTextReaderNext(_SELF(self)));
211
- }
212
-
213
- /*
214
- * call-seq:
215
- * reader.next_sibling -> code
216
- *
217
- * Skip to the node following the current one in document order while avoiding
218
- * the subtree if any. Currently implemented only for Readers built on a
219
- * document.
220
- */
221
- static VALUE
222
- ruby_xml_reader_next_sibling(VALUE self)
223
- {
224
- return INT2FIX(xmlTextReaderNextSibling(_SELF(self)));
225
- }
226
-
227
- /*
228
- * call-seq:
229
- * reader.node_type -> type
230
- *
231
- * Get the node type of the current node. Reference:
232
- * http://dotgnu.org/pnetlib-doc/System/Xml/XmlNodeType.html
233
- */
234
- static VALUE
235
- ruby_xml_reader_node_type(VALUE self)
236
- {
237
- return INT2FIX(xmlTextReaderNodeType(_SELF(self)));
238
- }
239
-
240
- /*
241
- * call-seq:
242
- * reader.normalization -> value
243
- *
244
- * The value indicating whether to normalize white space and attribute values.
245
- * Since attribute value and end of line normalizations are a MUST in the XML
246
- * specification only the value true is accepted. The broken bahaviour of
247
- * accepting out of range character entities like � is of course not
248
- * supported either.
249
- *
250
- * Return 1 or -1 in case of error.
251
- */
252
- static VALUE
253
- ruby_xml_reader_normalization(VALUE self)
254
- {
255
- return INT2FIX(xmlTextReaderNormalization(_SELF(self)));
256
- }
257
-
258
- /*
259
- * call-seq:
260
- * reader.read -> code
261
- *
262
- * Move the position of the current instance to the next node in the stream,
263
- * exposing its properties.
264
- *
265
- * Return 1 if the node was read successfully, 0 if there is no more nodes to
266
- * read, or -1 in case of error.
267
- */
268
- static VALUE
269
- ruby_xml_reader_read(VALUE self)
270
- {
271
- return INT2FIX(xmlTextReaderRead(_SELF(self)));
272
- }
273
-
274
- /*
275
- * call-seq:
276
- * reader.read_attribute_value -> code
277
- *
278
- * Parse an attribute value into one or more Text and EntityReference nodes.
279
- *
280
- * Return 1 in case of success, 0 if the reader was not positionned on an
281
- * attribute node or all the attribute values have been read, or -1 in case of
282
- * error.
283
- */
284
- static VALUE
285
- ruby_xml_reader_read_attr_value(VALUE self)
286
- {
287
- return INT2FIX(xmlTextReaderReadAttributeValue(_SELF(self)));
288
- }
289
-
290
- /*
291
- * call-seq:
292
- * reader.read_inner_xml -> data
293
- *
294
- * Read the contents of the current node, including child nodes and markup.
295
- *
296
- * Return a string containing the XML content, or nil if the current node is
297
- * neither an element nor attribute, or has no child nodes.
298
- */
299
- static VALUE
300
- ruby_xml_reader_read_inner_xml(VALUE self)
301
- {
302
- return CSTR2RVAL2(xmlTextReaderReadInnerXml(_SELF(self)));
303
- }
304
-
305
- /*
306
- * call-seq:
307
- * reader.read_outer_xml -> data
308
- *
309
- * Read the contents of the current node, including child nodes and markup.
310
- *
311
- * Return a string containing the XML content, or nil if the current node is
312
- * neither an element nor attribute, or has no child nodes.
313
- */
314
- static VALUE
315
- ruby_xml_reader_read_outer_xml(VALUE self)
316
- {
317
- return CSTR2RVAL2(xmlTextReaderReadOuterXml(_SELF(self)));
318
- }
319
-
320
- /*
321
- * call-seq:
322
- * reader.read_state -> state
323
- *
324
- * Get the read state of the reader.
325
- */
326
- static VALUE
327
- ruby_xml_reader_read_state(VALUE self)
328
- {
329
- return INT2FIX(xmlTextReaderReadState(_SELF(self)));
330
- }
331
-
332
- /*
333
- * call-seq:
334
- * reader.read_string -> string
335
- *
336
- * Read the contents of an element or a text node as a string.
337
- *
338
- * Return a string containing the contents of the Element or Text node, or nil
339
- * if the reader is positioned on any other type of node.
340
- */
341
- static VALUE
342
- ruby_xml_reader_read_string(VALUE self)
343
- {
344
- return CSTR2RVAL2(xmlTextReaderReadString(_SELF(self)));
345
- }
346
-
347
- static void
348
- __xml_reader_error_cb(void *arg,
349
- const char *msg, xmlParserSeverities severity,
350
- xmlTextReaderLocatorPtr locator)
351
- {
352
- VALUE reader;
353
- VALUE block;
354
-
355
- reader = (VALUE)arg;
356
- block = rb_ivar_get(reader, error_handler_block_ivar_id);
357
- if (NIL_P(block))
358
- rb_bug("no ivar block");
359
-
360
- rb_funcall(block,
361
- rb_intern("call"),
362
- 5,
363
- reader,
364
- CSTR2RVAL(msg),
365
- INT2FIX(severity),
366
- CSTR2RVAL2(xmlTextReaderLocatorBaseURI(locator)),
367
- INT2FIX(xmlTextReaderLocatorLineNumber(locator)));
368
- }
369
-
370
- /*
371
- * call-seq:
372
- * reader.set_error_handler { ... }
373
- *
374
- * Register a callback block that will be called on error and warnings. The
375
- * block will be called with 5 parameters: the reader, the error message, the
376
- * severity, the base URI and the line number.
377
- */
378
- static VALUE
379
- ruby_xml_reader_set_error_handler(VALUE self)
380
- {
381
- VALUE block;
382
- xmlTextReaderPtr reader;
383
-
384
- if (rb_block_given_p() == Qfalse)
385
- rb_raise(rb_eRuntimeError, "No block given");
386
-
387
- block = rb_block_proc();
388
-
389
- /* Embed the block within the parser object to avoid it to be collected.
390
- * Previous handler if exits is overwritten.
391
- */
392
- rb_ivar_set(self, error_handler_block_ivar_id, block);
393
- reader = _SELF(self);
394
- xmlTextReaderSetErrorHandler(reader, __xml_reader_error_cb, (void *)self);
395
-
396
- return self;
397
- }
398
-
399
- /*
400
- * call-seq:
401
- * reader.reset_error_handler
402
- *
403
- * Restore the default error and warning handlers.
404
- */
405
- static VALUE
406
- ruby_xml_reader_reset_error_handler(VALUE self)
407
- {
408
- xmlTextReaderSetErrorHandler(_SELF(self), NULL, NULL);
409
- return self;
410
- }
411
-
412
- /*
413
- * call-seq:
414
- * reader.relax_ng_validate(rng) -> code
415
- *
416
- * Use RelaxNG to validate the document as it is processed. Activation is only
417
- * possible before the first read. If +rng+ is nil, the RelaxNG validation is
418
- * desactivated.
419
- *
420
- * Return 0 in case the RelaxNG validation could be (des)activated and -1 in
421
- * case of error.
422
- */
423
- static VALUE
424
- ruby_xml_reader_relax_ng_validate(VALUE self, VALUE rng)
425
- {
426
- return INT2FIX(xmlTextReaderRelaxNGValidate(_SELF(self), NIL_P(rng) ? NULL : RVAL2CSTR(rng)));
427
- }
428
-
429
- #if LIBXML_VERSION >= 20620
430
- /*
431
- * call-seq:
432
- * reader.schema_validate(schema) -> code
433
- *
434
- * Use W3C XSD schema to validate the document as it is processed. Activation
435
- * is only possible before the first read. If +schema+ is nil, then XML Schema
436
- * validation is desactivated.
437
- *
438
- * Return 0 in case the schemas validation could be (de)activated and -1 in
439
- * case of error.
440
- */
441
- static VALUE
442
- ruby_xml_reader_schema_validate(VALUE self, VALUE xsd)
443
- {
444
- return INT2FIX(xmlTextReaderSchemaValidate(_SELF(self), NIL_P(xsd) ? NULL : RVAL2CSTR(xsd)));
445
- }
446
- #endif
447
-
448
- /*
449
- * call-seq:
450
- * reader.name -> name
451
- *
452
- * Return the qualified name of the node.
453
- */
454
- static VALUE
455
- ruby_xml_reader_name(VALUE self)
456
- {
457
- return CSTR2RVAL(xmlTextReaderConstName(_SELF(self)));
458
- }
459
-
460
- /*
461
- * call-seq:
462
- * reader.local_name -> name
463
- *
464
- * Return the local name of the node.
465
- */
466
- static VALUE
467
- ruby_xml_reader_local_name(VALUE self)
468
- {
469
- return CSTR2RVAL(xmlTextReaderConstLocalName(_SELF(self)));
470
- }
471
-
472
- /*
473
- * call-seq:
474
- * reader.attribute_count -> count
475
- *
476
- * Provide the number of attributes of the current node.
477
- */
478
- static VALUE
479
- ruby_xml_reader_attr_count(VALUE self)
480
- {
481
- return INT2FIX(xmlTextReaderAttributeCount(_SELF(self)));
482
- }
483
-
484
- /*
485
- * call-seq:
486
- * reader.encoding -> encoding
487
- *
488
- * Determine the encoding of the document being read.
489
- */
490
- static VALUE
491
- ruby_xml_reader_encoding(VALUE self)
492
- {
493
- return CSTR2RVAL(xmlTextReaderConstEncoding(_SELF(self)));
494
- }
495
-
496
- /*
497
- * call-seq:
498
- * reader.base_uri -> URI
499
- *
500
- * Determine the base URI of the node.
501
- */
502
- static VALUE
503
- ruby_xml_reader_base_uri(VALUE self)
504
- {
505
- return CSTR2RVAL(xmlTextReaderConstBaseUri(_SELF(self)));
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
- ruby_xml_reader_namespace_uri(VALUE self)
516
- {
517
- return CSTR2RVAL(xmlTextReaderConstNamespaceUri(_SELF(self)));
518
- }
519
-
520
- /*
521
- * call-seq:
522
- * reader.value -> text
523
- *
524
- * Provide the text value of the node if present.
525
- */
526
- static VALUE
527
- ruby_xml_reader_value(VALUE self)
528
- {
529
- return CSTR2RVAL(xmlTextReaderConstValue(_SELF(self)));
530
- }
531
-
532
- /*
533
- * call-seq:
534
- * reader.prefix -> prefix
535
- *
536
- * Get a shorthand reference to the namespace associated with the node.
537
- */
538
- static VALUE
539
- ruby_xml_reader_prefix(VALUE self)
540
- {
541
- return CSTR2RVAL(xmlTextReaderConstPrefix(_SELF(self)));
542
- }
543
-
544
- /*
545
- * call-seq:
546
- * reader.depth -> depth
547
- *
548
- * Get the depth of the node in the tree.
549
- */
550
- static VALUE
551
- ruby_xml_reader_depth(VALUE self)
552
- {
553
- return INT2FIX(xmlTextReaderDepth(_SELF(self)));
554
- }
555
-
556
- /*
557
- * call-seq:
558
- * reader.quote_char -> char
559
- *
560
- * Get the quotation mark character used to enclose the value of an attribute,
561
- * as an integer value (and -1 in case of error).
562
- */
563
- static VALUE
564
- ruby_xml_reader_quote_char(VALUE self)
565
- {
566
- return INT2FIX(xmlTextReaderQuoteChar(_SELF(self)));
567
- }
568
-
569
- /*
570
- * call-seq:
571
- * reader.standalone -> code
572
- *
573
- * Determine the standalone status of the document being read.
574
- *
575
- * Return 1 if the document was declared to be standalone, 0 if it was
576
- * declared to be not standalone, or -1 if the document did not specify its
577
- * standalone status or in case of error.
578
- */
579
- static VALUE
580
- ruby_xml_reader_standalone(VALUE self)
581
- {
582
- return INT2FIX(xmlTextReaderStandalone(_SELF(self)));
583
- }
584
-
585
- /*
586
- * call-seq:
587
- * reader.xml_lang -> value
588
- *
589
- * Get the xml:lang scope within which the node resides.
590
- */
591
- static VALUE
592
- ruby_xml_reader_xml_lang(VALUE self)
593
- {
594
- return CSTR2RVAL(xmlTextReaderConstXmlLang(_SELF(self)));
595
- }
596
-
597
- /*
598
- * call-seq:
599
- * reader.xml_version -> version
600
- *
601
- * Determine the XML version of the document being read.
602
- */
603
- static VALUE
604
- ruby_xml_reader_xml_version(VALUE self)
605
- {
606
- return CSTR2RVAL(xmlTextReaderConstXmlVersion(_SELF(self)));
607
- }
608
-
609
- /*
610
- * call-seq:
611
- * reader.has_attributes? -> bool
612
- *
613
- * Get whether the node has attributes.
614
- */
615
- static VALUE
616
- ruby_xml_reader_has_attributes(VALUE self)
617
- {
618
- return xmlTextReaderHasAttributes(_SELF(self)) ? Qtrue : Qfalse;
619
- }
620
-
621
- /*
622
- * call-seq:
623
- * reader.has_value? -> bool
624
- *
625
- * Get whether the node can have a text value.
626
- */
627
- static VALUE
628
- ruby_xml_reader_has_value(VALUE self)
629
- {
630
- return xmlTextReaderHasValue(_SELF(self)) ? Qtrue : Qfalse;
631
- }
632
-
633
- /*
634
- * call-seq:
635
- * reader[key] -> value
636
- *
637
- * Provide the value of the attribute with the specified index (if +key+ is an
638
- * integer) or with the specified name (if +key+ is a string) relative to the
639
- * containing element, as a string.
640
- */
641
- static VALUE
642
- ruby_xml_reader_attribute(VALUE self, VALUE key)
643
- {
644
- xmlTextReaderPtr reader;
645
- xmlChar *attr;
646
-
647
- reader = _SELF(self);
648
-
649
- if (TYPE(key) == T_FIXNUM) {
650
- attr = xmlTextReaderGetAttributeNo(reader, FIX2INT(key));
651
- }
652
- else {
653
- attr = xmlTextReaderGetAttribute(reader, (const xmlChar *)RVAL2CSTR(key));
654
- }
655
- return CSTR2RVAL2(attr);
656
- }
657
-
658
- /*
659
- * call-seq:
660
- * reader.lookup_namespace(prefix) -> value
661
- *
662
- * Resolve a namespace prefix in the scope of the current element.
663
- * To return the default namespace, specify nil as +prefix+.
664
- */
665
- static VALUE
666
- ruby_xml_reader_lookup_namespace(VALUE self, VALUE prefix)
667
- {
668
- return CSTR2RVAL2(xmlTextReaderLookupNamespace(_SELF(self), (const xmlChar *)RVAL2CSTR(prefix)));
669
- }
670
-
671
- /*
672
- * call-seq:
673
- * reader.expand -> node
674
- *
675
- * Read the contents of the current node and the full subtree. It then makes
676
- * the subtree available until the next read call.
677
- *
678
- * Return an XML::Node object, or nil in case of error.
679
- */
680
- static VALUE
681
- ruby_xml_reader_expand(VALUE self)
682
- {
683
- xmlNodePtr node;
684
-
685
- node = xmlTextReaderExpand(_SELF(self));
686
- if (NIL_P(node))
687
- return Qnil;
688
-
689
- if ( node->doc != NULL )
690
- ruby_xml_document_wrap2(node->doc);
691
-
692
- return ruby_xml_node2_wrap(cXMLNode, node);
693
- }
694
-
695
- #if LIBXML_VERSION >= 20618
696
- /*
697
- * call-seq:
698
- * reader.byte_consumed -> value
699
- *
700
- * This method provides the current index of the parser used by the reader,
701
- * relative to the start of the current entity.
702
- */
703
- static VALUE
704
- ruby_xml_reader_byte_consumed(VALUE self)
705
- {
706
- return INT2NUM(xmlTextReaderByteConsumed(_SELF(self)));
707
- }
708
- #endif
709
-
710
- #if LIBXML_VERSION >= 20617
711
- /*
712
- * call-seq:
713
- * reader.column_number -> number
714
- *
715
- * Provide the column number of the current parsing point.
716
- */
717
- static VALUE
718
- ruby_xml_reader_column_number(VALUE self)
719
- {
720
- return INT2NUM(xmlTextReaderGetParserColumnNumber(_SELF(self)));
721
- }
722
-
723
- /*
724
- * call-seq:
725
- * reader.line_number -> number
726
- *
727
- * Provide the line number of the current parsing point.
728
- */
729
- static VALUE
730
- ruby_xml_reader_line_number(VALUE self)
731
- {
732
- return INT2NUM(xmlTextReaderGetParserLineNumber(_SELF(self)));
733
- }
734
- #endif
735
-
736
- /*
737
- * call-seq:
738
- * reader.default? -> bool
739
- *
740
- * Return whether an Attribute node was generated from the default value
741
- * defined in the DTD or schema.
742
- */
743
- static VALUE
744
- ruby_xml_reader_default(VALUE self)
745
- {
746
- return xmlTextReaderIsDefault(_SELF(self)) ? Qtrue : Qfalse;
747
- }
748
-
749
- /*
750
- * call-seq:
751
- * reader.namespace_declaration? -> bool
752
- *
753
- * Determine whether the current node is a namespace declaration rather than a
754
- * regular attribute.
755
- */
756
- static VALUE
757
- ruby_xml_reader_namespace_declaration(VALUE self)
758
- {
759
- return xmlTextReaderIsNamespaceDecl(_SELF(self)) ? Qtrue : Qfalse;
760
- }
761
-
762
- /*
763
- * call-seq:
764
- * reader.empty_element? -> bool
765
- *
766
- * Check if the current node is empty.
767
- */
768
- static VALUE
769
- ruby_xml_reader_empty_element(VALUE self)
770
- {
771
- return xmlTextReaderIsEmptyElement(_SELF(self)) ? Qtrue : Qfalse;
772
- }
773
-
774
- /*
775
- * call-seq:
776
- * reader.valid? -> bool
777
- *
778
- * Retrieve the validity status from the parser context.
779
- */
780
- static VALUE
781
- ruby_xml_reader_valid(VALUE self)
782
- {
783
- return xmlTextReaderIsValid(_SELF(self)) ? Qtrue : Qfalse;
784
- }
785
-
786
- /* Rdoc needs to know. */
787
- #ifdef RDOC_NEVER_DEFINED
788
- mXML = rb_define_module("XML");
789
- #endif
790
-
791
- void
792
- ruby_init_xml_reader(void)
793
- {
794
- cXMLReader = rb_define_class_under(mXML, "Reader", rb_cObject);
795
- error_handler_block_ivar_id = rb_intern("@__error_handler_callback__");
796
-
797
- rb_define_singleton_method(cXMLReader, "file", ruby_xml_reader_new_file, -1);
798
- rb_define_singleton_method(cXMLReader, "walker", ruby_xml_reader_new_walker, 1);
799
- rb_define_alias(CLASS_OF(cXMLReader), "document", "walker");
800
- rb_define_singleton_method(cXMLReader, "new", ruby_xml_reader_new_data, -1);
801
- rb_define_alias(CLASS_OF(cXMLReader), "string", "new");
802
-
803
- rb_define_method(cXMLReader, "close", ruby_xml_reader_close, 0);
804
-
805
- rb_define_method(cXMLReader, "move_to_attribute", ruby_xml_reader_move_to_attr, 1);
806
- rb_define_method(cXMLReader, "move_to_first_attribute", ruby_xml_reader_move_to_first_attr, 0);
807
- rb_define_method(cXMLReader, "move_to_next_attribute", ruby_xml_reader_move_to_next_attr, 0);
808
- rb_define_method(cXMLReader, "move_to_element", ruby_xml_reader_move_to_element, 0);
809
- rb_define_method(cXMLReader, "next", ruby_xml_reader_next, 0);
810
- rb_define_method(cXMLReader, "next_sibling", ruby_xml_reader_next_sibling, 0);
811
- rb_define_method(cXMLReader, "read", ruby_xml_reader_read, 0);
812
- rb_define_method(cXMLReader, "read_attribute_value", ruby_xml_reader_read_attr_value, 0);
813
- rb_define_method(cXMLReader, "read_inner_xml", ruby_xml_reader_read_inner_xml, 0);
814
- rb_define_method(cXMLReader, "read_outer_xml", ruby_xml_reader_read_outer_xml, 0);
815
- rb_define_method(cXMLReader, "read_state", ruby_xml_reader_read_state, 0);
816
- rb_define_method(cXMLReader, "read_string", ruby_xml_reader_read_string, 0);
817
-
818
- rb_define_method(cXMLReader, "set_error_handler", ruby_xml_reader_set_error_handler, 0);
819
- rb_define_method(cXMLReader, "reset_error_handler", ruby_xml_reader_reset_error_handler, 0);
820
-
821
- rb_define_method(cXMLReader, "relax_ng_validate", ruby_xml_reader_relax_ng_validate, 1);
822
- #if LIBXML_VERSION >= 20620
823
- rb_define_method(cXMLReader, "schema_validate", ruby_xml_reader_schema_validate, 1);
824
- #endif
825
-
826
- rb_define_method(cXMLReader, "node_type", ruby_xml_reader_node_type, 0);
827
- rb_define_method(cXMLReader, "normalization", ruby_xml_reader_normalization, 0);
828
- rb_define_method(cXMLReader, "attribute_count", ruby_xml_reader_attr_count, 0);
829
- rb_define_method(cXMLReader, "name", ruby_xml_reader_name, 0);
830
- rb_define_method(cXMLReader, "local_name", ruby_xml_reader_local_name, 0);
831
- rb_define_method(cXMLReader, "encoding", ruby_xml_reader_encoding, 0);
832
- rb_define_method(cXMLReader, "base_uri", ruby_xml_reader_base_uri, 0);
833
- rb_define_method(cXMLReader, "namespace_uri", ruby_xml_reader_namespace_uri, 0);
834
- rb_define_method(cXMLReader, "xml_lang", ruby_xml_reader_xml_lang, 0);
835
- rb_define_method(cXMLReader, "xml_version", ruby_xml_reader_xml_version, 0);
836
- rb_define_method(cXMLReader, "prefix", ruby_xml_reader_prefix, 0);
837
- rb_define_method(cXMLReader, "depth", ruby_xml_reader_depth, 0);
838
- rb_define_method(cXMLReader, "quote_char", ruby_xml_reader_quote_char, 0);
839
- rb_define_method(cXMLReader, "standalone", ruby_xml_reader_standalone, 0);
840
-
841
- rb_define_method(cXMLReader, "has_attributes?", ruby_xml_reader_has_attributes, 0);
842
- rb_define_method(cXMLReader, "[]", ruby_xml_reader_attribute, 1);
843
- rb_define_method(cXMLReader, "has_value?", ruby_xml_reader_has_value, 0);
844
- rb_define_method(cXMLReader, "value", ruby_xml_reader_value, 0);
845
-
846
- rb_define_method(cXMLReader, "lookup_namespace", ruby_xml_reader_lookup_namespace, 1);
847
- rb_define_method(cXMLReader, "expand", ruby_xml_reader_expand, 0);
848
-
849
- #if LIBXML_VERSION >= 20618
850
- rb_define_method(cXMLReader, "byte_consumed", ruby_xml_reader_byte_consumed, 0);
851
- #endif
852
- #if LIBXML_VERSION >= 20617
853
- rb_define_method(cXMLReader, "column_number", ruby_xml_reader_column_number, 0);
854
- rb_define_method(cXMLReader, "line_number", ruby_xml_reader_line_number, 0);
855
- #endif
856
- rb_define_method(cXMLReader, "default?", ruby_xml_reader_default, 0);
857
- rb_define_method(cXMLReader, "empty_element?", ruby_xml_reader_empty_element, 0);
858
- rb_define_method(cXMLReader, "namespace_declaration?", ruby_xml_reader_namespace_declaration, 0);
859
- rb_define_method(cXMLReader, "valid?", ruby_xml_reader_valid, 0);
860
-
861
- rb_define_const(cXMLReader, "LOADDTD", INT2FIX(XML_PARSER_LOADDTD));
862
- rb_define_const(cXMLReader, "DEFAULTATTRS", INT2FIX(XML_PARSER_DEFAULTATTRS));
863
- rb_define_const(cXMLReader, "VALIDATE", INT2FIX(XML_PARSER_VALIDATE));
864
- rb_define_const(cXMLReader, "SUBST_ENTITIES", INT2FIX(XML_PARSER_SUBST_ENTITIES));
865
-
866
- rb_define_const(cXMLReader, "SEVERITY_VALIDITY_WARNING", INT2FIX(XML_PARSER_SEVERITY_VALIDITY_WARNING));
867
- rb_define_const(cXMLReader, "SEVERITY_VALIDITY_ERROR", INT2FIX(XML_PARSER_SEVERITY_VALIDITY_ERROR));
868
- rb_define_const(cXMLReader, "SEVERITY_WARNING", INT2FIX(XML_PARSER_SEVERITY_WARNING));
869
- rb_define_const(cXMLReader, "SEVERITY_ERROR", INT2FIX(XML_PARSER_SEVERITY_ERROR));
870
-
871
- rb_define_const(cXMLReader, "TYPE_NONE", INT2FIX(XML_READER_TYPE_NONE));
872
- rb_define_const(cXMLReader, "TYPE_ELEMENT", INT2FIX(XML_READER_TYPE_ELEMENT));
873
- rb_define_const(cXMLReader, "TYPE_ATTRIBUTE", INT2FIX(XML_READER_TYPE_ATTRIBUTE));
874
- rb_define_const(cXMLReader, "TYPE_TEXT", INT2FIX(XML_READER_TYPE_TEXT));
875
- rb_define_const(cXMLReader, "TYPE_CDATA", INT2FIX(XML_READER_TYPE_CDATA));
876
- rb_define_const(cXMLReader, "TYPE_ENTITY_REFERENCE", INT2FIX(XML_READER_TYPE_ENTITY_REFERENCE));
877
- rb_define_const(cXMLReader, "TYPE_ENTITY", INT2FIX(XML_READER_TYPE_ENTITY));
878
- rb_define_const(cXMLReader, "TYPE_PROCESSING_INSTRUCTION", INT2FIX(XML_READER_TYPE_PROCESSING_INSTRUCTION));
879
- rb_define_const(cXMLReader, "TYPE_COMMENT", INT2FIX(XML_READER_TYPE_COMMENT));
880
- rb_define_const(cXMLReader, "TYPE_DOCUMENT", INT2FIX(XML_READER_TYPE_DOCUMENT));
881
- rb_define_const(cXMLReader, "TYPE_DOCUMENT_TYPE", INT2FIX(XML_READER_TYPE_DOCUMENT_TYPE));
882
- rb_define_const(cXMLReader, "TYPE_DOCUMENT_FRAGMENT", INT2FIX(XML_READER_TYPE_DOCUMENT_FRAGMENT));
883
- rb_define_const(cXMLReader, "TYPE_NOTATION", INT2FIX(XML_READER_TYPE_NOTATION));
884
- rb_define_const(cXMLReader, "TYPE_WHITESPACE", INT2FIX(XML_READER_TYPE_WHITESPACE));
885
- rb_define_const(cXMLReader, "TYPE_SIGNIFICANT_WHITESPACE", INT2FIX(XML_READER_TYPE_SIGNIFICANT_WHITESPACE));
886
- rb_define_const(cXMLReader, "TYPE_END_ELEMENT", INT2FIX(XML_READER_TYPE_END_ELEMENT));
887
- rb_define_const(cXMLReader, "TYPE_END_ENTITY", INT2FIX(XML_READER_TYPE_END_ENTITY));
888
- rb_define_const(cXMLReader, "TYPE_XML_DECLARATION", INT2FIX(XML_READER_TYPE_XML_DECLARATION));
889
-
890
- rb_define_const(cXMLReader, "MODE_INITIAL", INT2FIX(XML_TEXTREADER_MODE_INITIAL));
891
- rb_define_const(cXMLReader, "MODE_INTERACTIVE", INT2FIX(XML_TEXTREADER_MODE_INTERACTIVE));
892
- rb_define_const(cXMLReader, "MODE_ERROR", INT2FIX(XML_TEXTREADER_MODE_ERROR));
893
- rb_define_const(cXMLReader, "MODE_EOF", INT2FIX(XML_TEXTREADER_MODE_EOF));
894
- rb_define_const(cXMLReader, "MODE_CLOSED", INT2FIX(XML_TEXTREADER_MODE_CLOSED));
895
- rb_define_const(cXMLReader, "MODE_READING", INT2FIX(XML_TEXTREADER_MODE_READING));
896
- }
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
+ #define CSTR2RVAL(x) (x == NULL ? Qnil : rb_str_new2((const char *)x))
8
+ #define RVAL2CSTR(x) (StringValueCStr(x))
9
+
10
+ static inline VALUE
11
+ __rb_str_new_and_free(xmlChar *x)
12
+ {
13
+ if (x != NULL) {
14
+ VALUE v = rb_str_new2((const char *)x);
15
+ xmlFree(x);
16
+ return v;
17
+ }
18
+ return Qnil;
19
+ }
20
+
21
+ #define CSTR2RVAL2(x) (__rb_str_new_and_free(x))
22
+
23
+ VALUE cXMLReader;
24
+ static ID error_handler_block_ivar_id;
25
+
26
+ static VALUE
27
+ ruby_xml_reader_new(VALUE class, xmlTextReaderPtr reader)
28
+ {
29
+ return Data_Wrap_Struct(class, NULL, xmlFreeTextReader, reader);
30
+ }
31
+
32
+ static xmlTextReaderPtr
33
+ ruby_xml_text_reader_get(VALUE obj)
34
+ {
35
+ xmlTextReaderPtr ptr;
36
+ Data_Get_Struct(obj, xmlTextReader, ptr);
37
+ return ptr;
38
+ }
39
+
40
+ /*
41
+ * call-seq:
42
+ * XML::Reader.file(path, encoding=nil, options=0) -> reader
43
+ *
44
+ * Parse an XML file from the filesystem or the network. The parsing flags
45
+ * options are a combination of xmlParserOption.
46
+ */
47
+ static VALUE
48
+ ruby_xml_reader_new_file(int argc, VALUE *argv, VALUE self)
49
+ {
50
+ xmlTextReaderPtr reader;
51
+ VALUE path, encoding, options;
52
+
53
+ rb_scan_args(argc, argv, "12", &path, &encoding, &options);
54
+
55
+ reader = xmlReaderForFile(RVAL2CSTR(path),
56
+ NIL_P(encoding) ? NULL : RVAL2CSTR(encoding),
57
+ NIL_P(options) ? 0 : FIX2INT(options));
58
+ if (reader == NULL)
59
+ rb_raise(rb_eRuntimeError,
60
+ "cannot create text reader for given XML file at path '%s'",
61
+ RVAL2CSTR(path));
62
+
63
+ return ruby_xml_reader_new(self, reader);
64
+ }
65
+
66
+ /*
67
+ * call-seq:
68
+ * XML::Reader.walker(doc) -> reader
69
+ * XML::Reader.document(doc) -> reader
70
+ *
71
+ * Create an XML text reader for a preparsed document.
72
+ */
73
+ VALUE
74
+ ruby_xml_reader_new_walker(VALUE self, VALUE doc)
75
+ {
76
+ ruby_xml_document_t *rxd;
77
+ xmlTextReaderPtr reader;
78
+
79
+ Data_Get_Struct(doc, ruby_xml_document_t, rxd);
80
+
81
+ reader = xmlReaderWalker(rxd->doc);
82
+ if (reader == NULL)
83
+ rb_raise(rb_eRuntimeError, "cannot create text reader for given document");
84
+
85
+ return ruby_xml_reader_new(self, reader);
86
+ }
87
+
88
+ /*
89
+ * call-seq:
90
+ * XML::Reader.new(data, url=nil, encoding=nil, options=0) -> reader
91
+ * XML::Reader.string(data, url=nil, encoding=nil, options=0) -> reader
92
+ *
93
+ * Create an XML text reader for an XML in-memory document. The parsing flags
94
+ * options are a combination of xmlParserOption.
95
+ */
96
+ static VALUE
97
+ ruby_xml_reader_new_data(int argc, VALUE *argv, VALUE self)
98
+ {
99
+ xmlTextReaderPtr reader;
100
+ VALUE data, url, encoding, options;
101
+ char *c_data;
102
+
103
+ rb_scan_args(argc, argv, "13", &data, &url, &encoding, &options);
104
+
105
+ c_data = RVAL2CSTR(data);
106
+ reader = xmlReaderForMemory(c_data,
107
+ strlen(c_data),
108
+ NIL_P(url) ? NULL : RVAL2CSTR(url),
109
+ NIL_P(encoding) ? NULL : RVAL2CSTR(encoding),
110
+ NIL_P(options) ? 0 : FIX2INT(options));
111
+ if (reader == NULL)
112
+ rb_raise(rb_eRuntimeError, "cannot create text reader for given data");
113
+
114
+ return ruby_xml_reader_new(self, reader);
115
+ }
116
+
117
+ /*
118
+ * call-seq:
119
+ * parser.close -> code
120
+ *
121
+ * This method releases any resources allocated by the current instance
122
+ * changes the state to Closed and close any underlying input.
123
+ */
124
+ static VALUE
125
+ ruby_xml_reader_close(VALUE self)
126
+ {
127
+ return INT2FIX(xmlTextReaderClose(ruby_xml_text_reader_get(self)));
128
+ }
129
+
130
+ /*
131
+ * call-seq:
132
+ * parser.move_to_attribute(val) -> code
133
+ *
134
+ * Move the position of the current instance to the attribute with the
135
+ * specified index (if +val+ is an integer) or name (if +val+ is a string)
136
+ * relative to the containing element.
137
+ */
138
+ static VALUE
139
+ ruby_xml_reader_move_to_attr(VALUE self, VALUE val)
140
+ {
141
+ xmlTextReaderPtr reader;
142
+ int ret;
143
+
144
+ reader = ruby_xml_text_reader_get(self);
145
+
146
+ if (TYPE(val) == T_FIXNUM) {
147
+ ret = xmlTextReaderMoveToAttributeNo(reader, FIX2INT(val));
148
+ }
149
+ else {
150
+ ret = xmlTextReaderMoveToAttribute(reader, (const xmlChar *)RVAL2CSTR(val));
151
+ }
152
+
153
+ return INT2FIX(ret);
154
+ }
155
+
156
+ /*
157
+ * call-seq:
158
+ * reader.move_to_first_attribute -> code
159
+ *
160
+ * Move the position of the current instance to the first attribute associated
161
+ * with the current node.
162
+ */
163
+ static VALUE
164
+ ruby_xml_reader_move_to_first_attr(VALUE self)
165
+ {
166
+ return INT2FIX(xmlTextReaderMoveToFirstAttribute(ruby_xml_text_reader_get(self)));
167
+ }
168
+
169
+ /*
170
+ * call-seq:
171
+ * reader.move_to_next_attribute -> code
172
+ *
173
+ * Move the position of the current instance to the next attribute associated
174
+ * with the current node.
175
+ */
176
+ static VALUE
177
+ ruby_xml_reader_move_to_next_attr(VALUE self)
178
+ {
179
+ return INT2FIX(xmlTextReaderMoveToNextAttribute(ruby_xml_text_reader_get(self)));
180
+ }
181
+
182
+ /*
183
+ * call-seq:
184
+ * reader.move_to_element -> code
185
+ *
186
+ * Move the position of the current instance to the node that contains the
187
+ * current attribute node.
188
+ */
189
+ static VALUE
190
+ ruby_xml_reader_move_to_element(VALUE self)
191
+ {
192
+ return INT2FIX(xmlTextReaderMoveToElement(ruby_xml_text_reader_get(self)));
193
+ }
194
+
195
+ /*
196
+ * call-seq:
197
+ * reader.next -> code
198
+ *
199
+ * Skip to the node following the current one in document order while avoiding
200
+ * the subtree if any.
201
+ */
202
+ static VALUE
203
+ ruby_xml_reader_next(VALUE self)
204
+ {
205
+ return INT2FIX(xmlTextReaderNext(ruby_xml_text_reader_get(self)));
206
+ }
207
+
208
+ /*
209
+ * call-seq:
210
+ * reader.next_sibling -> code
211
+ *
212
+ * Skip to the node following the current one in document order while avoiding
213
+ * the subtree if any. Currently implemented only for Readers built on a
214
+ * document.
215
+ */
216
+ static VALUE
217
+ ruby_xml_reader_next_sibling(VALUE self)
218
+ {
219
+ return INT2FIX(xmlTextReaderNextSibling(ruby_xml_text_reader_get(self)));
220
+ }
221
+
222
+ /*
223
+ * call-seq:
224
+ * reader.node_type -> type
225
+ *
226
+ * Get the node type of the current node. Reference:
227
+ * http://dotgnu.org/pnetlib-doc/System/Xml/XmlNodeType.html
228
+ */
229
+ static VALUE
230
+ ruby_xml_reader_node_type(VALUE self)
231
+ {
232
+ return INT2FIX(xmlTextReaderNodeType(ruby_xml_text_reader_get(self)));
233
+ }
234
+
235
+ /*
236
+ * call-seq:
237
+ * reader.normalization -> value
238
+ *
239
+ * The value indicating whether to normalize white space and attribute values.
240
+ * Since attribute value and end of line normalizations are a MUST in the XML
241
+ * specification only the value true is accepted. The broken bahaviour of
242
+ * accepting out of range character entities like � is of course not
243
+ * supported either.
244
+ *
245
+ * Return 1 or -1 in case of error.
246
+ */
247
+ static VALUE
248
+ ruby_xml_reader_normalization(VALUE self)
249
+ {
250
+ return INT2FIX(xmlTextReaderNormalization(ruby_xml_text_reader_get(self)));
251
+ }
252
+
253
+ /*
254
+ * call-seq:
255
+ * reader.read -> code
256
+ *
257
+ * Move the position of the current instance to the next node in the stream,
258
+ * exposing its properties.
259
+ *
260
+ * Return 1 if the node was read successfully, 0 if there is no more nodes to
261
+ * read, or -1 in case of error.
262
+ */
263
+ static VALUE
264
+ ruby_xml_reader_read(VALUE self)
265
+ {
266
+ return INT2FIX(xmlTextReaderRead(ruby_xml_text_reader_get(self)));
267
+ }
268
+
269
+ /*
270
+ * call-seq:
271
+ * reader.read_attribute_value -> code
272
+ *
273
+ * Parse an attribute value into one or more Text and EntityReference nodes.
274
+ *
275
+ * Return 1 in case of success, 0 if the reader was not positionned on an
276
+ * attribute node or all the attribute values have been read, or -1 in case of
277
+ * error.
278
+ */
279
+ static VALUE
280
+ ruby_xml_reader_read_attr_value(VALUE self)
281
+ {
282
+ return INT2FIX(xmlTextReaderReadAttributeValue(ruby_xml_text_reader_get(self)));
283
+ }
284
+
285
+ /*
286
+ * call-seq:
287
+ * reader.read_inner_xml -> data
288
+ *
289
+ * Read the contents of the current node, including child nodes and markup.
290
+ *
291
+ * Return a string containing the XML content, or nil if the current node is
292
+ * neither an element nor attribute, or has no child nodes.
293
+ */
294
+ static VALUE
295
+ ruby_xml_reader_read_inner_xml(VALUE self)
296
+ {
297
+ return CSTR2RVAL2(xmlTextReaderReadInnerXml(ruby_xml_text_reader_get(self)));
298
+ }
299
+
300
+ /*
301
+ * call-seq:
302
+ * reader.read_outer_xml -> data
303
+ *
304
+ * Read the contents of the current node, including child nodes and markup.
305
+ *
306
+ * Return a string containing the XML content, or nil if the current node is
307
+ * neither an element nor attribute, or has no child nodes.
308
+ */
309
+ static VALUE
310
+ ruby_xml_reader_read_outer_xml(VALUE self)
311
+ {
312
+ return CSTR2RVAL2(xmlTextReaderReadOuterXml(ruby_xml_text_reader_get(self)));
313
+ }
314
+
315
+ /*
316
+ * call-seq:
317
+ * reader.read_state -> state
318
+ *
319
+ * Get the read state of the reader.
320
+ */
321
+ static VALUE
322
+ ruby_xml_reader_read_state(VALUE self)
323
+ {
324
+ return INT2FIX(xmlTextReaderReadState(ruby_xml_text_reader_get(self)));
325
+ }
326
+
327
+ /*
328
+ * call-seq:
329
+ * reader.read_string -> string
330
+ *
331
+ * Read the contents of an element or a text node as a string.
332
+ *
333
+ * Return a string containing the contents of the Element or Text node, or nil
334
+ * if the reader is positioned on any other type of node.
335
+ */
336
+ static VALUE
337
+ ruby_xml_reader_read_string(VALUE self)
338
+ {
339
+ return CSTR2RVAL2(xmlTextReaderReadString(ruby_xml_text_reader_get(self)));
340
+ }
341
+
342
+ static void
343
+ __xml_reader_error_cb(void *arg,
344
+ const char *msg, xmlParserSeverities severity,
345
+ xmlTextReaderLocatorPtr locator)
346
+ {
347
+ VALUE reader;
348
+ VALUE block;
349
+
350
+ reader = (VALUE)arg;
351
+ block = rb_ivar_get(reader, error_handler_block_ivar_id);
352
+ if (NIL_P(block))
353
+ rb_bug("no ivar block");
354
+
355
+ rb_funcall(block,
356
+ rb_intern("call"),
357
+ 5,
358
+ reader,
359
+ CSTR2RVAL(msg),
360
+ INT2FIX(severity),
361
+ CSTR2RVAL2(xmlTextReaderLocatorBaseURI(locator)),
362
+ INT2FIX(xmlTextReaderLocatorLineNumber(locator)));
363
+ }
364
+
365
+ /*
366
+ * call-seq:
367
+ * reader.set_error_handler { ... }
368
+ *
369
+ * Register a callback block that will be called on error and warnings. The
370
+ * block will be called with 5 parameters: the reader, the error message, the
371
+ * severity, the base URI and the line number.
372
+ */
373
+ static VALUE
374
+ ruby_xml_reader_set_error_handler(VALUE self)
375
+ {
376
+ VALUE block;
377
+ xmlTextReaderPtr reader;
378
+
379
+ if (rb_block_given_p() == Qfalse)
380
+ rb_raise(rb_eRuntimeError, "No block given");
381
+
382
+ block = rb_block_proc();
383
+
384
+ /* Embed the block within the parser object to avoid it to be collected.
385
+ * Previous handler if exits is overwritten.
386
+ */
387
+ rb_ivar_set(self, error_handler_block_ivar_id, block);
388
+ reader = ruby_xml_text_reader_get(self);
389
+ xmlTextReaderSetErrorHandler(reader, __xml_reader_error_cb, (void *)self);
390
+
391
+ return self;
392
+ }
393
+
394
+ /*
395
+ * call-seq:
396
+ * reader.reset_error_handler
397
+ *
398
+ * Restore the default error and warning handlers.
399
+ */
400
+ static VALUE
401
+ ruby_xml_reader_reset_error_handler(VALUE self)
402
+ {
403
+ xmlTextReaderSetErrorHandler(ruby_xml_text_reader_get(self), NULL, NULL);
404
+ return self;
405
+ }
406
+
407
+ /*
408
+ * call-seq:
409
+ * reader.relax_ng_validate(rng) -> code
410
+ *
411
+ * Use RelaxNG to validate the document as it is processed. Activation is only
412
+ * possible before the first read. If +rng+ is nil, the RelaxNG validation is
413
+ * desactivated.
414
+ *
415
+ * Return 0 in case the RelaxNG validation could be (des)activated and -1 in
416
+ * case of error.
417
+ */
418
+ static VALUE
419
+ ruby_xml_reader_relax_ng_validate(VALUE self, VALUE rng)
420
+ {
421
+ return INT2FIX(xmlTextReaderRelaxNGValidate(ruby_xml_text_reader_get(self), NIL_P(rng) ? NULL : RVAL2CSTR(rng)));
422
+ }
423
+
424
+ #if LIBXML_VERSION >= 20620
425
+ /*
426
+ * call-seq:
427
+ * reader.schema_validate(schema) -> code
428
+ *
429
+ * Use W3C XSD schema to validate the document as it is processed. Activation
430
+ * is only possible before the first read. If +schema+ is nil, then XML Schema
431
+ * validation is desactivated.
432
+ *
433
+ * Return 0 in case the schemas validation could be (de)activated and -1 in
434
+ * case of error.
435
+ */
436
+ static VALUE
437
+ ruby_xml_reader_schema_validate(VALUE self, VALUE xsd)
438
+ {
439
+ return INT2FIX(xmlTextReaderSchemaValidate(ruby_xml_text_reader_get(self), NIL_P(xsd) ? NULL : RVAL2CSTR(xsd)));
440
+ }
441
+ #endif
442
+
443
+ /*
444
+ * call-seq:
445
+ * reader.name -> name
446
+ *
447
+ * Return the qualified name of the node.
448
+ */
449
+ static VALUE
450
+ ruby_xml_reader_name(VALUE self)
451
+ {
452
+ return CSTR2RVAL(xmlTextReaderConstName(ruby_xml_text_reader_get(self)));
453
+ }
454
+
455
+ /*
456
+ * call-seq:
457
+ * reader.local_name -> name
458
+ *
459
+ * Return the local name of the node.
460
+ */
461
+ static VALUE
462
+ ruby_xml_reader_local_name(VALUE self)
463
+ {
464
+ return CSTR2RVAL(xmlTextReaderConstLocalName(ruby_xml_text_reader_get(self)));
465
+ }
466
+
467
+ /*
468
+ * call-seq:
469
+ * reader.attribute_count -> count
470
+ *
471
+ * Provide the number of attributes of the current node.
472
+ */
473
+ static VALUE
474
+ ruby_xml_reader_attr_count(VALUE self)
475
+ {
476
+ return INT2FIX(xmlTextReaderAttributeCount(ruby_xml_text_reader_get(self)));
477
+ }
478
+
479
+ /*
480
+ * call-seq:
481
+ * reader.encoding -> encoding
482
+ *
483
+ * Determine the encoding of the document being read.
484
+ */
485
+ static VALUE
486
+ ruby_xml_reader_encoding(VALUE self)
487
+ {
488
+ return CSTR2RVAL(xmlTextReaderConstEncoding(ruby_xml_text_reader_get(self)));
489
+ }
490
+
491
+ /*
492
+ * call-seq:
493
+ * reader.base_uri -> URI
494
+ *
495
+ * Determine the base URI of the node.
496
+ */
497
+ static VALUE
498
+ ruby_xml_reader_base_uri(VALUE self)
499
+ {
500
+ return CSTR2RVAL(xmlTextReaderConstBaseUri(ruby_xml_text_reader_get(self)));
501
+ }
502
+
503
+ /*
504
+ * call-seq:
505
+ * reader.namespace_uri -> URI
506
+ *
507
+ * Determine the namespace URI of the node.
508
+ */
509
+ static VALUE
510
+ ruby_xml_reader_namespace_uri(VALUE self)
511
+ {
512
+ return CSTR2RVAL(xmlTextReaderConstNamespaceUri(ruby_xml_text_reader_get(self)));
513
+ }
514
+
515
+ /*
516
+ * call-seq:
517
+ * reader.value -> text
518
+ *
519
+ * Provide the text value of the node if present.
520
+ */
521
+ static VALUE
522
+ ruby_xml_reader_value(VALUE self)
523
+ {
524
+ return CSTR2RVAL(xmlTextReaderConstValue(ruby_xml_text_reader_get(self)));
525
+ }
526
+
527
+ /*
528
+ * call-seq:
529
+ * reader.prefix -> prefix
530
+ *
531
+ * Get a shorthand reference to the namespace associated with the node.
532
+ */
533
+ static VALUE
534
+ ruby_xml_reader_prefix(VALUE self)
535
+ {
536
+ return CSTR2RVAL(xmlTextReaderConstPrefix(ruby_xml_text_reader_get(self)));
537
+ }
538
+
539
+ /*
540
+ * call-seq:
541
+ * reader.depth -> depth
542
+ *
543
+ * Get the depth of the node in the tree.
544
+ */
545
+ static VALUE
546
+ ruby_xml_reader_depth(VALUE self)
547
+ {
548
+ return INT2FIX(xmlTextReaderDepth(ruby_xml_text_reader_get(self)));
549
+ }
550
+
551
+ /*
552
+ * call-seq:
553
+ * reader.quote_char -> char
554
+ *
555
+ * Get the quotation mark character used to enclose the value of an attribute,
556
+ * as an integer value (and -1 in case of error).
557
+ */
558
+ static VALUE
559
+ ruby_xml_reader_quote_char(VALUE self)
560
+ {
561
+ return INT2FIX(xmlTextReaderQuoteChar(ruby_xml_text_reader_get(self)));
562
+ }
563
+
564
+ /*
565
+ * call-seq:
566
+ * reader.standalone -> code
567
+ *
568
+ * Determine the standalone status of the document being read.
569
+ *
570
+ * Return 1 if the document was declared to be standalone, 0 if it was
571
+ * declared to be not standalone, or -1 if the document did not specify its
572
+ * standalone status or in case of error.
573
+ */
574
+ static VALUE
575
+ ruby_xml_reader_standalone(VALUE self)
576
+ {
577
+ return INT2FIX(xmlTextReaderStandalone(ruby_xml_text_reader_get(self)));
578
+ }
579
+
580
+ /*
581
+ * call-seq:
582
+ * reader.xml_lang -> value
583
+ *
584
+ * Get the xml:lang scope within which the node resides.
585
+ */
586
+ static VALUE
587
+ ruby_xml_reader_xml_lang(VALUE self)
588
+ {
589
+ return CSTR2RVAL(xmlTextReaderConstXmlLang(ruby_xml_text_reader_get(self)));
590
+ }
591
+
592
+ /*
593
+ * call-seq:
594
+ * reader.xml_version -> version
595
+ *
596
+ * Determine the XML version of the document being read.
597
+ */
598
+ static VALUE
599
+ ruby_xml_reader_xml_version(VALUE self)
600
+ {
601
+ return CSTR2RVAL(xmlTextReaderConstXmlVersion(ruby_xml_text_reader_get(self)));
602
+ }
603
+
604
+ /*
605
+ * call-seq:
606
+ * reader.has_attributes? -> bool
607
+ *
608
+ * Get whether the node has attributes.
609
+ */
610
+ static VALUE
611
+ ruby_xml_reader_has_attributes(VALUE self)
612
+ {
613
+ return xmlTextReaderHasAttributes(ruby_xml_text_reader_get(self)) ? Qtrue : Qfalse;
614
+ }
615
+
616
+ /*
617
+ * call-seq:
618
+ * reader.has_value? -> bool
619
+ *
620
+ * Get whether the node can have a text value.
621
+ */
622
+ static VALUE
623
+ ruby_xml_reader_has_value(VALUE self)
624
+ {
625
+ return xmlTextReaderHasValue(ruby_xml_text_reader_get(self)) ? Qtrue : Qfalse;
626
+ }
627
+
628
+ /*
629
+ * call-seq:
630
+ * reader[key] -> value
631
+ *
632
+ * Provide the value of the attribute with the specified index (if +key+ is an
633
+ * integer) or with the specified name (if +key+ is a string) relative to the
634
+ * containing element, as a string.
635
+ */
636
+ static VALUE
637
+ ruby_xml_reader_attribute(VALUE self, VALUE key)
638
+ {
639
+ xmlTextReaderPtr reader;
640
+ xmlChar *attr;
641
+
642
+ reader = ruby_xml_text_reader_get(self);
643
+
644
+ if (TYPE(key) == T_FIXNUM) {
645
+ attr = xmlTextReaderGetAttributeNo(reader, FIX2INT(key));
646
+ }
647
+ else {
648
+ attr = xmlTextReaderGetAttribute(reader, (const xmlChar *)RVAL2CSTR(key));
649
+ }
650
+ return CSTR2RVAL2(attr);
651
+ }
652
+
653
+ /*
654
+ * call-seq:
655
+ * reader.lookup_namespace(prefix) -> value
656
+ *
657
+ * Resolve a namespace prefix in the scope of the current element.
658
+ * To return the default namespace, specify nil as +prefix+.
659
+ */
660
+ static VALUE
661
+ ruby_xml_reader_lookup_namespace(VALUE self, VALUE prefix)
662
+ {
663
+ return CSTR2RVAL2(xmlTextReaderLookupNamespace(ruby_xml_text_reader_get(self), (const xmlChar *)RVAL2CSTR(prefix)));
664
+ }
665
+
666
+ /*
667
+ * call-seq:
668
+ * reader.expand -> node
669
+ *
670
+ * Read the contents of the current node and the full subtree. It then makes
671
+ * the subtree available until the next read call.
672
+ *
673
+ * Return an XML::Node object, or nil in case of error.
674
+ */
675
+ static VALUE
676
+ ruby_xml_reader_expand(VALUE self)
677
+ {
678
+ xmlNodePtr node;
679
+ xmlDocPtr doc;
680
+ xmlTextReaderPtr reader = ruby_xml_text_reader_get(self);
681
+ node = xmlTextReaderExpand(reader);
682
+
683
+ if (!node)
684
+ return Qnil;
685
+
686
+ /* Okay this is tricky. By accessing the returned node, we
687
+ take ownership of the reader's document. Thus we need to
688
+ tell the reader to not free it. Otherwise it will be
689
+ freed twice - once when the Ruby document wrapper goes
690
+ out of scope and once when the reader goes out of scope. */
691
+
692
+ xmlTextReaderPreserve(reader);
693
+ doc = xmlTextReaderCurrentDoc(reader);
694
+ ruby_xml_document_wrap(doc);
695
+
696
+ return ruby_xml_node2_wrap(cXMLNode, node);
697
+ }
698
+
699
+ #if LIBXML_VERSION >= 20618
700
+ /*
701
+ * call-seq:
702
+ * reader.byte_consumed -> value
703
+ *
704
+ * This method provides the current index of the parser used by the reader,
705
+ * relative to the start of the current entity.
706
+ */
707
+ static VALUE
708
+ ruby_xml_reader_byte_consumed(VALUE self)
709
+ {
710
+ return INT2NUM(xmlTextReaderByteConsumed(ruby_xml_text_reader_get(self)));
711
+ }
712
+ #endif
713
+
714
+ #if LIBXML_VERSION >= 20617
715
+ /*
716
+ * call-seq:
717
+ * reader.column_number -> number
718
+ *
719
+ * Provide the column number of the current parsing point.
720
+ */
721
+ static VALUE
722
+ ruby_xml_reader_column_number(VALUE self)
723
+ {
724
+ return INT2NUM(xmlTextReaderGetParserColumnNumber(ruby_xml_text_reader_get(self)));
725
+ }
726
+
727
+ /*
728
+ * call-seq:
729
+ * reader.line_number -> number
730
+ *
731
+ * Provide the line number of the current parsing point.
732
+ */
733
+ static VALUE
734
+ ruby_xml_reader_line_number(VALUE self)
735
+ {
736
+ return INT2NUM(xmlTextReaderGetParserLineNumber(ruby_xml_text_reader_get(self)));
737
+ }
738
+ #endif
739
+
740
+ /*
741
+ * call-seq:
742
+ * reader.default? -> bool
743
+ *
744
+ * Return whether an Attribute node was generated from the default value
745
+ * defined in the DTD or schema.
746
+ */
747
+ static VALUE
748
+ ruby_xml_reader_default(VALUE self)
749
+ {
750
+ return xmlTextReaderIsDefault(ruby_xml_text_reader_get(self)) ? Qtrue : Qfalse;
751
+ }
752
+
753
+ /*
754
+ * call-seq:
755
+ * reader.namespace_declaration? -> bool
756
+ *
757
+ * Determine whether the current node is a namespace declaration rather than a
758
+ * regular attribute.
759
+ */
760
+ static VALUE
761
+ ruby_xml_reader_namespace_declaration(VALUE self)
762
+ {
763
+ return xmlTextReaderIsNamespaceDecl(ruby_xml_text_reader_get(self)) ? Qtrue : Qfalse;
764
+ }
765
+
766
+ /*
767
+ * call-seq:
768
+ * reader.empty_element? -> bool
769
+ *
770
+ * Check if the current node is empty.
771
+ */
772
+ static VALUE
773
+ ruby_xml_reader_empty_element(VALUE self)
774
+ {
775
+ return xmlTextReaderIsEmptyElement(ruby_xml_text_reader_get(self)) ? Qtrue : Qfalse;
776
+ }
777
+
778
+ /*
779
+ * call-seq:
780
+ * reader.valid? -> bool
781
+ *
782
+ * Retrieve the validity status from the parser context.
783
+ */
784
+ static VALUE
785
+ ruby_xml_reader_valid(VALUE self)
786
+ {
787
+ return xmlTextReaderIsValid(ruby_xml_text_reader_get(self)) ? Qtrue : Qfalse;
788
+ }
789
+
790
+ /* Rdoc needs to know. */
791
+ #ifdef RDOC_NEVER_DEFINED
792
+ mXML = rb_define_module("XML");
793
+ #endif
794
+
795
+ void
796
+ ruby_init_xml_reader(void)
797
+ {
798
+ cXMLReader = rb_define_class_under(mXML, "Reader", rb_cObject);
799
+ error_handler_block_ivar_id = rb_intern("@__error_handler_callback__");
800
+
801
+ rb_define_singleton_method(cXMLReader, "file", ruby_xml_reader_new_file, -1);
802
+ rb_define_singleton_method(cXMLReader, "walker", ruby_xml_reader_new_walker, 1);
803
+ rb_define_alias(CLASS_OF(cXMLReader), "document", "walker");
804
+ rb_define_singleton_method(cXMLReader, "new", ruby_xml_reader_new_data, -1);
805
+ rb_define_alias(CLASS_OF(cXMLReader), "string", "new");
806
+
807
+ rb_define_method(cXMLReader, "close", ruby_xml_reader_close, 0);
808
+
809
+ rb_define_method(cXMLReader, "move_to_attribute", ruby_xml_reader_move_to_attr, 1);
810
+ rb_define_method(cXMLReader, "move_to_first_attribute", ruby_xml_reader_move_to_first_attr, 0);
811
+ rb_define_method(cXMLReader, "move_to_next_attribute", ruby_xml_reader_move_to_next_attr, 0);
812
+ rb_define_method(cXMLReader, "move_to_element", ruby_xml_reader_move_to_element, 0);
813
+ rb_define_method(cXMLReader, "next", ruby_xml_reader_next, 0);
814
+ rb_define_method(cXMLReader, "next_sibling", ruby_xml_reader_next_sibling, 0);
815
+ rb_define_method(cXMLReader, "read", ruby_xml_reader_read, 0);
816
+ rb_define_method(cXMLReader, "read_attribute_value", ruby_xml_reader_read_attr_value, 0);
817
+ rb_define_method(cXMLReader, "read_inner_xml", ruby_xml_reader_read_inner_xml, 0);
818
+ rb_define_method(cXMLReader, "read_outer_xml", ruby_xml_reader_read_outer_xml, 0);
819
+ rb_define_method(cXMLReader, "read_state", ruby_xml_reader_read_state, 0);
820
+ rb_define_method(cXMLReader, "read_string", ruby_xml_reader_read_string, 0);
821
+
822
+ rb_define_method(cXMLReader, "set_error_handler", ruby_xml_reader_set_error_handler, 0);
823
+ rb_define_method(cXMLReader, "reset_error_handler", ruby_xml_reader_reset_error_handler, 0);
824
+
825
+ rb_define_method(cXMLReader, "relax_ng_validate", ruby_xml_reader_relax_ng_validate, 1);
826
+ #if LIBXML_VERSION >= 20620
827
+ rb_define_method(cXMLReader, "schema_validate", ruby_xml_reader_schema_validate, 1);
828
+ #endif
829
+
830
+ rb_define_method(cXMLReader, "node_type", ruby_xml_reader_node_type, 0);
831
+ rb_define_method(cXMLReader, "normalization", ruby_xml_reader_normalization, 0);
832
+ rb_define_method(cXMLReader, "attribute_count", ruby_xml_reader_attr_count, 0);
833
+ rb_define_method(cXMLReader, "name", ruby_xml_reader_name, 0);
834
+ rb_define_method(cXMLReader, "local_name", ruby_xml_reader_local_name, 0);
835
+ rb_define_method(cXMLReader, "encoding", ruby_xml_reader_encoding, 0);
836
+ rb_define_method(cXMLReader, "base_uri", ruby_xml_reader_base_uri, 0);
837
+ rb_define_method(cXMLReader, "namespace_uri", ruby_xml_reader_namespace_uri, 0);
838
+ rb_define_method(cXMLReader, "xml_lang", ruby_xml_reader_xml_lang, 0);
839
+ rb_define_method(cXMLReader, "xml_version", ruby_xml_reader_xml_version, 0);
840
+ rb_define_method(cXMLReader, "prefix", ruby_xml_reader_prefix, 0);
841
+ rb_define_method(cXMLReader, "depth", ruby_xml_reader_depth, 0);
842
+ rb_define_method(cXMLReader, "quote_char", ruby_xml_reader_quote_char, 0);
843
+ rb_define_method(cXMLReader, "standalone", ruby_xml_reader_standalone, 0);
844
+
845
+ rb_define_method(cXMLReader, "has_attributes?", ruby_xml_reader_has_attributes, 0);
846
+ rb_define_method(cXMLReader, "[]", ruby_xml_reader_attribute, 1);
847
+ rb_define_method(cXMLReader, "has_value?", ruby_xml_reader_has_value, 0);
848
+ rb_define_method(cXMLReader, "value", ruby_xml_reader_value, 0);
849
+
850
+ rb_define_method(cXMLReader, "lookup_namespace", ruby_xml_reader_lookup_namespace, 1);
851
+ rb_define_method(cXMLReader, "expand", ruby_xml_reader_expand, 0);
852
+
853
+ #if LIBXML_VERSION >= 20618
854
+ rb_define_method(cXMLReader, "byte_consumed", ruby_xml_reader_byte_consumed, 0);
855
+ #endif
856
+ #if LIBXML_VERSION >= 20617
857
+ rb_define_method(cXMLReader, "column_number", ruby_xml_reader_column_number, 0);
858
+ rb_define_method(cXMLReader, "line_number", ruby_xml_reader_line_number, 0);
859
+ #endif
860
+ rb_define_method(cXMLReader, "default?", ruby_xml_reader_default, 0);
861
+ rb_define_method(cXMLReader, "empty_element?", ruby_xml_reader_empty_element, 0);
862
+ rb_define_method(cXMLReader, "namespace_declaration?", ruby_xml_reader_namespace_declaration, 0);
863
+ rb_define_method(cXMLReader, "valid?", ruby_xml_reader_valid, 0);
864
+
865
+ rb_define_const(cXMLReader, "LOADDTD", INT2FIX(XML_PARSER_LOADDTD));
866
+ rb_define_const(cXMLReader, "DEFAULTATTRS", INT2FIX(XML_PARSER_DEFAULTATTRS));
867
+ rb_define_const(cXMLReader, "VALIDATE", INT2FIX(XML_PARSER_VALIDATE));
868
+ rb_define_const(cXMLReader, "SUBST_ENTITIES", INT2FIX(XML_PARSER_SUBST_ENTITIES));
869
+
870
+ rb_define_const(cXMLReader, "SEVERITY_VALIDITY_WARNING", INT2FIX(XML_PARSER_SEVERITY_VALIDITY_WARNING));
871
+ rb_define_const(cXMLReader, "SEVERITY_VALIDITY_ERROR", INT2FIX(XML_PARSER_SEVERITY_VALIDITY_ERROR));
872
+ rb_define_const(cXMLReader, "SEVERITY_WARNING", INT2FIX(XML_PARSER_SEVERITY_WARNING));
873
+ rb_define_const(cXMLReader, "SEVERITY_ERROR", INT2FIX(XML_PARSER_SEVERITY_ERROR));
874
+
875
+ rb_define_const(cXMLReader, "TYPE_NONE", INT2FIX(XML_READER_TYPE_NONE));
876
+ rb_define_const(cXMLReader, "TYPE_ELEMENT", INT2FIX(XML_READER_TYPE_ELEMENT));
877
+ rb_define_const(cXMLReader, "TYPE_ATTRIBUTE", INT2FIX(XML_READER_TYPE_ATTRIBUTE));
878
+ rb_define_const(cXMLReader, "TYPE_TEXT", INT2FIX(XML_READER_TYPE_TEXT));
879
+ rb_define_const(cXMLReader, "TYPE_CDATA", INT2FIX(XML_READER_TYPE_CDATA));
880
+ rb_define_const(cXMLReader, "TYPE_ENTITY_REFERENCE", INT2FIX(XML_READER_TYPE_ENTITY_REFERENCE));
881
+ rb_define_const(cXMLReader, "TYPE_ENTITY", INT2FIX(XML_READER_TYPE_ENTITY));
882
+ rb_define_const(cXMLReader, "TYPE_PROCESSING_INSTRUCTION", INT2FIX(XML_READER_TYPE_PROCESSING_INSTRUCTION));
883
+ rb_define_const(cXMLReader, "TYPE_COMMENT", INT2FIX(XML_READER_TYPE_COMMENT));
884
+ rb_define_const(cXMLReader, "TYPE_DOCUMENT", INT2FIX(XML_READER_TYPE_DOCUMENT));
885
+ rb_define_const(cXMLReader, "TYPE_DOCUMENT_TYPE", INT2FIX(XML_READER_TYPE_DOCUMENT_TYPE));
886
+ rb_define_const(cXMLReader, "TYPE_DOCUMENT_FRAGMENT", INT2FIX(XML_READER_TYPE_DOCUMENT_FRAGMENT));
887
+ rb_define_const(cXMLReader, "TYPE_NOTATION", INT2FIX(XML_READER_TYPE_NOTATION));
888
+ rb_define_const(cXMLReader, "TYPE_WHITESPACE", INT2FIX(XML_READER_TYPE_WHITESPACE));
889
+ rb_define_const(cXMLReader, "TYPE_SIGNIFICANT_WHITESPACE", INT2FIX(XML_READER_TYPE_SIGNIFICANT_WHITESPACE));
890
+ rb_define_const(cXMLReader, "TYPE_END_ELEMENT", INT2FIX(XML_READER_TYPE_END_ELEMENT));
891
+ rb_define_const(cXMLReader, "TYPE_END_ENTITY", INT2FIX(XML_READER_TYPE_END_ENTITY));
892
+ rb_define_const(cXMLReader, "TYPE_XML_DECLARATION", INT2FIX(XML_READER_TYPE_XML_DECLARATION));
893
+
894
+ rb_define_const(cXMLReader, "MODE_INITIAL", INT2FIX(XML_TEXTREADER_MODE_INITIAL));
895
+ rb_define_const(cXMLReader, "MODE_INTERACTIVE", INT2FIX(XML_TEXTREADER_MODE_INTERACTIVE));
896
+ rb_define_const(cXMLReader, "MODE_ERROR", INT2FIX(XML_TEXTREADER_MODE_ERROR));
897
+ rb_define_const(cXMLReader, "MODE_EOF", INT2FIX(XML_TEXTREADER_MODE_EOF));
898
+ rb_define_const(cXMLReader, "MODE_CLOSED", INT2FIX(XML_TEXTREADER_MODE_CLOSED));
899
+ rb_define_const(cXMLReader, "MODE_READING", INT2FIX(XML_TEXTREADER_MODE_READING));
900
+ }