libxml-ruby 0.9.5-x86-mswin32-60 → 0.9.6-x86-mswin32-60

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