libxml-ruby 0.8.1 → 0.8.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (161) hide show
  1. data/CHANGES +21 -0
  2. data/RAKEFILE +213 -0
  3. data/README +32 -11
  4. data/doc/rdoc/classes/LibXML.html +4 -0
  5. data/doc/rdoc/classes/LibXML/XML.html +7 -0
  6. data/doc/rdoc/classes/LibXML/XML/Attr.html +187 -177
  7. data/doc/rdoc/classes/LibXML/XML/Attributes.html +62 -61
  8. data/doc/rdoc/classes/LibXML/XML/Document.html +318 -254
  9. data/doc/rdoc/classes/LibXML/XML/Dtd.html +62 -8
  10. data/doc/rdoc/classes/LibXML/XML/Error.html +6 -0
  11. data/doc/rdoc/classes/LibXML/XML/HTMLParser.html +59 -41
  12. data/doc/rdoc/classes/LibXML/XML/InputCallbacks.html +12 -6
  13. data/doc/rdoc/classes/LibXML/XML/NS.html +65 -50
  14. data/doc/rdoc/classes/LibXML/XML/Node.html +671 -630
  15. data/doc/rdoc/classes/LibXML/XML/Node/FailedModify.html +12 -0
  16. data/doc/rdoc/classes/LibXML/XML/Node/Set.html +64 -60
  17. data/doc/rdoc/classes/LibXML/XML/Node/SetNamespace.html +12 -0
  18. data/doc/rdoc/classes/LibXML/XML/Node/UnknownType.html +12 -0
  19. data/doc/rdoc/classes/LibXML/XML/Parser.html +407 -383
  20. data/doc/rdoc/classes/LibXML/XML/Parser/Context.html +241 -219
  21. data/doc/rdoc/classes/LibXML/XML/Parser/ParseError.html +12 -0
  22. data/doc/rdoc/classes/LibXML/XML/Reader.html +421 -331
  23. data/doc/rdoc/classes/LibXML/XML/RelaxNG.html +237 -0
  24. data/doc/rdoc/classes/LibXML/XML/SaxParser.html +79 -60
  25. data/doc/rdoc/classes/LibXML/XML/Schema.html +109 -22
  26. data/doc/rdoc/classes/LibXML/XML/State.html +6 -0
  27. data/doc/rdoc/classes/LibXML/XML/XInclude.html +6 -0
  28. data/doc/rdoc/classes/LibXML/XML/XInclude/Error.html +6 -0
  29. data/doc/rdoc/classes/LibXML/XML/XPath.html +4 -48
  30. data/doc/rdoc/classes/LibXML/XML/XPath/Context.html +6 -5
  31. data/doc/rdoc/classes/LibXML/XML/XPath/InvalidPath.html +61 -0
  32. data/doc/rdoc/classes/LibXML/XML/XPath/Object.html +12 -8
  33. data/doc/rdoc/classes/LibXML/XML/XPointer.html +14 -8
  34. data/doc/rdoc/classes/LibXML/XML/XPointer/Context.html +6 -0
  35. data/doc/rdoc/classes/LibXML/XML/XPointer/Context/InvalidPath.html +6 -0
  36. data/doc/rdoc/classes/LibXML/XML/XPointer/InvalidExpression.html +13 -0
  37. data/doc/rdoc/created.rid +1 -1
  38. data/doc/rdoc/files/CHANGES.html +38 -10
  39. data/doc/rdoc/files/LICENSE.html +1 -1
  40. data/doc/rdoc/files/README.html +57 -23
  41. data/doc/rdoc/files/VERSION.html +1 -1
  42. data/doc/rdoc/files/ext/libxml/cbg_c.html +1 -1
  43. data/doc/rdoc/files/ext/libxml/libxml_c.html +1 -1
  44. data/doc/rdoc/files/ext/libxml/ruby_xml_attr_c.html +1 -1
  45. data/doc/rdoc/files/ext/libxml/ruby_xml_attributes_c.html +1 -1
  46. data/doc/rdoc/files/ext/libxml/ruby_xml_document_c.html +1 -1
  47. data/doc/rdoc/files/ext/libxml/ruby_xml_dtd_c.html +1 -1
  48. data/doc/rdoc/files/ext/libxml/ruby_xml_html_parser_c.html +1 -1
  49. data/doc/rdoc/files/ext/libxml/ruby_xml_input_cbg_c.html +1 -1
  50. data/doc/rdoc/files/ext/libxml/ruby_xml_node_c.html +1 -1
  51. data/doc/rdoc/files/ext/libxml/ruby_xml_node_set_c.html +1 -1
  52. data/doc/rdoc/files/ext/libxml/ruby_xml_ns_c.html +1 -1
  53. data/doc/rdoc/files/ext/libxml/ruby_xml_parser_c.html +1 -1
  54. data/doc/rdoc/files/ext/libxml/ruby_xml_parser_context_c.html +1 -1
  55. data/doc/rdoc/files/ext/libxml/ruby_xml_reader_c.html +1 -1
  56. data/doc/rdoc/{classes/XML.html → files/ext/libxml/ruby_xml_relaxng_c.html} +16 -35
  57. data/doc/rdoc/files/ext/libxml/ruby_xml_sax_parser_c.html +1 -1
  58. data/doc/rdoc/files/ext/libxml/ruby_xml_schema_c.html +1 -1
  59. data/doc/rdoc/files/ext/libxml/ruby_xml_state_c.html +1 -1
  60. data/doc/rdoc/files/ext/libxml/ruby_xml_xinclude_c.html +1 -1
  61. data/doc/rdoc/files/ext/libxml/ruby_xml_xpath_c.html +1 -1
  62. data/doc/rdoc/files/ext/libxml/ruby_xml_xpath_context_c.html +1 -1
  63. data/doc/rdoc/files/ext/libxml/ruby_xml_xpath_object_c.html +1 -1
  64. data/doc/rdoc/files/ext/libxml/ruby_xml_xpointer_c.html +1 -1
  65. data/doc/rdoc/files/ext/libxml/ruby_xml_xpointer_context_c.html +1 -1
  66. data/doc/rdoc/files/lib/libxml/attr_rb.html +1 -1
  67. data/doc/rdoc/files/lib/libxml/attributes_rb.html +1 -1
  68. data/doc/rdoc/files/lib/libxml/document_rb.html +1 -1
  69. data/doc/rdoc/files/lib/libxml/node_rb.html +1 -1
  70. data/doc/rdoc/files/lib/libxml/node_set_rb.html +1 -1
  71. data/doc/rdoc/files/lib/libxml/parser_options_rb.html +1 -1
  72. data/doc/rdoc/files/lib/libxml/parser_rb.html +1 -1
  73. data/doc/rdoc/files/lib/libxml/properties_rb.html +1 -1
  74. data/doc/rdoc/files/lib/libxml/tree_rb.html +1 -1
  75. data/doc/rdoc/files/lib/libxml_rb.html +2 -2
  76. data/doc/rdoc/files/lib/xml/libxml_rb.html +12 -2
  77. data/doc/rdoc/files/lib/xml_rb.html +134 -0
  78. data/doc/rdoc/fr_class_index.html +1 -1
  79. data/doc/rdoc/fr_file_index.html +2 -0
  80. data/doc/rdoc/fr_method_index.html +349 -344
  81. data/ext/libxml/libxml.c +2 -1
  82. data/ext/libxml/ruby_libxml.h +1 -0
  83. data/ext/libxml/ruby_xml_attr.c +8 -2
  84. data/ext/libxml/ruby_xml_attributes.c +5 -5
  85. data/ext/libxml/ruby_xml_document.c +41 -2
  86. data/ext/libxml/ruby_xml_dtd.c +169 -169
  87. data/ext/libxml/ruby_xml_html_parser.c +449 -449
  88. data/ext/libxml/ruby_xml_input_cbg.c +165 -165
  89. data/ext/libxml/ruby_xml_node.c +1 -1
  90. data/ext/libxml/ruby_xml_node_set.c +172 -172
  91. data/ext/libxml/ruby_xml_ns.c +145 -145
  92. data/ext/libxml/ruby_xml_parser.c +1398 -1398
  93. data/ext/libxml/ruby_xml_parser_context.c +697 -697
  94. data/ext/libxml/ruby_xml_reader.c +44 -0
  95. data/ext/libxml/ruby_xml_reader.h +14 -14
  96. data/ext/libxml/ruby_xml_relaxng.c +97 -0
  97. data/ext/libxml/ruby_xml_relaxng.h +15 -0
  98. data/ext/libxml/ruby_xml_sax_parser.c +486 -486
  99. data/ext/libxml/ruby_xml_schema.c +1 -1
  100. data/ext/libxml/ruby_xml_state.c +4 -4
  101. data/ext/libxml/ruby_xml_xinclude.c +21 -21
  102. data/ext/libxml/ruby_xml_xpath.c +89 -89
  103. data/ext/libxml/ruby_xml_xpath_context.c +283 -283
  104. data/ext/libxml/ruby_xml_xpath_object.c +5 -5
  105. data/ext/libxml/ruby_xml_xpointer.c +104 -104
  106. data/ext/libxml/ruby_xml_xpointer_context.c +22 -22
  107. data/ext/libxml/version.h +2 -2
  108. data/ext/libxml/version.h.rej +17 -0
  109. data/ext/mingw/Rakefile +41 -0
  110. data/lib/libxml.rb +15 -4
  111. data/lib/xml.rb +14 -0
  112. data/lib/xml/libxml.rb +4 -1
  113. data/test/etc_doc_to_s.rb +1 -1
  114. data/test/ets_copy_bug.rb +1 -1
  115. data/test/ets_copy_bug3.rb +1 -1
  116. data/test/ets_doc_file.rb +1 -1
  117. data/test/ets_doc_to_s.rb +1 -1
  118. data/test/ets_node_gc.rb +1 -1
  119. data/test/ets_tsr.rb +1 -1
  120. data/test/model/shiporder.rnc +28 -0
  121. data/test/model/shiporder.rng +86 -0
  122. data/test/{tc_xml_attributes.rb → tc_attributes.rb} +1 -10
  123. data/test/{tc_xml_document.rb → tc_document.rb} +1 -1
  124. data/test/{tc_xml_document_write.rb → tc_document_write.rb} +1 -1
  125. data/test/{tc_xml_dtd.rb → tc_dtd.rb} +1 -1
  126. data/test/{tc_xml_html_parser.rb → tc_html_parser.rb} +1 -1
  127. data/test/{tc_xml_node.rb → tc_node.rb} +1 -1
  128. data/test/{tc_xml_node_attr.rb → tc_node_attr.rb} +1 -1
  129. data/test/{tc_xml_node_cdata.rb → tc_node_cdata.rb} +24 -5
  130. data/test/{tc_xml_node_comment.rb → tc_node_comment.rb} +1 -1
  131. data/test/{tc_xml_node_copy.rb → tc_node_copy.rb} +1 -1
  132. data/test/{tc_xml_node_edit.rb → tc_node_edit.rb} +1 -1
  133. data/test/{tc_xml_node_set.rb → tc_node_set.rb} +1 -1
  134. data/test/{tc_xml_node_set2.rb → tc_node_set2.rb} +1 -1
  135. data/test/{tc_xml_node_text.rb → tc_node_text.rb} +1 -1
  136. data/test/{tc_xml_node_xlink.rb → tc_node_xlink.rb} +2 -2
  137. data/test/{tc_xml_parser.rb → tc_parser.rb} +1 -1
  138. data/test/{tc_xml_parser_context.rb → tc_parser_context.rb} +1 -1
  139. data/test/{tc_xml_properties.rb → tc_properties.rb} +1 -7
  140. data/test/{tc_xml_reader.rb → tc_reader.rb} +1 -1
  141. data/test/tc_relaxng.rb +39 -0
  142. data/test/{tc_xml_sax_parser.rb → tc_sax_parser.rb} +1 -1
  143. data/test/{tc_xml_schema.rb → tc_schema.rb} +1 -1
  144. data/test/{tc_xml_traversal.rb → tc_traversal.rb} +1 -1
  145. data/test/{tc_xml_xinclude.rb → tc_xinclude.rb} +1 -1
  146. data/test/{tc_xml_xpath.rb → tc_xpath.rb} +1 -1
  147. data/test/{tc_xml_xpath_context.rb → tc_xpath_context.rb} +1 -1
  148. data/test/{tc_xml_xpointer.rb → tc_xpointer.rb} +1 -1
  149. data/test/test_suite.rb +26 -25
  150. metadata +100 -100
  151. data/benchmark/depixelate.rb +0 -632
  152. data/benchmark/hamlet.xml +0 -9055
  153. data/benchmark/sock_entries.xml +0 -507
  154. data/benchmark/throughput.rb +0 -39
  155. data/benchmark/xml_benchmarks.rb +0 -227
  156. data/mingw/libiconv-2.dll +0 -0
  157. data/mingw/libxml2-2.dll +0 -0
  158. data/mingw/libxml_ruby.so +0 -0
  159. data/test/gc.log +0 -0
  160. data/vc/libxml_ruby.sln +0 -20
  161. data/vc/libxml_ruby.vcproj +0 -389
@@ -1,697 +1,697 @@
1
- /* $Id: ruby_xml_parser_context.c 461 2008-07-15 21:35:56Z cfis $ */
2
-
3
- /* Please see the LICENSE file for copyright and distribution information */
4
-
5
- #include "ruby_libxml.h"
6
- #include "ruby_xml_parser_context.h"
7
-
8
- /* TODO:
9
- *
10
- * *) xmlParserInput class/structure
11
- * *) errNo and mappings
12
- * *) validity context
13
- * *) record_info or stats class/structure
14
- * *) xmlParserNodeInfoSeq
15
- * *) xmlParserInputState
16
- */
17
- VALUE cXMLParserContext;
18
-
19
- /*
20
- * call-seq:
21
- * context.data_directory -> "dir"
22
- *
23
- * Obtain the data directory associated with this context.
24
- */
25
- VALUE
26
- ruby_xml_parser_context_data_directory_get(VALUE self) {
27
- ruby_xml_parser_context *rxpc;
28
- Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
29
-
30
- if (rxpc->ctxt->directory == NULL)
31
- return(Qnil);
32
- else
33
- return(rb_str_new2(rxpc->ctxt->directory));
34
- }
35
-
36
-
37
- /*
38
- * call-seq:
39
- * context.depth -> num
40
- *
41
- * Obtain the depth of this context.
42
- */
43
- VALUE
44
- ruby_xml_parser_context_depth_get(VALUE self) {
45
- ruby_xml_parser_context *rxpc;
46
- Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
47
-
48
- return(INT2NUM(rxpc->ctxt->depth));
49
- }
50
-
51
-
52
- /*
53
- * call-seq:
54
- * context.disable_sax? -> (true|false)
55
- *
56
- * Determine whether SAX-based processing is disabled
57
- * in this context.
58
- */
59
- VALUE
60
- ruby_xml_parser_context_disable_sax_q(VALUE self) {
61
- ruby_xml_parser_context *rxpc;
62
- Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
63
-
64
- if (rxpc->ctxt->disableSAX)
65
- return(Qtrue);
66
- else
67
- return(Qfalse);
68
- }
69
-
70
-
71
-
72
- /*
73
- * call-seq:
74
- * context.docbook? -> (true|false)
75
- *
76
- * Determine whether this is a docbook context.
77
- */
78
- VALUE
79
- ruby_xml_parser_context_docbook_q(VALUE self) {
80
- ruby_xml_parser_context *rxpc;
81
- Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
82
-
83
- if (rxpc->ctxt->html == 2) // TODO check this
84
- return(Qtrue);
85
- else
86
- return(Qfalse);
87
- }
88
-
89
-
90
- /*
91
- * call-seq:
92
- * context.encoding -> "encoding"
93
- *
94
- * Obtain the character encoding identifier used in
95
- * this context.
96
- */
97
- VALUE
98
- ruby_xml_parser_context_encoding_get(VALUE self) {
99
- ruby_xml_parser_context *rxpc;
100
- Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
101
-
102
- if (rxpc->ctxt->encoding == NULL)
103
- return(Qnil);
104
- else
105
- return(rb_str_new2((const char*)rxpc->ctxt->encoding));
106
- }
107
-
108
-
109
- /*
110
- * call-seq:
111
- * context.errno -> num
112
- *
113
- * Obtain the last-error number in this context.
114
- */
115
- VALUE
116
- ruby_xml_parser_context_errno_get(VALUE self) {
117
- ruby_xml_parser_context *rxpc;
118
- Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
119
-
120
- return(INT2NUM(rxpc->ctxt->errNo));
121
- }
122
-
123
-
124
- void
125
- ruby_xml_parser_context_free(ruby_xml_parser_context *rxpc) {
126
- if (rxpc->ctxt != NULL) {
127
- xmlFreeParserCtxt(rxpc->ctxt);
128
- rxpc->ctxt = NULL;
129
- }
130
-
131
- ruby_xfree(rxpc);
132
- }
133
-
134
-
135
- /*
136
- * call-seq:
137
- * context.html? -> (true|false)
138
- *
139
- * Determine whether this is an html context.
140
- */
141
- VALUE
142
- ruby_xml_parser_context_html_q(VALUE self) {
143
- ruby_xml_parser_context *rxpc;
144
- Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
145
-
146
- if (rxpc->ctxt->html == 1)
147
- return(Qtrue);
148
- else
149
- return(Qfalse);
150
- }
151
-
152
-
153
- /*
154
- * call-seq:
155
- * context.max_num_streams -> num
156
- *
157
- * Obtain the limit on the number of IO streams opened in
158
- * this context.
159
- */
160
- VALUE
161
- ruby_xml_parser_context_io_max_num_streams_get(VALUE self) {
162
- // TODO alias to max_streams and dep this?
163
- ruby_xml_parser_context *rxpc;
164
- Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
165
-
166
- return(INT2NUM(rxpc->ctxt->inputMax));
167
- }
168
-
169
-
170
- /*
171
- * call-seq:
172
- * context.num_streams -> "dir"
173
- *
174
- * Obtain the actual number of IO streams in this
175
- * context.
176
- */
177
- VALUE
178
- ruby_xml_parser_context_io_num_streams_get(VALUE self) {
179
- ruby_xml_parser_context *rxpc;
180
- Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
181
-
182
- return(INT2NUM(rxpc->ctxt->inputNr));
183
- }
184
-
185
-
186
- /*
187
- * call-seq:
188
- * context.keep_blanks? -> (true|false)
189
- *
190
- * Determine whether parsers in this context retain
191
- * whitespace.
192
- */
193
- VALUE
194
- ruby_xml_parser_context_keep_blanks_q(VALUE self) {
195
- ruby_xml_parser_context *rxpc;
196
- Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
197
-
198
- if (rxpc->ctxt->keepBlanks)
199
- return(Qtrue);
200
- else
201
- return(Qfalse);
202
- }
203
-
204
-
205
- /*
206
- * call-seq:
207
- * context.name_depth -> num
208
- *
209
- * Obtain the name depth for this context.
210
- */
211
- VALUE
212
- ruby_xml_parser_context_name_depth_get(VALUE self) {
213
- ruby_xml_parser_context *rxpc;
214
- Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
215
-
216
- return(INT2NUM(rxpc->ctxt->nameNr));
217
- }
218
-
219
-
220
- /*
221
- * call-seq:
222
- * context.name_depth_max -> num
223
- *
224
- * Obtain the maximum name depth for this context.
225
- */
226
- VALUE
227
- ruby_xml_parser_context_name_depth_max_get(VALUE self) {
228
- ruby_xml_parser_context *rxpc;
229
- Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
230
-
231
- return(INT2NUM(rxpc->ctxt->nameMax));
232
- }
233
-
234
-
235
- /*
236
- * call-seq:
237
- * context.name_node -> "name"
238
- *
239
- * Obtain the name node for this context.
240
- */
241
- VALUE
242
- ruby_xml_parser_context_name_node_get(VALUE self) {
243
- ruby_xml_parser_context *rxpc;
244
- Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
245
-
246
- if (rxpc->ctxt->name == NULL)
247
- return(Qnil);
248
- else
249
- return(rb_str_new2((const char*)rxpc->ctxt->name));
250
- }
251
-
252
-
253
- /*
254
- * call-seq:
255
- * context.name_tab -> ["name", ..., "name"]
256
- *
257
- * Obtain the name table for this context.
258
- */
259
- VALUE
260
- ruby_xml_parser_context_name_tab_get(VALUE self) {
261
- int i;
262
- ruby_xml_parser_context *rxpc;
263
- VALUE tab_ary;
264
-
265
- Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
266
-
267
- if (rxpc->ctxt->nameTab == NULL)
268
- return(Qnil);
269
-
270
- tab_ary = rb_ary_new();
271
-
272
- for (i = (rxpc->ctxt->nameNr - 1); i >= 0; i--) {
273
- if (rxpc->ctxt->nameTab[i] == NULL)
274
- continue;
275
- else
276
- rb_ary_push(tab_ary, rb_str_new2((const char*)rxpc->ctxt->nameTab[i]));
277
- }
278
-
279
- return(tab_ary);
280
- }
281
-
282
-
283
- /*
284
- * call-seq:
285
- * context.node_depth -> num
286
- *
287
- * Obtain the node depth for this context.
288
- */
289
- VALUE
290
- ruby_xml_parser_context_node_depth_get(VALUE self) {
291
- ruby_xml_parser_context *rxpc;
292
- Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
293
-
294
- return(INT2NUM(rxpc->ctxt->nodeNr));
295
- }
296
-
297
-
298
- /*
299
- * call-seq:
300
- * context.node -> node
301
- *
302
- * Obtain the root node of this context.
303
- */
304
- VALUE
305
- ruby_xml_parser_context_node_get(VALUE self) {
306
- ruby_xml_parser_context *rxpc;
307
- Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
308
-
309
- if (rxpc->ctxt->node == NULL)
310
- return(Qnil);
311
- else
312
- return(ruby_xml_node2_wrap(cXMLNode,
313
- rxpc->ctxt->node));
314
- }
315
-
316
-
317
- /*
318
- * call-seq:
319
- * context.node_depth_max -> num
320
- *
321
- * Obtain the maximum node depth for this context.
322
- */
323
- VALUE
324
- ruby_xml_parser_context_node_depth_max_get(VALUE self) {
325
- ruby_xml_parser_context *rxpc;
326
- Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
327
-
328
- return(INT2NUM(rxpc->ctxt->nodeMax));
329
- }
330
-
331
-
332
- /*
333
- * call-seq:
334
- * context.num_chars -> num
335
- *
336
- * Obtain the number of characters in this context.
337
- */
338
- VALUE
339
- ruby_xml_parser_context_num_chars_get(VALUE self) {
340
- ruby_xml_parser_context *rxpc;
341
- Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
342
-
343
- return(LONG2NUM(rxpc->ctxt->nbChars));
344
- }
345
-
346
-
347
- VALUE
348
- ruby_xml_parser_context_new() {
349
- ruby_xml_parser_context *rxpc = ALLOC(ruby_xml_parser_context);
350
- return Data_Wrap_Struct(cXMLParserContext,
351
- NULL,
352
- ruby_xml_parser_context_free,
353
- rxpc);
354
- }
355
-
356
-
357
- VALUE
358
- ruby_xml_parser_context_options_set(VALUE self, VALUE options) {
359
- ruby_xml_parser_context *rxpc;
360
- Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
361
-
362
- if (xmlCtxtUseOptions(rxpc->ctxt, NUM2INT(options)))
363
- return Qfalse;
364
- else
365
- return Qtrue;
366
- }
367
-
368
- VALUE
369
- ruby_xml_parser_context_options_get(VALUE self) {
370
- ruby_xml_parser_context *rxpc;
371
- Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
372
- return INT2NUM(rxpc->ctxt->options);
373
- }
374
-
375
- /*
376
- * call-seq:
377
- * context.replace_entities? -> (true|false)
378
- *
379
- * Determine whether external entity replacement is enabled in this
380
- * context.
381
- */
382
- VALUE
383
- ruby_xml_parser_context_replace_entities_q(VALUE self) {
384
- ruby_xml_parser_context *rxpc;
385
- Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
386
-
387
- if (rxpc->ctxt->replaceEntities)
388
- return(Qtrue);
389
- else
390
- return(Qfalse);
391
- }
392
-
393
-
394
- /*
395
- * call-seq:
396
- * context.replace_entities = true|false
397
- *
398
- * Control whether external entity replacement is enabled in this
399
- * context.
400
- */
401
- VALUE
402
- ruby_xml_parser_context_replace_entities_set(VALUE self, VALUE bool) {
403
- ruby_xml_parser_context *rxpc;
404
- Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
405
-
406
- if (TYPE(bool) == T_FALSE) {
407
- rxpc->ctxt->replaceEntities = 0;
408
- return(Qfalse);
409
- } else {
410
- rxpc->ctxt->replaceEntities = 1;
411
- return(Qfalse);
412
- }
413
- }
414
-
415
- /*
416
- * call-seq:
417
- * context.space_depth -> num
418
- *
419
- * Obtain the space depth for this context.
420
- */
421
- VALUE
422
- ruby_xml_parser_context_space_depth_get(VALUE self) {
423
- ruby_xml_parser_context *rxpc;
424
- Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
425
-
426
- return(INT2NUM(rxpc->ctxt->spaceNr));
427
- }
428
-
429
-
430
- /*
431
- * call-seq:
432
- * context.space_depth -> num
433
- *
434
- * Obtain the maximum space depth for this context.
435
- */
436
- VALUE
437
- ruby_xml_parser_context_space_depth_max_get(VALUE self) {
438
- ruby_xml_parser_context *rxpc;
439
- Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
440
-
441
- return(INT2NUM(rxpc->ctxt->spaceMax));
442
- }
443
-
444
-
445
- /*
446
- * call-seq:
447
- * context.subset_external? -> (true|false)
448
- *
449
- * Determine whether this context is a subset of an
450
- * external context.
451
- */
452
- VALUE
453
- ruby_xml_parser_context_subset_external_q(VALUE self) {
454
- ruby_xml_parser_context *rxpc;
455
- Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
456
-
457
- if (rxpc->ctxt->inSubset == 2)
458
- return(Qtrue);
459
- else
460
- return(Qfalse);
461
- }
462
-
463
-
464
- /*
465
- * call-seq:
466
- * context.subset_internal? -> (true|false)
467
- *
468
- * Determine whether this context is a subset of an
469
- * internal context.
470
- */
471
- VALUE
472
- ruby_xml_parser_context_subset_internal_q(VALUE self) {
473
- ruby_xml_parser_context *rxpc;
474
- Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
475
-
476
- if (rxpc->ctxt->inSubset == 1)
477
- return(Qtrue);
478
- else
479
- return(Qfalse);
480
- }
481
-
482
-
483
- /*
484
- * call-seq:
485
- * context.subset_name -> "name"
486
- *
487
- * Obtain this context's subset name (valid only if
488
- * either of subset_external? or subset_internal?
489
- * is true).
490
- */
491
- VALUE
492
- ruby_xml_parser_context_subset_name_get(VALUE self) {
493
- ruby_xml_parser_context *rxpc;
494
- Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
495
-
496
- if (rxpc->ctxt->intSubName == NULL)
497
- return(Qnil);
498
- else
499
- return(rb_str_new2((const char*)rxpc->ctxt->intSubName));
500
- }
501
-
502
-
503
- /*
504
- * call-seq:
505
- * context.subset_external_uri -> "uri"
506
- *
507
- * Obtain this context's external subset URI. (valid only if
508
- * either of subset_external? or subset_internal?
509
- * is true).
510
- */
511
- VALUE
512
- ruby_xml_parser_context_subset_external_uri_get(VALUE self) {
513
- ruby_xml_parser_context *rxpc;
514
- Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
515
-
516
- if (rxpc->ctxt->extSubURI == NULL)
517
- return(Qnil);
518
- else
519
- return(rb_str_new2((const char*)rxpc->ctxt->extSubURI));
520
- }
521
-
522
-
523
- /*
524
- * call-seq:
525
- * context.subset_external_system_id -> "system_id"
526
- *
527
- * Obtain this context's external subset system identifier.
528
- * (valid only if either of subset_external? or subset_internal?
529
- * is true).
530
- */
531
- VALUE
532
- ruby_xml_parser_context_subset_external_system_id_get(VALUE self) {
533
- ruby_xml_parser_context *rxpc;
534
- Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
535
-
536
- if (rxpc->ctxt->extSubSystem == NULL)
537
- return(Qnil);
538
- else
539
- return(rb_str_new2((const char*)rxpc->ctxt->extSubSystem));
540
- }
541
-
542
-
543
- /*
544
- * call-seq:
545
- * context.standalone? -> (true|false)
546
- *
547
- * Determine whether this is a standalone context.
548
- */
549
- VALUE
550
- ruby_xml_parser_context_standalone_q(VALUE self) {
551
- ruby_xml_parser_context *rxpc;
552
- Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
553
-
554
- if (rxpc->ctxt->standalone)
555
- return(Qtrue);
556
- else
557
- return(Qfalse);
558
- }
559
-
560
-
561
- /*
562
- * call-seq:
563
- * context.stats? -> (true|false)
564
- *
565
- * Determine whether this context maintains statistics.
566
- */
567
- VALUE
568
- ruby_xml_parser_context_stats_q(VALUE self) {
569
- ruby_xml_parser_context *rxpc;
570
- Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
571
-
572
- if (rxpc->ctxt->record_info)
573
- return(Qtrue);
574
- else
575
- return(Qfalse);
576
- }
577
-
578
-
579
- /*
580
- * call-seq:
581
- * context.valid? -> (true|false)
582
- *
583
- * Determine whether this context is valid.
584
- */
585
- VALUE
586
- ruby_xml_parser_context_valid_q(VALUE self) {
587
- ruby_xml_parser_context *rxpc;
588
- Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
589
-
590
- if (rxpc->ctxt->valid)
591
- return(Qtrue);
592
- else
593
- return(Qfalse);
594
- }
595
-
596
-
597
- /*
598
- * call-seq:
599
- * context.validate? -> (true|false)
600
- *
601
- * Determine whether validation is enabled in this context.
602
- */
603
- VALUE
604
- ruby_xml_parser_context_validate_q(VALUE self) {
605
- ruby_xml_parser_context *rxpc;
606
- Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
607
-
608
- if (rxpc->ctxt->validate)
609
- return(Qtrue);
610
- else
611
- return(Qfalse);
612
- }
613
-
614
-
615
- /*
616
- * call-seq:
617
- * context.version -> "version"
618
- *
619
- * Obtain this context's version identifier.
620
- */
621
- VALUE
622
- ruby_xml_parser_context_version_get(VALUE self) {
623
- ruby_xml_parser_context *rxpc;
624
- Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
625
-
626
- if (rxpc->ctxt->version == NULL)
627
- return(Qnil);
628
- else
629
- return(rb_str_new2((const char*)rxpc->ctxt->version));
630
- }
631
-
632
-
633
- /*
634
- * call-seq:
635
- * context.well_formed? -> (true|false)
636
- *
637
- * Determine whether this context contains well-formed XML.
638
- */
639
- VALUE
640
- ruby_xml_parser_context_well_formed_q(VALUE self) {
641
- ruby_xml_parser_context *rxpc;
642
- Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
643
-
644
- if (rxpc->ctxt->wellFormed)
645
- return(Qtrue);
646
- else
647
- return(Qfalse);
648
- }
649
-
650
-
651
- // Rdoc needs to know
652
- #ifdef RDOC_NEVER_DEFINED
653
- mLibXML = rb_define_module("LibXML");
654
- mXML = rb_define_module_under(mLibXML, "XML");
655
- cXMLParser = rb_define_class_under(mXML, "Parser", rb_cObject);
656
- #endif
657
-
658
- void
659
- ruby_init_xml_parser_context(void) {
660
- cXMLParserContext = rb_define_class_under(cXMLParser, "Context", rb_cObject);
661
-
662
- rb_define_method(cXMLParserContext, "data_directory", ruby_xml_parser_context_data_directory_get, 0);
663
- rb_define_method(cXMLParserContext, "depth", ruby_xml_parser_context_depth_get, 0);
664
- rb_define_method(cXMLParserContext, "disable_sax?", ruby_xml_parser_context_disable_sax_q, 0);
665
- rb_define_method(cXMLParserContext, "docbook?", ruby_xml_parser_context_docbook_q, 0);
666
- rb_define_method(cXMLParserContext, "encoding", ruby_xml_parser_context_encoding_get, 0);
667
- rb_define_method(cXMLParserContext, "errno", ruby_xml_parser_context_errno_get, 0);
668
- rb_define_method(cXMLParserContext, "html?", ruby_xml_parser_context_html_q, 0);
669
- rb_define_method(cXMLParserContext, "io_max_num_streams", ruby_xml_parser_context_io_max_num_streams_get, 0);
670
- rb_define_method(cXMLParserContext, "io_num_streams", ruby_xml_parser_context_io_num_streams_get, 0);
671
- rb_define_method(cXMLParserContext, "keep_blanks?", ruby_xml_parser_context_keep_blanks_q, 0);
672
- rb_define_method(cXMLParserContext, "name_node", ruby_xml_parser_context_name_node_get, 0);
673
- rb_define_method(cXMLParserContext, "name_depth", ruby_xml_parser_context_name_depth_get, 0);
674
- rb_define_method(cXMLParserContext, "name_depth_max", ruby_xml_parser_context_name_depth_max_get, 0);
675
- rb_define_method(cXMLParserContext, "name_tab", ruby_xml_parser_context_name_tab_get, 0);
676
- rb_define_method(cXMLParserContext, "node", ruby_xml_parser_context_node_get, 0);
677
- rb_define_method(cXMLParserContext, "node_depth", ruby_xml_parser_context_node_depth_get, 0);
678
- rb_define_method(cXMLParserContext, "node_depth_max", ruby_xml_parser_context_node_depth_max_get, 0);
679
- rb_define_method(cXMLParserContext, "num_chars", ruby_xml_parser_context_num_chars_get, 0);
680
- rb_define_method(cXMLParserContext, "options", ruby_xml_parser_context_options_get, 0);
681
- rb_define_method(cXMLParserContext, "options=", ruby_xml_parser_context_options_set, 1);
682
- rb_define_method(cXMLParserContext, "replace_entities?", ruby_xml_parser_context_replace_entities_q, 0);
683
- rb_define_method(cXMLParserContext, "replace_entities=", ruby_xml_parser_context_replace_entities_set, 1);
684
- rb_define_method(cXMLParserContext, "space_depth", ruby_xml_parser_context_space_depth_get, 0);
685
- rb_define_method(cXMLParserContext, "space_depth_max", ruby_xml_parser_context_space_depth_max_get, 0);
686
- rb_define_method(cXMLParserContext, "subset_external?", ruby_xml_parser_context_subset_external_q, 0);
687
- rb_define_method(cXMLParserContext, "subset_external_system_id", ruby_xml_parser_context_subset_external_system_id_get, 0);
688
- rb_define_method(cXMLParserContext, "subset_external_uri", ruby_xml_parser_context_subset_name_get, 0);
689
- rb_define_method(cXMLParserContext, "subset_internal?", ruby_xml_parser_context_subset_internal_q, 0);
690
- rb_define_method(cXMLParserContext, "subset_internal_name", ruby_xml_parser_context_subset_name_get, 0);
691
- rb_define_method(cXMLParserContext, "stats?", ruby_xml_parser_context_stats_q, 0);
692
- rb_define_method(cXMLParserContext, "standalone?", ruby_xml_parser_context_standalone_q, 0);
693
- rb_define_method(cXMLParserContext, "valid", ruby_xml_parser_context_valid_q, 0);
694
- rb_define_method(cXMLParserContext, "validate?", ruby_xml_parser_context_validate_q, 0);
695
- rb_define_method(cXMLParserContext, "version", ruby_xml_parser_context_version_get, 0);
696
- rb_define_method(cXMLParserContext, "well_formed?", ruby_xml_parser_context_well_formed_q, 0);
697
- }
1
+ /* $Id: ruby_xml_parser_context.c 461 2008-07-15 21:35:56Z cfis $ */
2
+
3
+ /* Please see the LICENSE file for copyright and distribution information */
4
+
5
+ #include "ruby_libxml.h"
6
+ #include "ruby_xml_parser_context.h"
7
+
8
+ /* TODO:
9
+ *
10
+ * *) xmlParserInput class/structure
11
+ * *) errNo and mappings
12
+ * *) validity context
13
+ * *) record_info or stats class/structure
14
+ * *) xmlParserNodeInfoSeq
15
+ * *) xmlParserInputState
16
+ */
17
+ VALUE cXMLParserContext;
18
+
19
+ /*
20
+ * call-seq:
21
+ * context.data_directory -> "dir"
22
+ *
23
+ * Obtain the data directory associated with this context.
24
+ */
25
+ VALUE
26
+ ruby_xml_parser_context_data_directory_get(VALUE self) {
27
+ ruby_xml_parser_context *rxpc;
28
+ Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
29
+
30
+ if (rxpc->ctxt->directory == NULL)
31
+ return(Qnil);
32
+ else
33
+ return(rb_str_new2(rxpc->ctxt->directory));
34
+ }
35
+
36
+
37
+ /*
38
+ * call-seq:
39
+ * context.depth -> num
40
+ *
41
+ * Obtain the depth of this context.
42
+ */
43
+ VALUE
44
+ ruby_xml_parser_context_depth_get(VALUE self) {
45
+ ruby_xml_parser_context *rxpc;
46
+ Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
47
+
48
+ return(INT2NUM(rxpc->ctxt->depth));
49
+ }
50
+
51
+
52
+ /*
53
+ * call-seq:
54
+ * context.disable_sax? -> (true|false)
55
+ *
56
+ * Determine whether SAX-based processing is disabled
57
+ * in this context.
58
+ */
59
+ VALUE
60
+ ruby_xml_parser_context_disable_sax_q(VALUE self) {
61
+ ruby_xml_parser_context *rxpc;
62
+ Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
63
+
64
+ if (rxpc->ctxt->disableSAX)
65
+ return(Qtrue);
66
+ else
67
+ return(Qfalse);
68
+ }
69
+
70
+
71
+
72
+ /*
73
+ * call-seq:
74
+ * context.docbook? -> (true|false)
75
+ *
76
+ * Determine whether this is a docbook context.
77
+ */
78
+ VALUE
79
+ ruby_xml_parser_context_docbook_q(VALUE self) {
80
+ ruby_xml_parser_context *rxpc;
81
+ Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
82
+
83
+ if (rxpc->ctxt->html == 2) // TODO check this
84
+ return(Qtrue);
85
+ else
86
+ return(Qfalse);
87
+ }
88
+
89
+
90
+ /*
91
+ * call-seq:
92
+ * context.encoding -> "encoding"
93
+ *
94
+ * Obtain the character encoding identifier used in
95
+ * this context.
96
+ */
97
+ VALUE
98
+ ruby_xml_parser_context_encoding_get(VALUE self) {
99
+ ruby_xml_parser_context *rxpc;
100
+ Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
101
+
102
+ if (rxpc->ctxt->encoding == NULL)
103
+ return(Qnil);
104
+ else
105
+ return(rb_str_new2((const char*)rxpc->ctxt->encoding));
106
+ }
107
+
108
+
109
+ /*
110
+ * call-seq:
111
+ * context.errno -> num
112
+ *
113
+ * Obtain the last-error number in this context.
114
+ */
115
+ VALUE
116
+ ruby_xml_parser_context_errno_get(VALUE self) {
117
+ ruby_xml_parser_context *rxpc;
118
+ Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
119
+
120
+ return(INT2NUM(rxpc->ctxt->errNo));
121
+ }
122
+
123
+
124
+ void
125
+ ruby_xml_parser_context_free(ruby_xml_parser_context *rxpc) {
126
+ if (rxpc->ctxt != NULL) {
127
+ xmlFreeParserCtxt(rxpc->ctxt);
128
+ rxpc->ctxt = NULL;
129
+ }
130
+
131
+ ruby_xfree(rxpc);
132
+ }
133
+
134
+
135
+ /*
136
+ * call-seq:
137
+ * context.html? -> (true|false)
138
+ *
139
+ * Determine whether this is an html context.
140
+ */
141
+ VALUE
142
+ ruby_xml_parser_context_html_q(VALUE self) {
143
+ ruby_xml_parser_context *rxpc;
144
+ Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
145
+
146
+ if (rxpc->ctxt->html == 1)
147
+ return(Qtrue);
148
+ else
149
+ return(Qfalse);
150
+ }
151
+
152
+
153
+ /*
154
+ * call-seq:
155
+ * context.max_num_streams -> num
156
+ *
157
+ * Obtain the limit on the number of IO streams opened in
158
+ * this context.
159
+ */
160
+ VALUE
161
+ ruby_xml_parser_context_io_max_num_streams_get(VALUE self) {
162
+ // TODO alias to max_streams and dep this?
163
+ ruby_xml_parser_context *rxpc;
164
+ Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
165
+
166
+ return(INT2NUM(rxpc->ctxt->inputMax));
167
+ }
168
+
169
+
170
+ /*
171
+ * call-seq:
172
+ * context.num_streams -> "dir"
173
+ *
174
+ * Obtain the actual number of IO streams in this
175
+ * context.
176
+ */
177
+ VALUE
178
+ ruby_xml_parser_context_io_num_streams_get(VALUE self) {
179
+ ruby_xml_parser_context *rxpc;
180
+ Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
181
+
182
+ return(INT2NUM(rxpc->ctxt->inputNr));
183
+ }
184
+
185
+
186
+ /*
187
+ * call-seq:
188
+ * context.keep_blanks? -> (true|false)
189
+ *
190
+ * Determine whether parsers in this context retain
191
+ * whitespace.
192
+ */
193
+ VALUE
194
+ ruby_xml_parser_context_keep_blanks_q(VALUE self) {
195
+ ruby_xml_parser_context *rxpc;
196
+ Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
197
+
198
+ if (rxpc->ctxt->keepBlanks)
199
+ return(Qtrue);
200
+ else
201
+ return(Qfalse);
202
+ }
203
+
204
+
205
+ /*
206
+ * call-seq:
207
+ * context.name_depth -> num
208
+ *
209
+ * Obtain the name depth for this context.
210
+ */
211
+ VALUE
212
+ ruby_xml_parser_context_name_depth_get(VALUE self) {
213
+ ruby_xml_parser_context *rxpc;
214
+ Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
215
+
216
+ return(INT2NUM(rxpc->ctxt->nameNr));
217
+ }
218
+
219
+
220
+ /*
221
+ * call-seq:
222
+ * context.name_depth_max -> num
223
+ *
224
+ * Obtain the maximum name depth for this context.
225
+ */
226
+ VALUE
227
+ ruby_xml_parser_context_name_depth_max_get(VALUE self) {
228
+ ruby_xml_parser_context *rxpc;
229
+ Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
230
+
231
+ return(INT2NUM(rxpc->ctxt->nameMax));
232
+ }
233
+
234
+
235
+ /*
236
+ * call-seq:
237
+ * context.name_node -> "name"
238
+ *
239
+ * Obtain the name node for this context.
240
+ */
241
+ VALUE
242
+ ruby_xml_parser_context_name_node_get(VALUE self) {
243
+ ruby_xml_parser_context *rxpc;
244
+ Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
245
+
246
+ if (rxpc->ctxt->name == NULL)
247
+ return(Qnil);
248
+ else
249
+ return(rb_str_new2((const char*)rxpc->ctxt->name));
250
+ }
251
+
252
+
253
+ /*
254
+ * call-seq:
255
+ * context.name_tab -> ["name", ..., "name"]
256
+ *
257
+ * Obtain the name table for this context.
258
+ */
259
+ VALUE
260
+ ruby_xml_parser_context_name_tab_get(VALUE self) {
261
+ int i;
262
+ ruby_xml_parser_context *rxpc;
263
+ VALUE tab_ary;
264
+
265
+ Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
266
+
267
+ if (rxpc->ctxt->nameTab == NULL)
268
+ return(Qnil);
269
+
270
+ tab_ary = rb_ary_new();
271
+
272
+ for (i = (rxpc->ctxt->nameNr - 1); i >= 0; i--) {
273
+ if (rxpc->ctxt->nameTab[i] == NULL)
274
+ continue;
275
+ else
276
+ rb_ary_push(tab_ary, rb_str_new2((const char*)rxpc->ctxt->nameTab[i]));
277
+ }
278
+
279
+ return(tab_ary);
280
+ }
281
+
282
+
283
+ /*
284
+ * call-seq:
285
+ * context.node_depth -> num
286
+ *
287
+ * Obtain the node depth for this context.
288
+ */
289
+ VALUE
290
+ ruby_xml_parser_context_node_depth_get(VALUE self) {
291
+ ruby_xml_parser_context *rxpc;
292
+ Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
293
+
294
+ return(INT2NUM(rxpc->ctxt->nodeNr));
295
+ }
296
+
297
+
298
+ /*
299
+ * call-seq:
300
+ * context.node -> node
301
+ *
302
+ * Obtain the root node of this context.
303
+ */
304
+ VALUE
305
+ ruby_xml_parser_context_node_get(VALUE self) {
306
+ ruby_xml_parser_context *rxpc;
307
+ Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
308
+
309
+ if (rxpc->ctxt->node == NULL)
310
+ return(Qnil);
311
+ else
312
+ return(ruby_xml_node2_wrap(cXMLNode,
313
+ rxpc->ctxt->node));
314
+ }
315
+
316
+
317
+ /*
318
+ * call-seq:
319
+ * context.node_depth_max -> num
320
+ *
321
+ * Obtain the maximum node depth for this context.
322
+ */
323
+ VALUE
324
+ ruby_xml_parser_context_node_depth_max_get(VALUE self) {
325
+ ruby_xml_parser_context *rxpc;
326
+ Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
327
+
328
+ return(INT2NUM(rxpc->ctxt->nodeMax));
329
+ }
330
+
331
+
332
+ /*
333
+ * call-seq:
334
+ * context.num_chars -> num
335
+ *
336
+ * Obtain the number of characters in this context.
337
+ */
338
+ VALUE
339
+ ruby_xml_parser_context_num_chars_get(VALUE self) {
340
+ ruby_xml_parser_context *rxpc;
341
+ Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
342
+
343
+ return(LONG2NUM(rxpc->ctxt->nbChars));
344
+ }
345
+
346
+
347
+ VALUE
348
+ ruby_xml_parser_context_new() {
349
+ ruby_xml_parser_context *rxpc = ALLOC(ruby_xml_parser_context);
350
+ return Data_Wrap_Struct(cXMLParserContext,
351
+ NULL,
352
+ ruby_xml_parser_context_free,
353
+ rxpc);
354
+ }
355
+
356
+
357
+ VALUE
358
+ ruby_xml_parser_context_options_set(VALUE self, VALUE options) {
359
+ ruby_xml_parser_context *rxpc;
360
+ Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
361
+
362
+ if (xmlCtxtUseOptions(rxpc->ctxt, NUM2INT(options)))
363
+ return Qfalse;
364
+ else
365
+ return Qtrue;
366
+ }
367
+
368
+ VALUE
369
+ ruby_xml_parser_context_options_get(VALUE self) {
370
+ ruby_xml_parser_context *rxpc;
371
+ Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
372
+ return INT2NUM(rxpc->ctxt->options);
373
+ }
374
+
375
+ /*
376
+ * call-seq:
377
+ * context.replace_entities? -> (true|false)
378
+ *
379
+ * Determine whether external entity replacement is enabled in this
380
+ * context.
381
+ */
382
+ VALUE
383
+ ruby_xml_parser_context_replace_entities_q(VALUE self) {
384
+ ruby_xml_parser_context *rxpc;
385
+ Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
386
+
387
+ if (rxpc->ctxt->replaceEntities)
388
+ return(Qtrue);
389
+ else
390
+ return(Qfalse);
391
+ }
392
+
393
+
394
+ /*
395
+ * call-seq:
396
+ * context.replace_entities = true|false
397
+ *
398
+ * Control whether external entity replacement is enabled in this
399
+ * context.
400
+ */
401
+ VALUE
402
+ ruby_xml_parser_context_replace_entities_set(VALUE self, VALUE bool) {
403
+ ruby_xml_parser_context *rxpc;
404
+ Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
405
+
406
+ if (TYPE(bool) == T_FALSE) {
407
+ rxpc->ctxt->replaceEntities = 0;
408
+ return(Qfalse);
409
+ } else {
410
+ rxpc->ctxt->replaceEntities = 1;
411
+ return(Qfalse);
412
+ }
413
+ }
414
+
415
+ /*
416
+ * call-seq:
417
+ * context.space_depth -> num
418
+ *
419
+ * Obtain the space depth for this context.
420
+ */
421
+ VALUE
422
+ ruby_xml_parser_context_space_depth_get(VALUE self) {
423
+ ruby_xml_parser_context *rxpc;
424
+ Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
425
+
426
+ return(INT2NUM(rxpc->ctxt->spaceNr));
427
+ }
428
+
429
+
430
+ /*
431
+ * call-seq:
432
+ * context.space_depth -> num
433
+ *
434
+ * Obtain the maximum space depth for this context.
435
+ */
436
+ VALUE
437
+ ruby_xml_parser_context_space_depth_max_get(VALUE self) {
438
+ ruby_xml_parser_context *rxpc;
439
+ Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
440
+
441
+ return(INT2NUM(rxpc->ctxt->spaceMax));
442
+ }
443
+
444
+
445
+ /*
446
+ * call-seq:
447
+ * context.subset_external? -> (true|false)
448
+ *
449
+ * Determine whether this context is a subset of an
450
+ * external context.
451
+ */
452
+ VALUE
453
+ ruby_xml_parser_context_subset_external_q(VALUE self) {
454
+ ruby_xml_parser_context *rxpc;
455
+ Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
456
+
457
+ if (rxpc->ctxt->inSubset == 2)
458
+ return(Qtrue);
459
+ else
460
+ return(Qfalse);
461
+ }
462
+
463
+
464
+ /*
465
+ * call-seq:
466
+ * context.subset_internal? -> (true|false)
467
+ *
468
+ * Determine whether this context is a subset of an
469
+ * internal context.
470
+ */
471
+ VALUE
472
+ ruby_xml_parser_context_subset_internal_q(VALUE self) {
473
+ ruby_xml_parser_context *rxpc;
474
+ Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
475
+
476
+ if (rxpc->ctxt->inSubset == 1)
477
+ return(Qtrue);
478
+ else
479
+ return(Qfalse);
480
+ }
481
+
482
+
483
+ /*
484
+ * call-seq:
485
+ * context.subset_name -> "name"
486
+ *
487
+ * Obtain this context's subset name (valid only if
488
+ * either of subset_external? or subset_internal?
489
+ * is true).
490
+ */
491
+ VALUE
492
+ ruby_xml_parser_context_subset_name_get(VALUE self) {
493
+ ruby_xml_parser_context *rxpc;
494
+ Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
495
+
496
+ if (rxpc->ctxt->intSubName == NULL)
497
+ return(Qnil);
498
+ else
499
+ return(rb_str_new2((const char*)rxpc->ctxt->intSubName));
500
+ }
501
+
502
+
503
+ /*
504
+ * call-seq:
505
+ * context.subset_external_uri -> "uri"
506
+ *
507
+ * Obtain this context's external subset URI. (valid only if
508
+ * either of subset_external? or subset_internal?
509
+ * is true).
510
+ */
511
+ VALUE
512
+ ruby_xml_parser_context_subset_external_uri_get(VALUE self) {
513
+ ruby_xml_parser_context *rxpc;
514
+ Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
515
+
516
+ if (rxpc->ctxt->extSubURI == NULL)
517
+ return(Qnil);
518
+ else
519
+ return(rb_str_new2((const char*)rxpc->ctxt->extSubURI));
520
+ }
521
+
522
+
523
+ /*
524
+ * call-seq:
525
+ * context.subset_external_system_id -> "system_id"
526
+ *
527
+ * Obtain this context's external subset system identifier.
528
+ * (valid only if either of subset_external? or subset_internal?
529
+ * is true).
530
+ */
531
+ VALUE
532
+ ruby_xml_parser_context_subset_external_system_id_get(VALUE self) {
533
+ ruby_xml_parser_context *rxpc;
534
+ Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
535
+
536
+ if (rxpc->ctxt->extSubSystem == NULL)
537
+ return(Qnil);
538
+ else
539
+ return(rb_str_new2((const char*)rxpc->ctxt->extSubSystem));
540
+ }
541
+
542
+
543
+ /*
544
+ * call-seq:
545
+ * context.standalone? -> (true|false)
546
+ *
547
+ * Determine whether this is a standalone context.
548
+ */
549
+ VALUE
550
+ ruby_xml_parser_context_standalone_q(VALUE self) {
551
+ ruby_xml_parser_context *rxpc;
552
+ Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
553
+
554
+ if (rxpc->ctxt->standalone)
555
+ return(Qtrue);
556
+ else
557
+ return(Qfalse);
558
+ }
559
+
560
+
561
+ /*
562
+ * call-seq:
563
+ * context.stats? -> (true|false)
564
+ *
565
+ * Determine whether this context maintains statistics.
566
+ */
567
+ VALUE
568
+ ruby_xml_parser_context_stats_q(VALUE self) {
569
+ ruby_xml_parser_context *rxpc;
570
+ Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
571
+
572
+ if (rxpc->ctxt->record_info)
573
+ return(Qtrue);
574
+ else
575
+ return(Qfalse);
576
+ }
577
+
578
+
579
+ /*
580
+ * call-seq:
581
+ * context.valid? -> (true|false)
582
+ *
583
+ * Determine whether this context is valid.
584
+ */
585
+ VALUE
586
+ ruby_xml_parser_context_valid_q(VALUE self) {
587
+ ruby_xml_parser_context *rxpc;
588
+ Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
589
+
590
+ if (rxpc->ctxt->valid)
591
+ return(Qtrue);
592
+ else
593
+ return(Qfalse);
594
+ }
595
+
596
+
597
+ /*
598
+ * call-seq:
599
+ * context.validate? -> (true|false)
600
+ *
601
+ * Determine whether validation is enabled in this context.
602
+ */
603
+ VALUE
604
+ ruby_xml_parser_context_validate_q(VALUE self) {
605
+ ruby_xml_parser_context *rxpc;
606
+ Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
607
+
608
+ if (rxpc->ctxt->validate)
609
+ return(Qtrue);
610
+ else
611
+ return(Qfalse);
612
+ }
613
+
614
+
615
+ /*
616
+ * call-seq:
617
+ * context.version -> "version"
618
+ *
619
+ * Obtain this context's version identifier.
620
+ */
621
+ VALUE
622
+ ruby_xml_parser_context_version_get(VALUE self) {
623
+ ruby_xml_parser_context *rxpc;
624
+ Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
625
+
626
+ if (rxpc->ctxt->version == NULL)
627
+ return(Qnil);
628
+ else
629
+ return(rb_str_new2((const char*)rxpc->ctxt->version));
630
+ }
631
+
632
+
633
+ /*
634
+ * call-seq:
635
+ * context.well_formed? -> (true|false)
636
+ *
637
+ * Determine whether this context contains well-formed XML.
638
+ */
639
+ VALUE
640
+ ruby_xml_parser_context_well_formed_q(VALUE self) {
641
+ ruby_xml_parser_context *rxpc;
642
+ Data_Get_Struct(self, ruby_xml_parser_context, rxpc);
643
+
644
+ if (rxpc->ctxt->wellFormed)
645
+ return(Qtrue);
646
+ else
647
+ return(Qfalse);
648
+ }
649
+
650
+
651
+ // Rdoc needs to know
652
+ #ifdef RDOC_NEVER_DEFINED
653
+ mLibXML = rb_define_module("LibXML");
654
+ mXML = rb_define_module_under(mLibXML, "XML");
655
+ cXMLParser = rb_define_class_under(mXML, "Parser", rb_cObject);
656
+ #endif
657
+
658
+ void
659
+ ruby_init_xml_parser_context(void) {
660
+ cXMLParserContext = rb_define_class_under(cXMLParser, "Context", rb_cObject);
661
+
662
+ rb_define_method(cXMLParserContext, "data_directory", ruby_xml_parser_context_data_directory_get, 0);
663
+ rb_define_method(cXMLParserContext, "depth", ruby_xml_parser_context_depth_get, 0);
664
+ rb_define_method(cXMLParserContext, "disable_sax?", ruby_xml_parser_context_disable_sax_q, 0);
665
+ rb_define_method(cXMLParserContext, "docbook?", ruby_xml_parser_context_docbook_q, 0);
666
+ rb_define_method(cXMLParserContext, "encoding", ruby_xml_parser_context_encoding_get, 0);
667
+ rb_define_method(cXMLParserContext, "errno", ruby_xml_parser_context_errno_get, 0);
668
+ rb_define_method(cXMLParserContext, "html?", ruby_xml_parser_context_html_q, 0);
669
+ rb_define_method(cXMLParserContext, "io_max_num_streams", ruby_xml_parser_context_io_max_num_streams_get, 0);
670
+ rb_define_method(cXMLParserContext, "io_num_streams", ruby_xml_parser_context_io_num_streams_get, 0);
671
+ rb_define_method(cXMLParserContext, "keep_blanks?", ruby_xml_parser_context_keep_blanks_q, 0);
672
+ rb_define_method(cXMLParserContext, "name_node", ruby_xml_parser_context_name_node_get, 0);
673
+ rb_define_method(cXMLParserContext, "name_depth", ruby_xml_parser_context_name_depth_get, 0);
674
+ rb_define_method(cXMLParserContext, "name_depth_max", ruby_xml_parser_context_name_depth_max_get, 0);
675
+ rb_define_method(cXMLParserContext, "name_tab", ruby_xml_parser_context_name_tab_get, 0);
676
+ rb_define_method(cXMLParserContext, "node", ruby_xml_parser_context_node_get, 0);
677
+ rb_define_method(cXMLParserContext, "node_depth", ruby_xml_parser_context_node_depth_get, 0);
678
+ rb_define_method(cXMLParserContext, "node_depth_max", ruby_xml_parser_context_node_depth_max_get, 0);
679
+ rb_define_method(cXMLParserContext, "num_chars", ruby_xml_parser_context_num_chars_get, 0);
680
+ rb_define_method(cXMLParserContext, "options", ruby_xml_parser_context_options_get, 0);
681
+ rb_define_method(cXMLParserContext, "options=", ruby_xml_parser_context_options_set, 1);
682
+ rb_define_method(cXMLParserContext, "replace_entities?", ruby_xml_parser_context_replace_entities_q, 0);
683
+ rb_define_method(cXMLParserContext, "replace_entities=", ruby_xml_parser_context_replace_entities_set, 1);
684
+ rb_define_method(cXMLParserContext, "space_depth", ruby_xml_parser_context_space_depth_get, 0);
685
+ rb_define_method(cXMLParserContext, "space_depth_max", ruby_xml_parser_context_space_depth_max_get, 0);
686
+ rb_define_method(cXMLParserContext, "subset_external?", ruby_xml_parser_context_subset_external_q, 0);
687
+ rb_define_method(cXMLParserContext, "subset_external_system_id", ruby_xml_parser_context_subset_external_system_id_get, 0);
688
+ rb_define_method(cXMLParserContext, "subset_external_uri", ruby_xml_parser_context_subset_name_get, 0);
689
+ rb_define_method(cXMLParserContext, "subset_internal?", ruby_xml_parser_context_subset_internal_q, 0);
690
+ rb_define_method(cXMLParserContext, "subset_internal_name", ruby_xml_parser_context_subset_name_get, 0);
691
+ rb_define_method(cXMLParserContext, "stats?", ruby_xml_parser_context_stats_q, 0);
692
+ rb_define_method(cXMLParserContext, "standalone?", ruby_xml_parser_context_standalone_q, 0);
693
+ rb_define_method(cXMLParserContext, "valid", ruby_xml_parser_context_valid_q, 0);
694
+ rb_define_method(cXMLParserContext, "validate?", ruby_xml_parser_context_validate_q, 0);
695
+ rb_define_method(cXMLParserContext, "version", ruby_xml_parser_context_version_get, 0);
696
+ rb_define_method(cXMLParserContext, "well_formed?", ruby_xml_parser_context_well_formed_q, 0);
697
+ }