libxml-ruby 0.8.3-x86-mswin32-60 → 0.9.0-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 (175) hide show
  1. data/CHANGES +18 -0
  2. data/RAKEFILE +15 -39
  3. data/README +48 -47
  4. data/ext/libxml/libxml.c +847 -22
  5. data/ext/libxml/ruby_libxml.h +71 -95
  6. data/ext/libxml/ruby_xml_attr.c +500 -500
  7. data/ext/libxml/ruby_xml_attributes.c +1 -1
  8. data/ext/libxml/ruby_xml_document.c +1144 -1135
  9. data/ext/libxml/ruby_xml_document.h +4 -11
  10. data/ext/libxml/ruby_xml_dtd.c +27 -0
  11. data/ext/libxml/ruby_xml_encoding.c +164 -0
  12. data/ext/libxml/ruby_xml_encoding.h +13 -0
  13. data/ext/libxml/ruby_xml_error.c +941 -0
  14. data/ext/libxml/ruby_xml_error.h +13 -0
  15. data/ext/libxml/ruby_xml_html_parser.c +71 -387
  16. data/ext/libxml/ruby_xml_html_parser.h +1 -17
  17. data/ext/libxml/ruby_xml_input.c +179 -0
  18. data/ext/libxml/ruby_xml_input.h +18 -0
  19. data/ext/libxml/ruby_xml_input_cbg.c +17 -3
  20. data/ext/libxml/ruby_xml_node.c +1566 -1582
  21. data/ext/libxml/ruby_xml_node.h +1 -4
  22. data/ext/libxml/ruby_xml_ns.c +14 -3
  23. data/ext/libxml/ruby_xml_parser.c +164 -1398
  24. data/ext/libxml/ruby_xml_parser.h +5 -17
  25. data/ext/libxml/ruby_xml_parser_context.c +131 -169
  26. data/ext/libxml/ruby_xml_parser_context.h +2 -9
  27. data/ext/libxml/ruby_xml_reader.c +910 -945
  28. data/ext/libxml/ruby_xml_relaxng.c +32 -3
  29. data/ext/libxml/ruby_xml_sax_parser.c +106 -364
  30. data/ext/libxml/ruby_xml_sax_parser.h +1 -37
  31. data/ext/libxml/ruby_xml_schema.c +174 -145
  32. data/ext/libxml/ruby_xml_xinclude.c +9 -5
  33. data/ext/libxml/ruby_xml_xpath.c +25 -6
  34. data/ext/libxml/ruby_xml_xpath.h +1 -2
  35. data/ext/libxml/ruby_xml_xpath_context.c +17 -19
  36. data/ext/libxml/ruby_xml_xpath_object.c +60 -56
  37. data/ext/libxml/ruby_xml_xpointer.c +11 -5
  38. data/ext/libxml/sax_parser_callbacks.inc +42 -37
  39. data/ext/libxml/version.h +3 -3
  40. data/ext/mingw/Rakefile +20 -27
  41. data/ext/mingw/build.rake +41 -0
  42. data/{lib → ext/mingw}/libiconv-2.dll +0 -0
  43. data/ext/mingw/libxml2-2.dll +0 -0
  44. data/ext/mingw/libxml_ruby.dll.a +0 -0
  45. data/ext/mingw/libxml_ruby.so +0 -0
  46. data/ext/vc/libxml_ruby.vcproj +23 -15
  47. data/lib/libxml.rb +8 -2
  48. data/lib/libxml/document.rb +16 -4
  49. data/lib/libxml/error.rb +84 -0
  50. data/lib/libxml/hpricot.rb +76 -0
  51. data/lib/libxml/html_parser.rb +61 -0
  52. data/lib/libxml/node.rb +36 -25
  53. data/lib/libxml/parser.rb +312 -33
  54. data/lib/libxml/parser_context.rb +17 -0
  55. data/lib/libxml/properties.rb +15 -2
  56. data/lib/libxml/reader.rb +15 -0
  57. data/lib/libxml/sax_callbacks.rb +179 -0
  58. data/lib/libxml/sax_parser.rb +42 -0
  59. data/lib/libxml/tree.rb +1 -2
  60. data/lib/libxml/xpath_object.rb +12 -0
  61. data/test/model/atom.xml +4 -0
  62. data/test/tc_attributes.rb +43 -19
  63. data/test/tc_document.rb +1 -1
  64. data/test/tc_document_write.rb +15 -8
  65. data/test/tc_dtd.rb +36 -20
  66. data/test/tc_encoding.rb +13 -0
  67. data/test/tc_error.rb +136 -0
  68. data/test/tc_node.rb +2 -3
  69. data/test/tc_node_copy.rb +1 -1
  70. data/test/tc_node_edit.rb +6 -0
  71. data/test/tc_ns.rb +18 -0
  72. data/test/tc_parser.rb +113 -228
  73. data/test/tc_parser_context.rb +1 -2
  74. data/test/tc_reader.rb +24 -14
  75. data/test/tc_relaxng.rb +18 -6
  76. data/test/tc_sax_parser.rb +48 -13
  77. data/test/tc_schema.rb +20 -8
  78. data/test/tc_well_formed.rb +2 -1
  79. data/test/tc_xml.rb +212 -0
  80. data/test/tc_xpath.rb +60 -46
  81. data/test/tc_xpointer.rb +7 -11
  82. data/test/test_suite.rb +4 -3
  83. metadata +32 -115
  84. data/doc/rdoc/classes/LibXML.html +0 -241
  85. data/doc/rdoc/classes/LibXML/XML.html +0 -185
  86. data/doc/rdoc/classes/LibXML/XML/Attr.html +0 -1010
  87. data/doc/rdoc/classes/LibXML/XML/Attributes.html +0 -526
  88. data/doc/rdoc/classes/LibXML/XML/Document.html +0 -1489
  89. data/doc/rdoc/classes/LibXML/XML/Dtd.html +0 -213
  90. data/doc/rdoc/classes/LibXML/XML/Error.html +0 -117
  91. data/doc/rdoc/classes/LibXML/XML/HTMLParser.html +0 -348
  92. data/doc/rdoc/classes/LibXML/XML/InputCallbacks.html +0 -160
  93. data/doc/rdoc/classes/LibXML/XML/NS.html +0 -381
  94. data/doc/rdoc/classes/LibXML/XML/Node.html +0 -3396
  95. data/doc/rdoc/classes/LibXML/XML/Node/FailedModify.html +0 -123
  96. data/doc/rdoc/classes/LibXML/XML/Node/Set.html +0 -440
  97. data/doc/rdoc/classes/LibXML/XML/Node/SetNamespace.html +0 -123
  98. data/doc/rdoc/classes/LibXML/XML/Node/UnknownType.html +0 -123
  99. data/doc/rdoc/classes/LibXML/XML/Parser.html +0 -2239
  100. data/doc/rdoc/classes/LibXML/XML/Parser/Context.html +0 -1255
  101. data/doc/rdoc/classes/LibXML/XML/Parser/ParseError.html +0 -123
  102. data/doc/rdoc/classes/LibXML/XML/Reader.html +0 -2264
  103. data/doc/rdoc/classes/LibXML/XML/RelaxNG.html +0 -237
  104. data/doc/rdoc/classes/LibXML/XML/SaxParser.html +0 -415
  105. data/doc/rdoc/classes/LibXML/XML/Schema.html +0 -308
  106. data/doc/rdoc/classes/LibXML/XML/State.html +0 -124
  107. data/doc/rdoc/classes/LibXML/XML/Tree.html +0 -111
  108. data/doc/rdoc/classes/LibXML/XML/XInclude.html +0 -123
  109. data/doc/rdoc/classes/LibXML/XML/XInclude/Error.html +0 -117
  110. data/doc/rdoc/classes/LibXML/XML/XMLParserOptions.html +0 -198
  111. data/doc/rdoc/classes/LibXML/XML/XPath.html +0 -184
  112. data/doc/rdoc/classes/LibXML/XML/XPath/Context.html +0 -404
  113. data/doc/rdoc/classes/LibXML/XML/XPath/InvalidPath.html +0 -172
  114. data/doc/rdoc/classes/LibXML/XML/XPath/Object.html +0 -627
  115. data/doc/rdoc/classes/LibXML/XML/XPointer.html +0 -170
  116. data/doc/rdoc/classes/LibXML/XML/XPointer/Context.html +0 -123
  117. data/doc/rdoc/classes/LibXML/XML/XPointer/Context/InvalidPath.html +0 -117
  118. data/doc/rdoc/classes/LibXML/XML/XPointer/InvalidExpression.html +0 -124
  119. data/doc/rdoc/classes/singleton.html +0 -114
  120. data/doc/rdoc/created.rid +0 -1
  121. data/doc/rdoc/files/CHANGES.html +0 -442
  122. data/doc/rdoc/files/LICENSE.html +0 -133
  123. data/doc/rdoc/files/README.html +0 -388
  124. data/doc/rdoc/files/VERSION.html +0 -107
  125. data/doc/rdoc/files/ext/libxml/cbg_c.html +0 -101
  126. data/doc/rdoc/files/ext/libxml/libxml_c.html +0 -101
  127. data/doc/rdoc/files/ext/libxml/ruby_xml_attr_c.html +0 -101
  128. data/doc/rdoc/files/ext/libxml/ruby_xml_attributes_c.html +0 -101
  129. data/doc/rdoc/files/ext/libxml/ruby_xml_document_c.html +0 -101
  130. data/doc/rdoc/files/ext/libxml/ruby_xml_dtd_c.html +0 -101
  131. data/doc/rdoc/files/ext/libxml/ruby_xml_html_parser_c.html +0 -101
  132. data/doc/rdoc/files/ext/libxml/ruby_xml_input_cbg_c.html +0 -101
  133. data/doc/rdoc/files/ext/libxml/ruby_xml_node_c.html +0 -101
  134. data/doc/rdoc/files/ext/libxml/ruby_xml_node_set_c.html +0 -101
  135. data/doc/rdoc/files/ext/libxml/ruby_xml_ns_c.html +0 -101
  136. data/doc/rdoc/files/ext/libxml/ruby_xml_parser_c.html +0 -101
  137. data/doc/rdoc/files/ext/libxml/ruby_xml_parser_context_c.html +0 -101
  138. data/doc/rdoc/files/ext/libxml/ruby_xml_reader_c.html +0 -101
  139. data/doc/rdoc/files/ext/libxml/ruby_xml_relaxng_c.html +0 -101
  140. data/doc/rdoc/files/ext/libxml/ruby_xml_sax_parser_c.html +0 -101
  141. data/doc/rdoc/files/ext/libxml/ruby_xml_schema_c.html +0 -101
  142. data/doc/rdoc/files/ext/libxml/ruby_xml_state_c.html +0 -101
  143. data/doc/rdoc/files/ext/libxml/ruby_xml_xinclude_c.html +0 -101
  144. data/doc/rdoc/files/ext/libxml/ruby_xml_xpath_c.html +0 -101
  145. data/doc/rdoc/files/ext/libxml/ruby_xml_xpath_context_c.html +0 -101
  146. data/doc/rdoc/files/ext/libxml/ruby_xml_xpath_object_c.html +0 -101
  147. data/doc/rdoc/files/ext/libxml/ruby_xml_xpointer_c.html +0 -101
  148. data/doc/rdoc/files/ext/libxml/ruby_xml_xpointer_context_c.html +0 -101
  149. data/doc/rdoc/files/lib/libxml/attr_rb.html +0 -108
  150. data/doc/rdoc/files/lib/libxml/attributes_rb.html +0 -108
  151. data/doc/rdoc/files/lib/libxml/document_rb.html +0 -108
  152. data/doc/rdoc/files/lib/libxml/node_rb.html +0 -108
  153. data/doc/rdoc/files/lib/libxml/node_set_rb.html +0 -108
  154. data/doc/rdoc/files/lib/libxml/parser_options_rb.html +0 -107
  155. data/doc/rdoc/files/lib/libxml/parser_rb.html +0 -101
  156. data/doc/rdoc/files/lib/libxml/properties_rb.html +0 -108
  157. data/doc/rdoc/files/lib/libxml/tree_rb.html +0 -107
  158. data/doc/rdoc/files/lib/libxml_rb.html +0 -124
  159. data/doc/rdoc/files/lib/xml/libxml_rb.html +0 -124
  160. data/doc/rdoc/files/lib/xml_rb.html +0 -134
  161. data/doc/rdoc/fr_class_index.html +0 -62
  162. data/doc/rdoc/fr_file_index.html +0 -66
  163. data/doc/rdoc/fr_method_index.html +0 -392
  164. data/doc/rdoc/index.html +0 -24
  165. data/doc/rdoc/rdoc-style.css +0 -208
  166. data/ext/libxml/ruby_xml_node_set.c +0 -172
  167. data/ext/libxml/ruby_xml_node_set.h +0 -20
  168. data/ext/libxml/ruby_xml_xpointer_context.c +0 -22
  169. data/ext/libxml/ruby_xml_xpointer_context.h +0 -18
  170. data/lib/libxml/node_set.rb +0 -27
  171. data/lib/libxml2-2.dll +0 -0
  172. data/lib/libxml_ruby.dll.a +0 -0
  173. data/lib/libxml_ruby.so +0 -0
  174. data/test/tc_node_set.rb +0 -24
  175. data/test/tc_node_set2.rb +0 -37
@@ -1,4 +1,4 @@
1
- /* $Id: ruby_xml_node.h 348 2008-07-09 18:18:19Z cfis $ */
1
+ /* $Id: ruby_xml_node.h 553 2008-11-18 02:34:38Z cfis $ */
2
2
 
3
3
  /* Please see the LICENSE file for copyright and distribution information */
4
4
 
@@ -6,9 +6,6 @@
6
6
  #define __RUBY_XML_NODE__
7
7
 
8
8
  extern VALUE cXMLNode;
9
- extern VALUE eXMLNodeSetNamespace;
10
- extern VALUE eXMLNodeFailedModify;
11
- extern VALUE eXMLNodeUnknownType;
12
9
 
13
10
  void ruby_init_xml_node(void);
14
11
  void ruby_xml_node_mark_common(xmlNodePtr xnode);
@@ -1,4 +1,4 @@
1
- /* $Id: ruby_xml_ns.c 461 2008-07-15 21:35:56Z cfis $ */
1
+ /* $Id: ruby_xml_ns.c 553 2008-11-18 02:34:38Z cfis $ */
2
2
 
3
3
  /* Please see the LICENSE file for copyright and distribution information */
4
4
 
@@ -8,6 +8,14 @@
8
8
  VALUE cXMLNS;
9
9
 
10
10
 
11
+ /* Document-class: LibXML::XML::NS
12
+ *
13
+ * The NS class is used to query information about
14
+ * xml namespaces associated with particular nodes.
15
+ * It can also be used to associate new namespaces
16
+ * with an node. */
17
+
18
+
11
19
  VALUE
12
20
  ruby_xml_ns_alloc(VALUE klass) {
13
21
  return Data_Wrap_Struct(cXMLNS, NULL, NULL, NULL);
@@ -25,10 +33,13 @@ ruby_xml_ns_alloc(VALUE klass) {
25
33
  VALUE
26
34
  ruby_xml_ns_initialize(VALUE self, VALUE node, VALUE href, VALUE prefix) {
27
35
  xmlNodePtr xnode;
28
- xmlNsPtr xns;
36
+ xmlChar *xmlPrefix;
37
+ xmlNsPtr xns;
29
38
 
30
39
  Data_Get_Struct(node, xmlNode, xnode);
31
- xns = xmlNewNs(xnode, (xmlChar*)StringValuePtr(href), (xmlChar*)StringValuePtr(prefix));
40
+ /* Prefix can be null - that means its the default namespace */
41
+ xmlPrefix = NIL_P(prefix) ? NULL : StringValuePtr(prefix);
42
+ xns = xmlNewNs(xnode, (xmlChar*)StringValuePtr(href), xmlPrefix);
32
43
 
33
44
  DATA_PTR(self) = xns;
34
45
  return self;
@@ -1,1398 +1,164 @@
1
- /* $Id: ruby_xml_parser.c 461 2008-07-15 21:35:56Z cfis $ */
2
-
3
- /* Please see the LICENSE file for copyright and distribution information */
4
-
5
- #include <stdarg.h>
6
- #include "ruby_libxml.h"
7
-
8
- static int id_call;
9
-
10
- VALUE cXMLParser;
11
- VALUE eXMLParserParseError;
12
-
13
- static int
14
- ctxtRead(FILE *f, char * buf, size_t len) {
15
- return(fread(buf, 1, len, f));
16
- }
17
-
18
- /*
19
- * call-seq:
20
- * XML::Parser.catalog_dump -> true
21
- *
22
- * Dump the parser resource catalogs to stdout.
23
- */
24
- VALUE
25
- ruby_xml_parser_catalog_dump(VALUE self) {
26
- xmlCatalogDump(stdout);
27
- return(Qtrue);
28
- }
29
-
30
-
31
- /*
32
- * call-seq:
33
- * XML::Parser.catalog_remove(catalog) -> true
34
- *
35
- * Remove the specified resource catalog.
36
- */
37
- VALUE
38
- ruby_xml_parser_catalog_remove(VALUE self, VALUE cat) {
39
- Check_Type(cat, T_STRING);
40
- xmlCatalogRemove((xmlChar *)StringValuePtr(cat));
41
- return(Qtrue);
42
- }
43
-
44
-
45
- /*
46
- * call-seq:
47
- * XML::Parser.check_lib_versions -> true
48
- *
49
- * Check LIBXML version matches version the bindings
50
- * were compiled to. Throws an exception if not.
51
- */
52
- VALUE
53
- ruby_xml_parser_check_lib_versions(VALUE class) {
54
- xmlCheckVersion(LIBXML_VERSION);
55
- return(Qtrue);
56
- }
57
-
58
-
59
- /*
60
- * call-seq:
61
- * XML::Parser.enabled_automata? -> (true|false)
62
- *
63
- * Determine whether libxml regexp automata support is enabled.
64
- */
65
- VALUE
66
- ruby_xml_parser_enabled_automata_q(VALUE class) {
67
- #ifdef LIBXML_AUTOMATA_ENABLED
68
- return(Qtrue);
69
- #else
70
- return(Qfalse);
71
- #endif
72
- }
73
-
74
-
75
- /*
76
- * call-seq:
77
- * XML::Parser.enabled_c14n? -> (true|false)
78
- *
79
- * Determine whether libxml 'canonical XML' support is enabled.
80
- * See "Canonical XML" (http://www.w3.org/TR/xml-c14n)
81
- */
82
- VALUE
83
- ruby_xml_parser_enabled_c14n_q(VALUE class) {
84
- #ifdef LIBXML_C14N_ENABLED
85
- return(Qtrue);
86
- #else
87
- return(Qfalse);
88
- #endif
89
- }
90
-
91
-
92
- /*
93
- * call-seq:
94
- * XML::Parser.enabled_catalog? -> (true|false)
95
- *
96
- * Determine whether libxml resource catalog support is enabled.
97
- */
98
- VALUE
99
- ruby_xml_parser_enabled_catalog_q(VALUE class) {
100
- #ifdef LIBXML_CATALOG_ENABLED
101
- return(Qtrue);
102
- #else
103
- return(Qfalse);
104
- #endif
105
- }
106
-
107
-
108
- /*
109
- * call-seq:
110
- * XML::Parser.enabled_debug? -> (true|false)
111
- *
112
- * Determine whether libxml debugging support is enabled.
113
- */
114
- VALUE
115
- ruby_xml_parser_enabled_debug_q(VALUE class) {
116
- #ifdef LIBXML_DEBUG_ENABLED
117
- return(Qtrue);
118
- #else
119
- return(Qfalse);
120
- #endif
121
- }
122
-
123
-
124
- /*
125
- * call-seq:
126
- * XML::Parser.enabled_docbook? -> (true|false)
127
- *
128
- * Determine whether libxml docbook support is enabled.
129
- */
130
- VALUE
131
- ruby_xml_parser_enabled_docbook_q(VALUE class) {
132
- #ifdef LIBXML_DOCB_ENABLED
133
- return(Qtrue);
134
- #else
135
- return(Qfalse);
136
- #endif
137
- }
138
-
139
-
140
- /*
141
- * call-seq:
142
- * XML::Parser.enabled_ftp? -> (true|false)
143
- *
144
- * Determine whether libxml ftp client support is enabled.
145
- */
146
- VALUE
147
- ruby_xml_parser_enabled_ftp_q(VALUE class) {
148
- #ifdef LIBXML_FTP_ENABLED
149
- return(Qtrue);
150
- #else
151
- return(Qfalse);
152
- #endif
153
- }
154
-
155
-
156
- /*
157
- * call-seq:
158
- * XML::Parser.enabled_http? -> (true|false)
159
- *
160
- * Determine whether libxml http client support is enabled.
161
- */
162
- VALUE
163
- ruby_xml_parser_enabled_http_q(VALUE class) {
164
- #ifdef LIBXML_HTTP_ENABLED
165
- return(Qtrue);
166
- #else
167
- return(Qfalse);
168
- #endif
169
- }
170
-
171
-
172
- /*
173
- * call-seq:
174
- * XML::Parser.enabled_html? -> (true|false)
175
- *
176
- * Determine whether libxml html support is enabled.
177
- */
178
- VALUE
179
- ruby_xml_parser_enabled_html_q(VALUE class) {
180
- #ifdef LIBXML_HTML_ENABLED
181
- return(Qtrue);
182
- #else
183
- return(Qfalse);
184
- #endif
185
- }
186
-
187
-
188
- /*
189
- * call-seq:
190
- * XML::Parser.enabled_iconv? -> (true|false)
191
- *
192
- * Determine whether libxml iconv support is enabled.
193
- */
194
- VALUE
195
- ruby_xml_parser_enabled_iconv_q(VALUE class) {
196
- #ifdef LIBXML_ICONV_ENABLED
197
- return(Qtrue);
198
- #else
199
- return(Qfalse);
200
- #endif
201
- }
202
-
203
-
204
- /*
205
- * call-seq:
206
- * XML::Parser.enabled_memory_debug? -> (true|false)
207
- *
208
- * Determine whether libxml memory location debugging support
209
- * is enabled.
210
- */
211
- VALUE
212
- ruby_xml_parser_enabled_memory_debug_location_q(VALUE class) {
213
- #ifdef DEBUG_MEMORY_LOCATION
214
- return(Qtrue);
215
- #else
216
- return(Qfalse);
217
- #endif
218
- }
219
-
220
-
221
- /*
222
- * call-seq:
223
- * XML::Parser.enabled_regexp? -> (true|false)
224
- *
225
- * Determine whether libxml regular expression support is enabled.
226
- */
227
- VALUE
228
- ruby_xml_parser_enabled_regexp_q(VALUE class) {
229
- #ifdef LIBXML_REGEXP_ENABLED
230
- return(Qtrue);
231
- #else
232
- return(Qfalse);
233
- #endif
234
- }
235
-
236
-
237
- /*
238
- * call-seq:
239
- * XML::Parser.enabled_schemas? -> (true|false)
240
- *
241
- * Determine whether libxml schema support is enabled.
242
- */
243
- VALUE
244
- ruby_xml_parser_enabled_schemas_q(VALUE class) {
245
- #ifdef LIBXML_SCHEMAS_ENABLED
246
- return(Qtrue);
247
- #else
248
- return(Qfalse);
249
- #endif
250
- }
251
-
252
-
253
- /*
254
- * call-seq:
255
- * XML::Parser.enabled_thread? -> (true|false)
256
- *
257
- * Determine whether libxml thread-safe semantics support
258
- * is enabled (I think?).
259
- */
260
- VALUE
261
- ruby_xml_parser_enabled_thread_q(VALUE class) {
262
- #ifdef LIBXML_THREAD_ENABLED
263
- return(Qtrue);
264
- #else
265
- return(Qfalse);
266
- #endif
267
- }
268
-
269
-
270
- /*
271
- * call-seq:
272
- * XML::Parser.enabled_unicode? -> (true|false)
273
- *
274
- * Determine whether libxml unicode support is enabled.
275
- */
276
- VALUE
277
- ruby_xml_parser_enabled_unicode_q(VALUE class) {
278
- #ifdef LIBXML_UNICODE_ENABLED
279
- return(Qtrue);
280
- #else
281
- return(Qfalse);
282
- #endif
283
- }
284
-
285
-
286
- /*
287
- * call-seq:
288
- * XML::Parser.enabled_xinclude? -> (true|false)
289
- *
290
- * Determine whether libxml xinclude support is enabled.
291
- */
292
- VALUE
293
- ruby_xml_parser_enabled_xinclude_q(VALUE class) {
294
- #ifdef LIBXML_XINCLUDE_ENABLED
295
- return(Qtrue);
296
- #else
297
- return(Qfalse);
298
- #endif
299
- }
300
-
301
-
302
- /*
303
- * call-seq:
304
- * XML::Parser.enabled_xpath? -> (true|false)
305
- *
306
- * Determine whether libxml xpath support is enabled.
307
- */
308
- VALUE
309
- ruby_xml_parser_enabled_xpath_q(VALUE class) {
310
- #ifdef LIBXML_XPATH_ENABLED
311
- return(Qtrue);
312
- #else
313
- return(Qfalse);
314
- #endif
315
- }
316
-
317
-
318
- /*
319
- * call-seq:
320
- * XML::Parser.enabled_xpointer? -> (true|false)
321
- *
322
- * Determine whether libxml xpointer support is enabled.
323
- */
324
- VALUE
325
- ruby_xml_parser_enabled_xpointer_q(VALUE class) {
326
- #ifdef LIBXML_XPTR_ENABLED
327
- return(Qtrue);
328
- #else
329
- return(Qfalse);
330
- #endif
331
- }
332
-
333
-
334
- /*
335
- * call-seq:
336
- * XML::Parser.enabled_zlib? -> (true|false)
337
- *
338
- * Determine whether libxml zlib support is enabled.
339
- */
340
- VALUE
341
- ruby_xml_parser_enabled_zlib_q(VALUE class) {
342
- #ifdef HAVE_ZLIB_H
343
- return(Qtrue);
344
- #else
345
- return(Qfalse);
346
- #endif
347
- }
348
-
349
-
350
- /*
351
- * call-seq:
352
- * XML::Parser.debug_entities -> (true|false)
353
- *
354
- * Determine whether included-entity debugging is enabled.
355
- * (Requires Libxml to be compiled with debugging support)
356
- */
357
- VALUE
358
- ruby_xml_parser_debug_entities_get(VALUE class) {
359
- #ifdef LIBXML_DEBUG_ENABLED
360
- if (xmlParserDebugEntities)
361
- return(Qtrue);
362
- else
363
- return(Qfalse);
364
- #else
365
- rb_warn("libxml was compiled with debugging turned off");
366
- return(Qfalse);
367
- #endif
368
- }
369
-
370
-
371
- /*
372
- * call-seq:
373
- * XML::Parser.debug_entities = true|false
374
- *
375
- * Enable or disable included-entity debugging.
376
- * (Requires Libxml to be compiled with debugging support)
377
- */
378
- VALUE
379
- ruby_xml_parser_debug_entities_set(VALUE class, VALUE bool) {
380
- #ifdef LIBXML_DEBUG_ENABLED
381
- if (TYPE(bool) == T_FALSE) {
382
- xmlParserDebugEntities = 0;
383
- return(Qfalse);
384
- } else {
385
- xmlParserDebugEntities = 1;
386
- return(Qtrue);
387
- }
388
- #else
389
- rb_warn("libxml was compiled with debugging turned off");
390
- #endif
391
- }
392
-
393
-
394
- /*
395
- * call-seq:
396
- * XML::Parser.default_keep_blanks -> (true|false)
397
- *
398
- * Determine whether parsers retain whitespace by default.
399
- */
400
- VALUE
401
- ruby_xml_parser_default_keep_blanks_get(VALUE class) {
402
- if (xmlKeepBlanksDefaultValue)
403
- return(Qtrue);
404
- else
405
- return(Qfalse);
406
- }
407
-
408
-
409
- /*
410
- * call-seq:
411
- * XML::Parser.default_keep_blanks = true|false
412
- *
413
- * Controls whether parsers retain whitespace by default.
414
- */
415
- VALUE
416
- ruby_xml_parser_default_keep_blanks_set(VALUE class, VALUE bool) {
417
- if (TYPE(bool) == T_FALSE) {
418
- xmlKeepBlanksDefaultValue = 0;
419
- return(Qfalse);
420
- } else if (TYPE(bool) == T_TRUE) {
421
- xmlKeepBlanksDefaultValue = 1;
422
- return(Qtrue);
423
- } else {
424
- rb_raise(rb_eArgError, "invalid argument, must be a boolean");
425
- }
426
- }
427
-
428
-
429
- /*
430
- * call-seq:
431
- * XML::Parser.default_load_external_dtd -> (true|false)
432
- *
433
- * Determine whether parsers load external DTDs by default.
434
- */
435
- VALUE
436
- ruby_xml_parser_default_load_external_dtd_get(VALUE class) {
437
- if (xmlLoadExtDtdDefaultValue)
438
- return(Qtrue);
439
- else
440
- return(Qfalse);
441
- }
442
-
443
-
444
- /*
445
- * call-seq:
446
- * XML::Parser.default_load_external_dtd = true|false
447
- *
448
- * Controls whether parsers load external DTDs by default.
449
- */
450
- VALUE
451
- ruby_xml_parser_default_load_external_dtd_set(VALUE class, VALUE bool) {
452
- if (TYPE(bool) == T_FALSE) {
453
- xmlLoadExtDtdDefaultValue = 0;
454
- return(Qfalse);
455
- } else {
456
- xmlLoadExtDtdDefaultValue = 1;
457
- return(Qtrue);
458
- }
459
- }
460
-
461
-
462
- /*
463
- * call-seq:
464
- * XML::Parser.default_line_numbers -> (true|false)
465
- *
466
- * Determine whether parsers retain line-numbers by default.
467
- */
468
- VALUE
469
- ruby_xml_parser_default_line_numbers_get(VALUE class) {
470
- if (xmlLineNumbersDefaultValue)
471
- return(Qtrue);
472
- else
473
- return(Qfalse);
474
- }
475
-
476
-
477
- /*
478
- * call-seq:
479
- * XML::Parser.default_line_numbers = true|false
480
- *
481
- * Controls whether parsers retain line-numbers by default.
482
- */
483
- VALUE
484
- ruby_xml_parser_default_line_numbers_set(VALUE class, VALUE bool) {
485
- if (TYPE(bool) == T_FALSE) {
486
- xmlLineNumbersDefault(0);
487
- return(Qfalse);
488
- } else {
489
- xmlLineNumbersDefault(1);
490
- return(Qtrue);
491
- }
492
- }
493
-
494
-
495
- /*
496
- * call-seq:
497
- * XML::Parser.default_pedantic_parser -> (true|false)
498
- *
499
- * Determine whether parsers are pedantic by default.
500
- */
501
- VALUE
502
- ruby_xml_parser_default_pedantic_parser_get(VALUE class) {
503
- if (xmlPedanticParserDefaultValue)
504
- return(Qtrue);
505
- else
506
- return(Qfalse);
507
- }
508
-
509
-
510
- /*
511
- * call-seq:
512
- * XML::Parser.default_pedantic_parser = true|false
513
- *
514
- * Controls whether parsers are pedantic by default.
515
- */
516
- VALUE
517
- ruby_xml_parser_default_pedantic_parser_set(VALUE class, VALUE bool) {
518
- if (TYPE(bool) == T_FALSE) {
519
- xmlPedanticParserDefault(0);
520
- return(Qfalse);
521
- } else {
522
- xmlPedanticParserDefault(1);
523
- return(Qtrue);
524
- }
525
- }
526
-
527
-
528
- /*
529
- * call-seq:
530
- * XML::Parser.default_substitute_entities -> (true|false)
531
- *
532
- * Determine whether parsers perform inline entity substitution
533
- * (for external entities) by default.
534
- */
535
- VALUE
536
- ruby_xml_parser_default_substitute_entities_get(VALUE class) {
537
- if (xmlSubstituteEntitiesDefaultValue)
538
- return(Qtrue);
539
- else
540
- return(Qfalse);
541
- }
542
-
543
-
544
- /*
545
- * call-seq:
546
- * XML::Parser.default_substitute_entities = true|false
547
- *
548
- * Controls whether parsers perform inline entity substitution
549
- * (for external entities) by default.
550
- */
551
- VALUE
552
- ruby_xml_parser_default_substitute_entities_set(VALUE class, VALUE bool) {
553
- if (TYPE(bool) == T_FALSE) {
554
- xmlSubstituteEntitiesDefault(0);
555
- return(Qfalse);
556
- } else {
557
- xmlSubstituteEntitiesDefault(1);
558
- return(Qtrue);
559
- }
560
- }
561
-
562
-
563
- /*
564
- * call-seq:
565
- * XML::Parser.default_tree_indent_string -> "string"
566
- *
567
- * Obtain the default string used by parsers to indent the XML tree
568
- * for output.
569
- */
570
- VALUE
571
- ruby_xml_parser_default_tree_indent_string_get(VALUE class) {
572
- if (xmlTreeIndentString == NULL)
573
- return(Qnil);
574
- else
575
- return(rb_str_new2(xmlTreeIndentString));
576
- }
577
-
578
-
579
- /*
580
- * call-seq:
581
- * XML::Parser.default_tree_indent_string = "string"
582
- *
583
- * Set the default string used by parsers to indent the XML tree
584
- * for output.
585
- */
586
- VALUE
587
- ruby_xml_parser_default_tree_indent_string_set(VALUE class, VALUE string) {
588
- Check_Type(string, T_STRING);
589
- xmlTreeIndentString = xmlStrdup(StringValuePtr(string));
590
- return(string);
591
- }
592
-
593
-
594
- /*
595
- * call-seq:
596
- * XML::Parser.default_validity_checking -> (true|false)
597
- *
598
- * Determine whether parsers perform XML validation by default.
599
- */
600
- VALUE
601
- ruby_xml_parser_default_validity_checking_get(VALUE class) {
602
- if (xmlDoValidityCheckingDefaultValue)
603
- return(Qtrue);
604
- else
605
- return(Qfalse);
606
- }
607
-
608
-
609
- /*
610
- * call-seq:
611
- * XML::Parser.default_validity_checking = true|false
612
- *
613
- * Controls whether parsers perform XML validation by default.
614
- */
615
- VALUE
616
- ruby_xml_parser_default_validity_checking_set(VALUE class, VALUE bool) {
617
- if (TYPE(bool) == T_FALSE) {
618
- xmlDoValidityCheckingDefaultValue = 0;
619
- return(Qfalse);
620
- } else {
621
- xmlDoValidityCheckingDefaultValue = 1;
622
- return(Qtrue);
623
- }
624
- }
625
-
626
-
627
- /*
628
- * call-seq:
629
- * XML::Parser.default_warnings -> (true|false)
630
- *
631
- * Determine whether parsers output warnings by default.
632
- */
633
- VALUE
634
- ruby_xml_parser_default_warnings_get(VALUE class) {
635
- if (xmlGetWarningsDefaultValue)
636
- return(Qtrue);
637
- else
638
- return(Qfalse);
639
- }
640
-
641
-
642
- /*
643
- * call-seq:
644
- * XML::Parser.default_warnings = true|false
645
- *
646
- * Controls whether parsers output warnings by default.
647
- */
648
- VALUE
649
- ruby_xml_parser_default_warnings_set(VALUE class, VALUE bool) {
650
- if (TYPE(bool) == T_FALSE) {
651
- xmlGetWarningsDefaultValue = 0;
652
- return(Qfalse);
653
- } else {
654
- xmlGetWarningsDefaultValue = 1;
655
- return(Qtrue);
656
- }
657
- }
658
-
659
-
660
- /*
661
- * call-seq:
662
- * XML::Parser.default_compression -> (true|false)
663
- *
664
- * Determine whether parsers use Zlib compression by default
665
- * (requires libxml to be compiled with Zlib support).
666
- */
667
- VALUE
668
- ruby_xml_parser_default_compression_get(VALUE class) {
669
- #ifdef HAVE_ZLIB_H
670
- return(INT2FIX(xmlGetCompressMode()));
671
- #else
672
- rb_warn("libxml was compiled without zlib support");
673
- return(Qfalse);
674
- #endif
675
- }
676
-
677
-
678
- /*
679
- * call-seq:
680
- * XML::Parser.default_compression = true|false
681
- *
682
- * Controls whether parsers use Zlib compression by default
683
- * (requires libxml to be compiled with Zlib support).
684
- */
685
- VALUE
686
- ruby_xml_parser_default_compression_set(VALUE class, VALUE num) {
687
- #ifdef HAVE_ZLIB_H
688
- Check_Type(num, T_FIXNUM);
689
- xmlSetCompressMode(FIX2INT(num));
690
- return(num);
691
- #else
692
- rb_warn("libxml was compiled without zlib support");
693
- return(Qfalse);
694
- #endif
695
- }
696
-
697
-
698
- /*
699
- * call-seq:
700
- * XML::Parser.features -> ["feature", ..., "feature"]
701
- *
702
- * Obtains an array of strings representing features supported
703
- * (and enabled) by the installed libxml.
704
- */
705
- VALUE
706
- ruby_xml_parser_features(VALUE class) {
707
- VALUE arr, str;
708
- int i, len = MAX_LIBXML_FEATURES_LEN;
709
- char **list = NULL;
710
-
711
- list = ALLOC_N(char *,MAX_LIBXML_FEATURES_LEN);
712
- MEMZERO(list, char *, MAX_LIBXML_FEATURES_LEN);
713
-
714
- arr = rb_ary_new();
715
- if (xmlGetFeaturesList(&len, (const char **)list) == -1)
716
- return Qnil;
717
-
718
- for (i = 0; i < len; i++) {
719
- str = rb_str_new2((const char *)list[i]);
720
- rb_gc_unregister_address(&str);
721
- rb_ary_push(arr, str);
722
- }
723
-
724
- if (len == MAX_LIBXML_FEATURES_LEN)
725
- rb_warn("Please contact libxml-devel@rubyforge.org and ask to have the \"MAX_LIBXML_FEATURES_LEN increased\" because you could possibly be seeing an incomplete list");
726
-
727
- ruby_xfree(list);
728
- return(arr);
729
- }
730
-
731
-
732
- /*
733
- * call-seq:
734
- * parser.filename -> "filename"
735
- *
736
- * Obtain the filename this parser will read from.
737
- */
738
- VALUE
739
- ruby_xml_parser_filename_get(VALUE self) {
740
- ruby_xml_parser *rxp;
741
- rx_file_data *data;
742
-
743
- Data_Get_Struct(self, ruby_xml_parser, rxp);
744
- if (rxp->data == NULL)
745
- return(Qnil);
746
-
747
- if (rxp->data_type != RUBY_LIBXML_SRC_TYPE_FILE)
748
- return(Qnil);
749
-
750
- data = (rx_file_data *)rxp->data;
751
- return(data->filename);
752
- }
753
-
754
-
755
- /*
756
- * call-seq:
757
- * parser.filename = "filename"
758
- *
759
- * Set the filename this parser will read from.
760
- */
761
- VALUE
762
- ruby_xml_parser_filename_set(VALUE self, VALUE filename) {
763
- ruby_xml_parser *rxp;
764
- ruby_xml_parser_context *rxpc;
765
- rx_file_data *data;
766
- int retry_count = 0;
767
-
768
- Check_Type(filename, T_STRING);
769
- Data_Get_Struct(self, ruby_xml_parser, rxp);
770
-
771
- if (rxp->data_type == RUBY_LIBXML_SRC_TYPE_NULL) {
772
- if (rxp->data != NULL)
773
- rb_fatal("crap, this should be null");
774
-
775
- rxp->data_type = RUBY_LIBXML_SRC_TYPE_FILE;
776
- data = ALLOC(rx_file_data);
777
- rxp->data = data;
778
- } else if (rxp->data_type != RUBY_LIBXML_SRC_TYPE_FILE) {
779
- return(Qnil);
780
- }
781
-
782
- rxp->ctxt = ruby_xml_parser_context_new();
783
- data = (rx_file_data *)rxp->data;
784
- data->filename = filename;
785
-
786
- Data_Get_Struct(rxp->ctxt, ruby_xml_parser_context, rxpc);
787
- retry:
788
- rxpc->ctxt = xmlCreateFileParserCtxt(StringValuePtr(filename));
789
- if (rxpc->ctxt == NULL) {
790
- if ((errno == EMFILE || errno == ENFILE) && retry_count == 0) {
791
- retry_count++;
792
- rb_gc();
793
- goto retry;
794
- } else {
795
- rb_raise(rb_eIOError, StringValuePtr(filename));
796
- }
797
- }
798
-
799
- return(data->filename);
800
- }
801
-
802
-
803
- void
804
- ruby_xml_parser_free(ruby_xml_parser *rxp) {
805
- void *data;
806
-
807
- switch(rxp->data_type) {
808
- case RUBY_LIBXML_SRC_TYPE_NULL:
809
- break;
810
- case RUBY_LIBXML_SRC_TYPE_FILE:
811
- data = (void *)(rx_file_data *)rxp->data;
812
- ruby_xfree((rx_file_data *)data);
813
- break;
814
- case RUBY_LIBXML_SRC_TYPE_STRING:
815
- data = (void *)(rx_string_data *)rxp->data;
816
- ruby_xfree((rx_string_data *)data);
817
- break;
818
- case RUBY_LIBXML_SRC_TYPE_IO:
819
- data = (void *)(rx_io_data *)rxp->data;
820
- ruby_xfree((rx_io_data *)data);
821
- break;
822
- default:
823
- rb_fatal("Unknown data type, %d", rxp->data_type);
824
- }
825
-
826
- ruby_xfree(rxp);
827
- }
828
-
829
-
830
- /*
831
- * call-seq:
832
- * XML::Parser.indent_tree_output -> (true|false)
833
- *
834
- * Determines whether XML output will be indented
835
- * (using the string supplied to +default_indent_tree_string+)
836
- */
837
- VALUE
838
- ruby_xml_parser_indent_tree_output_get(VALUE class) {
839
- if (xmlIndentTreeOutput)
840
- return(Qtrue);
841
- else
842
- return(Qfalse);
843
- }
844
-
845
-
846
- /*
847
- * call-seq:
848
- * XML::Parser.indent_tree_output = true|false
849
- *
850
- * Controls whether XML output will be indented
851
- * (using the string supplied to +default_indent_tree_string+)
852
- */
853
- VALUE
854
- ruby_xml_parser_indent_tree_output_set(VALUE class, VALUE bool) {
855
- if (TYPE(bool) == T_TRUE) {
856
- xmlIndentTreeOutput = 1;
857
- return(Qtrue);
858
- } else if (TYPE(bool) == T_FALSE) {
859
- xmlIndentTreeOutput = 0;
860
- return(Qfalse);
861
- } else {
862
- rb_raise(rb_eArgError, "invalid argument, must be boolean");
863
- }
864
- }
865
-
866
-
867
- /*
868
- * call-seq:
869
- * parser.io -> IO
870
- *
871
- * Obtain the IO instance this parser works with.
872
- */
873
- VALUE
874
- ruby_xml_parser_io_get(VALUE self, VALUE io) {
875
- ruby_xml_parser *rxp;
876
- rx_io_data *data;
877
-
878
- Data_Get_Struct(self, ruby_xml_parser, rxp);
879
-
880
- if (rxp->data_type == RUBY_LIBXML_SRC_TYPE_NULL ||
881
- rxp->data_type != RUBY_LIBXML_SRC_TYPE_IO ||
882
- rxp->data == NULL)
883
- return(Qnil);
884
-
885
- data = (rx_io_data *)rxp->data;
886
-
887
- return(data->io);
888
- }
889
-
890
-
891
- /*
892
- * call-seq:
893
- * parser.io = IO
894
- *
895
- * Set the IO instance this parser works with.
896
- */
897
- VALUE
898
- ruby_xml_parser_io_set(VALUE self, VALUE io) {
899
- ruby_xml_parser *rxp;
900
- ruby_xml_parser_context *rxpc;
901
- rx_io_data *data;
902
- OpenFile *fptr;
903
- FILE *f;
904
-
905
- #ifdef _WIN32
906
- rb_raise(rb_eRuntimeError, "Setting an io buffer is not supported on Windows");
907
- #endif
908
-
909
- if (!rb_obj_is_kind_of(io, rb_cIO))
910
- rb_raise(rb_eTypeError, "need an IO object");
911
-
912
- Data_Get_Struct(self, ruby_xml_parser, rxp);
913
-
914
- if (rxp->data_type == RUBY_LIBXML_SRC_TYPE_NULL) {
915
- if (rxp->data != NULL)
916
- rb_fatal("crap, this should be null");
917
-
918
- rxp->data_type = RUBY_LIBXML_SRC_TYPE_IO;
919
- data = ALLOC(rx_io_data);
920
- rxp->data = data;
921
- } else if (rxp->data_type != RUBY_LIBXML_SRC_TYPE_IO) {
922
- return(Qnil);
923
- }
924
-
925
- rxp->ctxt = ruby_xml_parser_context_new();
926
- data = (rx_io_data *)rxp->data;
927
- data->io = io;
928
-
929
- GetOpenFile(io, fptr);
930
- rb_io_check_readable(fptr);
931
- f = GetWriteFile(fptr);
932
-
933
- Data_Get_Struct(rxp->ctxt, ruby_xml_parser_context, rxpc);
934
- rxpc->ctxt = xmlCreateIOParserCtxt(NULL, NULL,
935
- (xmlInputReadCallback) ctxtRead,
936
- NULL, f, XML_CHAR_ENCODING_NONE);
937
- if (!rxpc->ctxt)
938
- rb_sys_fail(0);
939
-
940
- return(data->io);
941
- }
942
-
943
-
944
- void
945
- ruby_xml_parser_mark(ruby_xml_parser *rxp) {
946
- if (rxp == NULL) return;
947
- if (!NIL_P(rxp->ctxt))
948
- rb_gc_mark(rxp->ctxt);
949
-
950
- rb_gc_mark(LIBXML_STATE);
951
-
952
- switch(rxp->data_type) {
953
- case RUBY_LIBXML_SRC_TYPE_NULL:
954
- break;
955
- case RUBY_LIBXML_SRC_TYPE_FILE:
956
- if (!NIL_P(((rx_file_data *)rxp->data)->filename))
957
- rb_gc_mark(((rx_file_data *)rxp->data)->filename);
958
- break;
959
- case RUBY_LIBXML_SRC_TYPE_STRING:
960
- if (!NIL_P(((rx_string_data *)rxp->data)->str))
961
- rb_gc_mark(((rx_string_data *)rxp->data)->str);
962
- break;
963
- case RUBY_LIBXML_SRC_TYPE_IO:
964
- if (!NIL_P(((rx_io_data *)rxp->data)->io))
965
- rb_gc_mark(((rx_io_data *)rxp->data)->io);
966
- break;
967
- default:
968
- rb_fatal("unknown datatype: %d", rxp->data_type);
969
- }
970
- }
971
-
972
-
973
- /*
974
- * call-seq:
975
- * XML::Parser.memory_dump -> (true|false)
976
- *
977
- * Perform a parser memory dump (requires memory debugging
978
- * support in libxml).
979
- */
980
- VALUE
981
- ruby_xml_parser_memory_dump(VALUE self) {
982
- #ifdef DEBUG_MEMORY_LOCATION
983
- xmlMemoryDump();
984
- return(Qtrue);
985
- #else
986
- rb_warn("libxml was compiled without memory debugging support");
987
- return(Qfalse);
988
- #endif
989
- }
990
-
991
-
992
- /*
993
- * call-seq:
994
- * XML::Parser.memory_used -> num_bytes
995
- *
996
- * Perform a parser memory dump (requires memory debugging
997
- * support in libxml).
998
- */
999
- VALUE
1000
- ruby_xml_parser_memory_used(VALUE self) {
1001
- #ifdef DEBUG_MEMORY_LOCATION
1002
- return(INT2NUM(xmlMemUsed()));
1003
- #else
1004
- rb_warn("libxml was compiled without memory debugging support");
1005
- return(Qfalse);
1006
- #endif
1007
- }
1008
-
1009
-
1010
- /*
1011
- * call-seq:
1012
- * XML::Parser.new -> parser
1013
- *
1014
- * Create a new parser instance with no pre-determined source.
1015
- */
1016
- VALUE
1017
- ruby_xml_parser_new(VALUE class) {
1018
- ruby_xml_parser *rxp;
1019
- VALUE r;
1020
-
1021
- r=Data_Make_Struct(class,
1022
- ruby_xml_parser,
1023
- ruby_xml_parser_mark,
1024
- ruby_xml_parser_free,
1025
- rxp);
1026
-
1027
- rxp->ctxt = Qnil;
1028
- rxp->data_type = RUBY_LIBXML_SRC_TYPE_NULL;
1029
- rxp->data = NULL;
1030
- rxp->parsed = 0;
1031
-
1032
- return r;
1033
- }
1034
-
1035
-
1036
- /*
1037
- * call-seq:
1038
- * XML::Parser.file -> parser
1039
- *
1040
- * Create a new parser instance that will read the specified file.
1041
- */
1042
- VALUE
1043
- ruby_xml_parser_new_file(VALUE class, VALUE filename) {
1044
- VALUE obj;
1045
- ruby_xml_parser *rxp;
1046
- rx_file_data *data;
1047
-
1048
- obj = ruby_xml_parser_new(class);
1049
- Data_Get_Struct(obj, ruby_xml_parser, rxp);
1050
-
1051
- data = ALLOC(rx_file_data);
1052
- rxp->data_type = RUBY_LIBXML_SRC_TYPE_FILE;
1053
- rxp->data = data;
1054
-
1055
- ruby_xml_parser_filename_set(obj, filename);
1056
-
1057
- return(obj);
1058
- }
1059
-
1060
-
1061
- /*
1062
- * call-seq:
1063
- * XML::Parser.io -> parser
1064
- *
1065
- * Create a new parser instance that will read from the
1066
- * specified IO object.
1067
- */
1068
- VALUE
1069
- ruby_xml_parser_new_io(VALUE class, VALUE io) {
1070
- VALUE obj;
1071
- ruby_xml_parser *rxp;
1072
- rx_io_data *data;
1073
-
1074
- obj = ruby_xml_parser_new(class);
1075
- Data_Get_Struct(obj, ruby_xml_parser, rxp);
1076
-
1077
- data = ALLOC(rx_io_data);
1078
- rxp->data_type = RUBY_LIBXML_SRC_TYPE_IO;
1079
- rxp->data = data;
1080
-
1081
- ruby_xml_parser_io_set(obj, io);
1082
-
1083
- return(obj);
1084
- }
1085
-
1086
-
1087
- /*
1088
- * call-seq:
1089
- * XML::Parser.string -> parser
1090
- *
1091
- * Create a new parser instance that will parse the given
1092
- * string.
1093
- */
1094
- VALUE
1095
- ruby_xml_parser_new_string(VALUE class, VALUE str) {
1096
- VALUE obj;
1097
- ruby_xml_parser *rxp;
1098
- rx_string_data *data;
1099
-
1100
- obj = ruby_xml_parser_new(class);
1101
- Data_Get_Struct(obj, ruby_xml_parser, rxp);
1102
-
1103
- data = ALLOC(rx_string_data);
1104
- rxp->data_type = RUBY_LIBXML_SRC_TYPE_STRING;
1105
- rxp->data = data;
1106
-
1107
- ruby_xml_parser_str_set(obj, str);
1108
-
1109
- return(obj);
1110
- }
1111
-
1112
-
1113
- /*
1114
- * call-seq:
1115
- * parser.parse -> document
1116
- *
1117
- * Parse the input XML and create an XML::Document with
1118
- * it's content. If an error occurs, XML::Parser::ParseError
1119
- * is thrown.
1120
- */
1121
- VALUE
1122
- ruby_xml_parser_parse(VALUE self) {
1123
- ruby_xml_parser *rxp;
1124
- ruby_xml_parser_context *rxpc;
1125
- xmlDocPtr xdp;
1126
- VALUE doc;
1127
-
1128
- Data_Get_Struct(self, ruby_xml_parser, rxp);
1129
-
1130
- switch (rxp->data_type) {
1131
- case RUBY_LIBXML_SRC_TYPE_NULL:
1132
- return(Qnil);
1133
- case RUBY_LIBXML_SRC_TYPE_STRING:
1134
- case RUBY_LIBXML_SRC_TYPE_FILE:
1135
- case RUBY_LIBXML_SRC_TYPE_IO:
1136
- Data_Get_Struct(rxp->ctxt, ruby_xml_parser_context, rxpc);
1137
- if (xmlParseDocument(rxpc->ctxt) == -1) {
1138
- xmlFreeDoc(rxpc->ctxt->myDoc);
1139
- rb_raise(eXMLParserParseError, "Document didn't parse");
1140
- }
1141
-
1142
- xdp = rxpc->ctxt->myDoc;
1143
- if (!rxpc->ctxt->wellFormed) {
1144
- xmlFreeDoc(xdp);
1145
- xdp = NULL;
1146
- rb_raise(eXMLParserParseError, "Document did not contain well-formed XML");
1147
- } else {
1148
- rxp->parsed = 1;
1149
- }
1150
-
1151
- doc = ruby_xml_document_wrap(xdp);
1152
- break;
1153
- default:
1154
- rb_fatal("Unknown data type, %d", rxp->data_type);
1155
- }
1156
-
1157
- return(doc);
1158
- }
1159
-
1160
-
1161
- /*
1162
- * call-seq:
1163
- * parser.context -> context
1164
- *
1165
- * Obtain the XML::Parser::Context associated with this
1166
- * parser.
1167
- */
1168
- VALUE
1169
- ruby_xml_parser_context_get(VALUE self) {
1170
- ruby_xml_parser *rxp;
1171
-
1172
- Data_Get_Struct(self, ruby_xml_parser, rxp);
1173
- if (rxp->ctxt == Qnil)
1174
- return(Qnil);
1175
- else
1176
- return(rxp->ctxt);
1177
- }
1178
-
1179
-
1180
- /*
1181
- * call-seq:
1182
- * parser.string -> "string"
1183
- *
1184
- * Obtain the string this parser works with.
1185
- */
1186
- VALUE
1187
- ruby_xml_parser_str_get(VALUE self) {
1188
- ruby_xml_parser *rxp;
1189
- rx_string_data *data;
1190
-
1191
- Data_Get_Struct(self, ruby_xml_parser, rxp);
1192
- if (rxp->data == NULL || rxp->data_type != RUBY_LIBXML_SRC_TYPE_STRING)
1193
- return(Qnil);
1194
-
1195
- data = (rx_string_data *)rxp->data;
1196
- return(data->str);
1197
- }
1198
-
1199
-
1200
- /*
1201
- * call-seq:
1202
- * parser.string = "string"
1203
- *
1204
- * Set the string this parser works with.
1205
- */
1206
- VALUE
1207
- ruby_xml_parser_str_set(VALUE self, VALUE str) {
1208
- ruby_xml_parser *rxp;
1209
- ruby_xml_parser_context *rxpc;
1210
- rx_string_data *data;
1211
-
1212
- Check_Type(str, T_STRING);
1213
- Data_Get_Struct(self, ruby_xml_parser, rxp);
1214
-
1215
- if (rxp->data_type == RUBY_LIBXML_SRC_TYPE_NULL) {
1216
- rxp->data_type = RUBY_LIBXML_SRC_TYPE_STRING;
1217
- data = ALLOC(rx_string_data);
1218
- rxp->data = data;
1219
- } else if (rxp->data_type != RUBY_LIBXML_SRC_TYPE_STRING) {
1220
- return(Qnil);
1221
- }
1222
-
1223
- rxp->ctxt = ruby_xml_parser_context_new();
1224
- data = (rx_string_data *)rxp->data;
1225
- data->str = str;
1226
-
1227
- Data_Get_Struct(rxp->ctxt, ruby_xml_parser_context, rxpc);
1228
- rxpc->ctxt = xmlCreateMemoryParserCtxt(StringValuePtr(data->str), RSTRING_LEN(data->str));
1229
- if ( rxpc->ctxt == NULL )
1230
- rb_raise(eXMLParserParseError,"Cannot initialize parser with given string (maybe empty?)");
1231
-
1232
- return(data->str);
1233
- }
1234
-
1235
- static void
1236
- libxml_xmlErrorFuncHandler(ATTRIBUTE_UNUSED void *ctx, const char *msg, ...)
1237
- {
1238
- VALUE message;
1239
- va_list ap;
1240
- char str[1000];
1241
-
1242
- va_start(ap, msg);
1243
- if (vsnprintf(str, 999, msg, ap) >= 998) str[999] = 0;
1244
- va_end(ap);
1245
-
1246
- message = rb_str_new2(str);
1247
- rb_funcall(cXMLParser, rb_intern("xml_error_func_handler"), 1, message);
1248
- }
1249
-
1250
- /* #define RUBY_XML_PARSER_ENABLED_INIT(func, method) \
1251
- rb_define_singleton_method(cXMLParser, method, \
1252
- ruby_xml_parser_enabled_##func##_q, 0); */
1253
-
1254
- ///#include "cbg.c"
1255
- ///
1256
- ///VALUE ruby_register_deb(VALUE self) {
1257
- /// deb_register_cbg();
1258
- /// return(Qtrue);
1259
- ///}
1260
-
1261
- // Rdoc needs to know
1262
- #ifdef RDOC_NEVER_DEFINED
1263
- mLibXML = rb_define_module("LibXML");
1264
- mXML = rb_define_module_under(mLibXML, "XML");
1265
- #endif
1266
-
1267
- void
1268
- ruby_init_parser(void) {
1269
- cXMLParser = rb_define_class_under(mXML, "Parser", rb_cObject);
1270
- eXMLParserParseError = rb_define_class_under(cXMLParser, "ParseError",
1271
- rb_eRuntimeError);
1272
-
1273
- /* Constants */
1274
- rb_define_const(cXMLParser, "LIBXML_VERSION",
1275
- rb_str_new2(LIBXML_DOTTED_VERSION));
1276
- rb_define_const(cXMLParser, "VERSION", rb_str_new2(RUBY_LIBXML_VERSION));
1277
- rb_define_const(cXMLParser, "VERNUM", INT2NUM(RUBY_LIBXML_VERNUM));
1278
-
1279
- /* Question-esqe Class Methods */
1280
- /* RDoc won't have them defined by a macro... */
1281
- rb_define_singleton_method(cXMLParser, "enabled_automata?",
1282
- ruby_xml_parser_enabled_automata_q, 0);
1283
- rb_define_singleton_method(cXMLParser, "enabled_c14n?",
1284
- ruby_xml_parser_enabled_c14n_q, 0);
1285
- rb_define_singleton_method(cXMLParser, "enabled_catalog?",
1286
- ruby_xml_parser_enabled_catalog_q, 0);
1287
- rb_define_singleton_method(cXMLParser, "enabled_debug?",
1288
- ruby_xml_parser_enabled_debug_q, 0);
1289
- rb_define_singleton_method(cXMLParser, "enabled_docbook?",
1290
- ruby_xml_parser_enabled_docbook_q, 0);
1291
- rb_define_singleton_method(cXMLParser, "enabled_ftp?",
1292
- ruby_xml_parser_enabled_ftp_q, 0);
1293
- rb_define_singleton_method(cXMLParser, "enabled_http?",
1294
- ruby_xml_parser_enabled_http_q, 0);
1295
- rb_define_singleton_method(cXMLParser, "enabled_html?",
1296
- ruby_xml_parser_enabled_html_q, 0);
1297
- rb_define_singleton_method(cXMLParser, "enabled_iconv?",
1298
- ruby_xml_parser_enabled_iconv_q, 0);
1299
- rb_define_singleton_method(cXMLParser, "enabled_memory_debug?",
1300
- ruby_xml_parser_enabled_memory_debug_location_q, 0);
1301
- rb_define_singleton_method(cXMLParser, "enabled_regexp?",
1302
- ruby_xml_parser_enabled_regexp_q, 0);
1303
- rb_define_singleton_method(cXMLParser, "enabled_schemas?",
1304
- ruby_xml_parser_enabled_schemas_q, 0);
1305
- rb_define_singleton_method(cXMLParser, "enabled_thread?",
1306
- ruby_xml_parser_enabled_thread_q, 0);
1307
- rb_define_singleton_method(cXMLParser, "enabled_unicode?",
1308
- ruby_xml_parser_enabled_unicode_q, 0);
1309
- rb_define_singleton_method(cXMLParser, "enabled_xinclude?",
1310
- ruby_xml_parser_enabled_xinclude_q, 0);
1311
- rb_define_singleton_method(cXMLParser, "enabled_xpath?",
1312
- ruby_xml_parser_enabled_xpath_q, 0);
1313
- rb_define_singleton_method(cXMLParser, "enabled_xpointer?",
1314
- ruby_xml_parser_enabled_xpointer_q, 0);
1315
- rb_define_singleton_method(cXMLParser, "enabled_zlib?",
1316
- ruby_xml_parser_enabled_zlib_q, 0);
1317
-
1318
- /* Other Class Methods */
1319
- /// rb_define_singleton_method(cXMLParser, "register_deb",
1320
- /// ruby_register_deb, 0);
1321
-
1322
- // TODO Maybe a set of 'xxxx_catalog' aliases might be more Ruby?
1323
- rb_define_singleton_method(cXMLParser, "catalog_dump",
1324
- ruby_xml_parser_catalog_dump, 0);
1325
- rb_define_singleton_method(cXMLParser, "catalog_remove",
1326
- ruby_xml_parser_catalog_remove, 1);
1327
- rb_define_singleton_method(cXMLParser, "check_lib_versions",
1328
- ruby_xml_parser_check_lib_versions, 0);
1329
-
1330
- // TODO should this be debug_entities_q / debug_entities_set?
1331
- // should all these default attribute pairs work that way?
1332
- rb_define_singleton_method(cXMLParser, "debug_entities",
1333
- ruby_xml_parser_debug_entities_get, 0);
1334
- rb_define_singleton_method(cXMLParser, "debug_entities=",
1335
- ruby_xml_parser_debug_entities_set, 1);
1336
- rb_define_singleton_method(cXMLParser, "default_compression",
1337
- ruby_xml_parser_default_compression_get, 0);
1338
- rb_define_singleton_method(cXMLParser, "default_compression=",
1339
- ruby_xml_parser_default_compression_set, 1);
1340
- rb_define_singleton_method(cXMLParser, "default_keep_blanks",
1341
- ruby_xml_parser_default_keep_blanks_get, 0);
1342
- rb_define_singleton_method(cXMLParser, "default_keep_blanks=",
1343
- ruby_xml_parser_default_keep_blanks_set, 1);
1344
- rb_define_singleton_method(cXMLParser, "default_load_external_dtd",
1345
- ruby_xml_parser_default_load_external_dtd_get, 0);
1346
- rb_define_singleton_method(cXMLParser, "default_load_external_dtd=",
1347
- ruby_xml_parser_default_load_external_dtd_set, 1);
1348
- rb_define_singleton_method(cXMLParser, "default_line_numbers",
1349
- ruby_xml_parser_default_line_numbers_get, 0);
1350
- rb_define_singleton_method(cXMLParser, "default_line_numbers=",
1351
- ruby_xml_parser_default_line_numbers_set, 1);
1352
- rb_define_singleton_method(cXMLParser, "default_pedantic_parser",
1353
- ruby_xml_parser_default_pedantic_parser_get, 0);
1354
- rb_define_singleton_method(cXMLParser, "default_pedantic_parser=",
1355
- ruby_xml_parser_default_pedantic_parser_set, 1);
1356
- rb_define_singleton_method(cXMLParser, "default_substitute_entities",
1357
- ruby_xml_parser_default_substitute_entities_get, 0);
1358
- rb_define_singleton_method(cXMLParser, "default_substitute_entities=",
1359
- ruby_xml_parser_default_substitute_entities_set, 1);
1360
- rb_define_singleton_method(cXMLParser, "default_tree_indent_string",
1361
- ruby_xml_parser_default_tree_indent_string_get, 0);
1362
- rb_define_singleton_method(cXMLParser, "default_tree_indent_string=",
1363
- ruby_xml_parser_default_tree_indent_string_set, 1);
1364
- rb_define_singleton_method(cXMLParser, "default_validity_checking",
1365
- ruby_xml_parser_default_validity_checking_get, 0);
1366
- rb_define_singleton_method(cXMLParser, "default_validity_checking=",
1367
- ruby_xml_parser_default_validity_checking_set, 1);
1368
- rb_define_singleton_method(cXMLParser, "default_warnings",
1369
- ruby_xml_parser_default_warnings_get, 0);
1370
- rb_define_singleton_method(cXMLParser, "default_warnings=",
1371
- ruby_xml_parser_default_warnings_set, 1);
1372
-
1373
- rb_define_singleton_method(cXMLParser, "features", ruby_xml_parser_features, 0);
1374
- rb_define_singleton_method(cXMLParser, "file", ruby_xml_parser_new_file, 1);
1375
- rb_define_singleton_method(cXMLParser, "indent_tree_output", ruby_xml_parser_indent_tree_output_get, 0);
1376
- rb_define_singleton_method(cXMLParser, "indent_tree_output=", ruby_xml_parser_indent_tree_output_set, 1);
1377
- rb_define_singleton_method(cXMLParser, "io", ruby_xml_parser_new_io, 1);
1378
- rb_define_singleton_method(cXMLParser, "memory_dump",
1379
- ruby_xml_parser_memory_dump, 0);
1380
- rb_define_singleton_method(cXMLParser, "memory_used",
1381
- ruby_xml_parser_memory_used, 0);
1382
- rb_define_singleton_method(cXMLParser, "new", ruby_xml_parser_new, 0);
1383
- rb_define_singleton_method(cXMLParser, "string", ruby_xml_parser_new_string, 1);
1384
- rb_define_method(cXMLParser, "filename", ruby_xml_parser_filename_get, 0);
1385
- rb_define_method(cXMLParser, "filename=", ruby_xml_parser_filename_set, 1);
1386
- rb_define_method(cXMLParser, "io", ruby_xml_parser_io_get, 0);
1387
- rb_define_method(cXMLParser, "io=", ruby_xml_parser_io_set, 1);
1388
- rb_define_method(cXMLParser, "parse", ruby_xml_parser_parse, 0);
1389
- rb_define_method(cXMLParser, "context", ruby_xml_parser_context_get, 0);
1390
- rb_define_method(cXMLParser, "string", ruby_xml_parser_str_get, 0);
1391
- rb_define_method(cXMLParser, "string=", ruby_xml_parser_str_set, 1);
1392
-
1393
- // set up error handling
1394
- xmlSetGenericErrorFunc(NULL, libxml_xmlErrorFuncHandler);
1395
- xmlThrDefSetGenericErrorFunc(NULL, libxml_xmlErrorFuncHandler);
1396
-
1397
- id_call = rb_intern("call");
1398
- }
1
+ /* $Id: ruby_xml_parser.c 585 2008-11-18 17:40:45Z cfis $ */
2
+
3
+ /* Please see the LICENSE file for copyright and distribution information */
4
+
5
+ #include <stdarg.h>
6
+ #include "ruby_libxml.h"
7
+
8
+ VALUE cXMLParser;
9
+ ID INPUT_ATTR;
10
+ ID CONTEXT_ATTR;
11
+
12
+ /*
13
+ * Document-class: LibXML::XML::Parser
14
+ *
15
+ * The XML::Parser provides a tree based API for processing
16
+ * xml documents, in contract to XML::Reader's stream
17
+ * based api and XML::SaxParser callback based API.
18
+ *
19
+ * As a result, parsing a document creates an in-memory document object
20
+ * that consist of any number of XML::Node instances. This is simple
21
+ * and powerful model, but has the major limitation that the size of
22
+ * the document that can be processed is limited by the amount of
23
+ * memory available. In such cases, it is better to use the XML::Reader.
24
+ *
25
+ * Using the parser is simple:
26
+ *
27
+ * parser = XML::Parser.new
28
+ * parser.file = 'my_file'
29
+ * doc = parser.parse
30
+ *
31
+ * You can also parse strings (see XML::Parser.string) and io objects (see
32
+ * XML::Parser.io).
33
+ */
34
+
35
+ static int
36
+ ctxtRead(FILE *f, char * buf, size_t len) {
37
+ return(rb_io_fread(buf, len, f));
38
+ }
39
+
40
+
41
+ /*
42
+ * call-seq:
43
+ * parser.initialize -> parser
44
+ *
45
+ * Initiliazes instance of parser.
46
+ */
47
+ VALUE
48
+ ruby_xml_parser_initialize(VALUE self) {
49
+ VALUE input = rb_class_new_instance(0, NULL, cXMLInput);
50
+ rb_iv_set(self, "@input", input);
51
+ rb_iv_set(self, "@context", Qnil);
52
+ return self;
53
+ }
54
+
55
+
56
+ xmlParserCtxtPtr
57
+ ruby_xml_parser_filename_ctxt(VALUE input) {
58
+ xmlParserCtxtPtr ctxt;
59
+ int retry_count = 0;
60
+ VALUE filename = rb_ivar_get(input, FILE_ATTR);
61
+
62
+ retry:
63
+ ctxt = xmlCreateFileParserCtxt(StringValuePtr(filename));
64
+ if (ctxt == NULL) {
65
+ if ((errno == EMFILE || errno == ENFILE) && retry_count == 0) {
66
+ retry_count++;
67
+ rb_gc();
68
+ goto retry;
69
+ } else {
70
+ rb_raise(rb_eIOError, StringValuePtr(filename));
71
+ }
72
+ }
73
+
74
+ return ctxt;
75
+ }
76
+
77
+ xmlParserCtxtPtr
78
+ ruby_xml_parser_str_ctxt(VALUE input) {
79
+ VALUE str = rb_ivar_get(input, STRING_ATTR);
80
+ return xmlCreateMemoryParserCtxt(StringValuePtr(str), RSTRING_LEN(str));
81
+ }
82
+
83
+ xmlParserCtxtPtr
84
+ ruby_xml_parser_io_ctxt(VALUE input) {
85
+ VALUE io = rb_ivar_get(input, IO_ATTR);
86
+ VALUE encoding = rb_ivar_get(input, ENCODING_ATTR);
87
+ xmlCharEncoding xmlEncoding = NUM2INT(encoding);
88
+ OpenFile *fptr;
89
+ FILE *f;
90
+
91
+ GetOpenFile(io, fptr);
92
+ rb_io_check_readable(fptr);
93
+ f = GetReadFile(fptr);
94
+
95
+ return xmlCreateIOParserCtxt(NULL, NULL,
96
+ (xmlInputReadCallback) ctxtRead,
97
+ NULL, f, xmlEncoding);
98
+ }
99
+
100
+
101
+ /*
102
+ * call-seq:
103
+ * parser.parse -> document
104
+ *
105
+ * Parse the input XML and create an XML::Document with
106
+ * it's content. If an error occurs, XML::Parser::ParseError
107
+ * is thrown.
108
+ */
109
+ VALUE
110
+ ruby_xml_parser_parse(VALUE self) {
111
+ xmlParserCtxtPtr ctxt;
112
+ VALUE context;
113
+ VALUE input = rb_ivar_get(self, INPUT_ATTR);
114
+
115
+ context = rb_ivar_get(self, CONTEXT_ATTR);
116
+ if (context != Qnil)
117
+ rb_raise(rb_eRuntimeError, "You cannot parse a data source twice");
118
+
119
+ if (rb_ivar_get(input, FILE_ATTR) != Qnil)
120
+ ctxt = ruby_xml_parser_filename_ctxt(input);
121
+ else if (rb_ivar_get(input, STRING_ATTR) != Qnil)
122
+ ctxt = ruby_xml_parser_str_ctxt(input);
123
+ /*else if (rb_ivar_get(input, DOCUMENT_ATTR) != Qnil)
124
+ ctxt = ruby_xml_parser_parse_document(input);*/
125
+ else if (rb_ivar_get(input, IO_ATTR) != Qnil)
126
+ ctxt = ruby_xml_parser_io_ctxt(input);
127
+ else
128
+ rb_raise(rb_eArgError, "You must specify a parser data source");
129
+
130
+ if (!ctxt)
131
+ ruby_xml_raise(&xmlLastError);
132
+
133
+ context = ruby_xml_parser_context_wrap(ctxt);
134
+ rb_ivar_set(self, CONTEXT_ATTR, context);
135
+
136
+ if (xmlParseDocument(ctxt) == -1 || !ctxt->wellFormed) {
137
+ xmlFreeDoc(ctxt->myDoc);
138
+ ruby_xml_raise(&ctxt->lastError);
139
+ }
140
+
141
+ return ruby_xml_document_wrap(ctxt->myDoc);
142
+ }
143
+
144
+
145
+ // Rdoc needs to know
146
+ #ifdef RDOC_NEVER_DEFINED
147
+ mLibXML = rb_define_module("LibXML");
148
+ mXML = rb_define_module_under(mLibXML, "XML");
149
+ #endif
150
+
151
+ void
152
+ ruby_init_parser(void) {
153
+ cXMLParser = rb_define_class_under(mXML, "Parser", rb_cObject);
154
+
155
+ /* Atributes */
156
+ INPUT_ATTR = rb_intern("@input");
157
+ CONTEXT_ATTR = rb_intern("@context");
158
+ rb_define_attr(cXMLParser, "input", 1, 0);
159
+ rb_define_attr(cXMLParser, "context", 1, 0);
160
+
161
+ /* Instance Methods */
162
+ rb_define_method(cXMLParser, "initialize", ruby_xml_parser_initialize, 0);
163
+ rb_define_method(cXMLParser, "parse", ruby_xml_parser_parse, 0);
164
+ }