libxml-ruby 2.0.0-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (163) hide show
  1. data/HISTORY +516 -0
  2. data/LICENSE +23 -0
  3. data/MANIFEST +165 -0
  4. data/README.rdoc +161 -0
  5. data/Rakefile +82 -0
  6. data/ext/libxml/extconf.rb +122 -0
  7. data/ext/libxml/libxml.c +93 -0
  8. data/ext/libxml/ruby_libxml.h +101 -0
  9. data/ext/libxml/ruby_xml.c +893 -0
  10. data/ext/libxml/ruby_xml.h +10 -0
  11. data/ext/libxml/ruby_xml_attr.c +352 -0
  12. data/ext/libxml/ruby_xml_attr.h +14 -0
  13. data/ext/libxml/ruby_xml_attr_decl.c +171 -0
  14. data/ext/libxml/ruby_xml_attr_decl.h +13 -0
  15. data/ext/libxml/ruby_xml_attributes.c +277 -0
  16. data/ext/libxml/ruby_xml_attributes.h +17 -0
  17. data/ext/libxml/ruby_xml_cbg.c +85 -0
  18. data/ext/libxml/ruby_xml_document.c +958 -0
  19. data/ext/libxml/ruby_xml_document.h +17 -0
  20. data/ext/libxml/ruby_xml_dtd.c +257 -0
  21. data/ext/libxml/ruby_xml_dtd.h +9 -0
  22. data/ext/libxml/ruby_xml_encoding.c +221 -0
  23. data/ext/libxml/ruby_xml_encoding.h +16 -0
  24. data/ext/libxml/ruby_xml_error.c +1004 -0
  25. data/ext/libxml/ruby_xml_error.h +14 -0
  26. data/ext/libxml/ruby_xml_html_parser.c +92 -0
  27. data/ext/libxml/ruby_xml_html_parser.h +12 -0
  28. data/ext/libxml/ruby_xml_html_parser_context.c +308 -0
  29. data/ext/libxml/ruby_xml_html_parser_context.h +12 -0
  30. data/ext/libxml/ruby_xml_html_parser_options.c +40 -0
  31. data/ext/libxml/ruby_xml_html_parser_options.h +12 -0
  32. data/ext/libxml/ruby_xml_input_cbg.c +191 -0
  33. data/ext/libxml/ruby_xml_input_cbg.h +20 -0
  34. data/ext/libxml/ruby_xml_io.c +30 -0
  35. data/ext/libxml/ruby_xml_io.h +9 -0
  36. data/ext/libxml/ruby_xml_namespace.c +170 -0
  37. data/ext/libxml/ruby_xml_namespace.h +12 -0
  38. data/ext/libxml/ruby_xml_namespaces.c +295 -0
  39. data/ext/libxml/ruby_xml_namespaces.h +11 -0
  40. data/ext/libxml/ruby_xml_node.c +1386 -0
  41. data/ext/libxml/ruby_xml_node.h +13 -0
  42. data/ext/libxml/ruby_xml_parser.c +94 -0
  43. data/ext/libxml/ruby_xml_parser.h +14 -0
  44. data/ext/libxml/ruby_xml_parser_context.c +982 -0
  45. data/ext/libxml/ruby_xml_parser_context.h +12 -0
  46. data/ext/libxml/ruby_xml_parser_options.c +68 -0
  47. data/ext/libxml/ruby_xml_parser_options.h +14 -0
  48. data/ext/libxml/ruby_xml_reader.c +1057 -0
  49. data/ext/libxml/ruby_xml_reader.h +14 -0
  50. data/ext/libxml/ruby_xml_relaxng.c +111 -0
  51. data/ext/libxml/ruby_xml_relaxng.h +10 -0
  52. data/ext/libxml/ruby_xml_sax2_handler.c +334 -0
  53. data/ext/libxml/ruby_xml_sax2_handler.h +12 -0
  54. data/ext/libxml/ruby_xml_sax_parser.c +136 -0
  55. data/ext/libxml/ruby_xml_sax_parser.h +12 -0
  56. data/ext/libxml/ruby_xml_schema.c +159 -0
  57. data/ext/libxml/ruby_xml_schema.h +11 -0
  58. data/ext/libxml/ruby_xml_version.h +9 -0
  59. data/ext/libxml/ruby_xml_xinclude.c +18 -0
  60. data/ext/libxml/ruby_xml_xinclude.h +13 -0
  61. data/ext/libxml/ruby_xml_xpath.c +107 -0
  62. data/ext/libxml/ruby_xml_xpath.h +12 -0
  63. data/ext/libxml/ruby_xml_xpath_context.c +390 -0
  64. data/ext/libxml/ruby_xml_xpath_context.h +11 -0
  65. data/ext/libxml/ruby_xml_xpath_expression.c +83 -0
  66. data/ext/libxml/ruby_xml_xpath_expression.h +12 -0
  67. data/ext/libxml/ruby_xml_xpath_object.c +336 -0
  68. data/ext/libxml/ruby_xml_xpath_object.h +19 -0
  69. data/ext/libxml/ruby_xml_xpointer.c +101 -0
  70. data/ext/libxml/ruby_xml_xpointer.h +13 -0
  71. data/ext/mingw/Rakefile +34 -0
  72. data/ext/mingw/build.rake +41 -0
  73. data/ext/vc/libxml_ruby.sln +26 -0
  74. data/lib/1.8/libxml_ruby.so +0 -0
  75. data/lib/1.9/libxml_ruby.so +0 -0
  76. data/lib/libxml.rb +30 -0
  77. data/lib/libxml/attr.rb +113 -0
  78. data/lib/libxml/attr_decl.rb +80 -0
  79. data/lib/libxml/attributes.rb +14 -0
  80. data/lib/libxml/document.rb +192 -0
  81. data/lib/libxml/error.rb +90 -0
  82. data/lib/libxml/hpricot.rb +78 -0
  83. data/lib/libxml/html_parser.rb +96 -0
  84. data/lib/libxml/namespace.rb +62 -0
  85. data/lib/libxml/namespaces.rb +38 -0
  86. data/lib/libxml/node.rb +399 -0
  87. data/lib/libxml/ns.rb +22 -0
  88. data/lib/libxml/parser.rb +367 -0
  89. data/lib/libxml/properties.rb +23 -0
  90. data/lib/libxml/reader.rb +29 -0
  91. data/lib/libxml/sax_callbacks.rb +180 -0
  92. data/lib/libxml/sax_parser.rb +58 -0
  93. data/lib/libxml/tree.rb +29 -0
  94. data/lib/libxml/xpath_object.rb +16 -0
  95. data/lib/xml.rb +16 -0
  96. data/lib/xml/libxml.rb +10 -0
  97. data/libxml-ruby.gemspec +50 -0
  98. data/script/benchmark/depixelate +634 -0
  99. data/script/benchmark/hamlet.xml +9055 -0
  100. data/script/benchmark/parsecount +170 -0
  101. data/script/benchmark/sock_entries.xml +507 -0
  102. data/script/benchmark/throughput +41 -0
  103. data/script/test +6 -0
  104. data/setup.rb +1585 -0
  105. data/test/etc_doc_to_s.rb +21 -0
  106. data/test/ets_doc_file.rb +17 -0
  107. data/test/ets_doc_to_s.rb +23 -0
  108. data/test/ets_gpx.rb +28 -0
  109. data/test/ets_node_gc.rb +23 -0
  110. data/test/ets_test.xml +2 -0
  111. data/test/ets_tsr.rb +11 -0
  112. data/test/model/atom.xml +13 -0
  113. data/test/model/bands.iso-8859-1.xml +5 -0
  114. data/test/model/bands.utf-8.xml +5 -0
  115. data/test/model/bands.xml +5 -0
  116. data/test/model/books.xml +146 -0
  117. data/test/model/merge_bug_data.xml +58 -0
  118. data/test/model/ruby-lang.html +238 -0
  119. data/test/model/rubynet.xml +79 -0
  120. data/test/model/rubynet_project +1 -0
  121. data/test/model/shiporder.rnc +28 -0
  122. data/test/model/shiporder.rng +86 -0
  123. data/test/model/shiporder.xml +23 -0
  124. data/test/model/shiporder.xsd +31 -0
  125. data/test/model/soap.xml +27 -0
  126. data/test/model/xinclude.xml +5 -0
  127. data/test/rb-magic-comment.rb +33 -0
  128. data/test/tc_attr.rb +181 -0
  129. data/test/tc_attr_decl.rb +133 -0
  130. data/test/tc_attributes.rb +135 -0
  131. data/test/tc_deprecated_require.rb +13 -0
  132. data/test/tc_document.rb +119 -0
  133. data/test/tc_document_write.rb +187 -0
  134. data/test/tc_dtd.rb +125 -0
  135. data/test/tc_error.rb +138 -0
  136. data/test/tc_html_parser.rb +140 -0
  137. data/test/tc_namespace.rb +62 -0
  138. data/test/tc_namespaces.rb +177 -0
  139. data/test/tc_node.rb +258 -0
  140. data/test/tc_node_cdata.rb +51 -0
  141. data/test/tc_node_comment.rb +33 -0
  142. data/test/tc_node_copy.rb +42 -0
  143. data/test/tc_node_edit.rb +160 -0
  144. data/test/tc_node_text.rb +71 -0
  145. data/test/tc_node_write.rb +108 -0
  146. data/test/tc_node_xlink.rb +29 -0
  147. data/test/tc_parser.rb +336 -0
  148. data/test/tc_parser_context.rb +189 -0
  149. data/test/tc_properties.rb +39 -0
  150. data/test/tc_reader.rb +298 -0
  151. data/test/tc_relaxng.rb +54 -0
  152. data/test/tc_sax_parser.rb +276 -0
  153. data/test/tc_schema.rb +53 -0
  154. data/test/tc_traversal.rb +222 -0
  155. data/test/tc_xinclude.rb +21 -0
  156. data/test/tc_xml.rb +226 -0
  157. data/test/tc_xpath.rb +195 -0
  158. data/test/tc_xpath_context.rb +80 -0
  159. data/test/tc_xpath_expression.rb +38 -0
  160. data/test/tc_xpointer.rb +74 -0
  161. data/test/test_helper.rb +14 -0
  162. data/test/test_suite.rb +39 -0
  163. metadata +254 -0
@@ -0,0 +1,14 @@
1
+ /* Copyright (c) 2006 Apple Computer Inc.
2
+ * Please see the LICENSE file for copyright and distribution information. */
3
+
4
+ #ifndef __RXML_READER__
5
+ #define __RXML_READER__
6
+
7
+ extern VALUE cXMLReader;
8
+
9
+ void rxml_init_reader(void);
10
+
11
+ /* Exported to be used by XML::Document#reader */
12
+ VALUE rxml_reader_new_walker(VALUE self, VALUE doc);
13
+
14
+ #endif /* __rxml_READER__ */
@@ -0,0 +1,111 @@
1
+ #include "ruby_libxml.h"
2
+ #include "ruby_xml_relaxng.h"
3
+
4
+ /*
5
+ * Document-class: LibXML::XML::RelaxNG
6
+ *
7
+ * The XML::RelaxNG class is used to prepare RelaxNG schemas for validation
8
+ * of xml documents.
9
+ *
10
+ * Schemas can be created from XML documents, strings or URIs using the
11
+ * corresponding methods (new for URIs).
12
+ *
13
+ * Once a schema is prepared, an XML document can be validated by the
14
+ * XML::Document#validate_relaxng method providing the XML::RelaxNG object
15
+ * as parameter. The method will raise an exception if the document is
16
+ * not valid.
17
+ *
18
+ * Basic Usage:
19
+ *
20
+ * # parse schema as xml document
21
+ * relaxng_document = XML::Document.file('schema.rng')
22
+ *
23
+ * # prepare schema for validation
24
+ * relaxng_schema = XML::RelaxNG.document(relaxng_document)
25
+ *
26
+ * # parse xml document to be validated
27
+ * instance = XML::Document.file('instance.xml')
28
+ *
29
+ * # validate
30
+ * instance.validate_relaxng(relaxng_schema)
31
+ */
32
+
33
+ VALUE cXMLRelaxNG;
34
+
35
+ static void rxml_relaxng_free(xmlRelaxNGPtr xrelaxng)
36
+ {
37
+ xmlRelaxNGFree(xrelaxng);
38
+ }
39
+
40
+ /*
41
+ * call-seq:
42
+ * XML::Relaxng.new(relaxng_uri) -> relaxng
43
+ *
44
+ * Create a new relaxng from the specified URI.
45
+ */
46
+ static VALUE rxml_relaxng_init_from_uri(VALUE class, VALUE uri)
47
+ {
48
+ xmlRelaxNGParserCtxtPtr xparser;
49
+ xmlRelaxNGPtr xrelaxng;
50
+
51
+ Check_Type(uri, T_STRING);
52
+
53
+ xparser = xmlRelaxNGNewParserCtxt(StringValuePtr(uri));
54
+ xrelaxng = xmlRelaxNGParse(xparser);
55
+ xmlRelaxNGFreeParserCtxt(xparser);
56
+
57
+ return Data_Wrap_Struct(cXMLRelaxNG, NULL, rxml_relaxng_free, xrelaxng);
58
+ }
59
+
60
+ /*
61
+ * call-seq:
62
+ * XML::RelaxNG.document(document) -> relaxng
63
+ *
64
+ * Create a new relaxng from the specified document.
65
+ */
66
+ static VALUE rxml_relaxng_init_from_document(VALUE class, VALUE document)
67
+ {
68
+ xmlDocPtr xdoc;
69
+ xmlRelaxNGPtr xrelaxng;
70
+ xmlRelaxNGParserCtxtPtr xparser;
71
+
72
+ Data_Get_Struct(document, xmlDoc, xdoc);
73
+
74
+ xparser = xmlRelaxNGNewDocParserCtxt(xdoc);
75
+ xrelaxng = xmlRelaxNGParse(xparser);
76
+ xmlRelaxNGFreeParserCtxt(xparser);
77
+
78
+ return Data_Wrap_Struct(cXMLRelaxNG, NULL, rxml_relaxng_free, xrelaxng);
79
+ }
80
+
81
+ /*
82
+ * call-seq:
83
+ * XML::RelaxNG.string("relaxng_data") -> "value"
84
+ *
85
+ * Create a new relaxng using the specified string.
86
+ */
87
+ static VALUE rxml_relaxng_init_from_string(VALUE self, VALUE relaxng_str)
88
+ {
89
+ xmlRelaxNGParserCtxtPtr xparser;
90
+ xmlRelaxNGPtr xrelaxng;
91
+
92
+ Check_Type(relaxng_str, T_STRING);
93
+
94
+ xparser = xmlRelaxNGNewMemParserCtxt(StringValuePtr(relaxng_str), strlen(
95
+ StringValuePtr(relaxng_str)));
96
+ xrelaxng = xmlRelaxNGParse(xparser);
97
+ xmlRelaxNGFreeParserCtxt(xparser);
98
+
99
+ return Data_Wrap_Struct(cXMLRelaxNG, NULL, rxml_relaxng_free, xrelaxng);
100
+ }
101
+
102
+ void rxml_init_relaxng(void)
103
+ {
104
+ cXMLRelaxNG = rb_define_class_under(mXML, "RelaxNG", rb_cObject);
105
+ rb_define_singleton_method(cXMLRelaxNG, "new", rxml_relaxng_init_from_uri, 1);
106
+ rb_define_singleton_method(cXMLRelaxNG, "from_string",
107
+ rxml_relaxng_init_from_string, 1);
108
+ rb_define_singleton_method(cXMLRelaxNG, "document",
109
+ rxml_relaxng_init_from_document, 1);
110
+ }
111
+
@@ -0,0 +1,10 @@
1
+ #ifndef __RXML_RELAXNG__
2
+ #define __RXML_RELAXNG__
3
+
4
+ #include <libxml/relaxng.h>
5
+
6
+ extern VALUE cXMLRelaxNG;
7
+
8
+ void rxml_init_relaxng(void);
9
+ #endif
10
+
@@ -0,0 +1,334 @@
1
+ /* $Id: ruby_xml_sax_parser.c 682 2008-12-09 05:31:13Z cfis $ */
2
+
3
+ /* Please see the LICENSE file for copyright and distribution information */
4
+
5
+ #include "ruby_libxml.h"
6
+ #include "ruby_xml_sax2_handler.h"
7
+
8
+
9
+ VALUE cbidOnCdataBlock;
10
+ VALUE cbidOnCharacters;
11
+ VALUE cbidOnComment;
12
+ VALUE cbidOnEndDocument;
13
+ VALUE cbidOnEndElement;
14
+ VALUE cbidOnEndElementNs;
15
+ VALUE cbidOnExternalSubset;
16
+ VALUE cbidOnHasExternalSubset;
17
+ VALUE cbidOnHasInternalSubset;
18
+ VALUE cbidOnInternalSubset;
19
+ VALUE cbidOnIsStandalone;
20
+ VALUE cbidOnError;
21
+ VALUE cbidOnProcessingInstruction;
22
+ VALUE cbidOnReference;
23
+ VALUE cbidOnStartElement;
24
+ VALUE cbidOnStartElementNs;
25
+ VALUE cbidOnStartDocument;
26
+
27
+ /* ====== Callbacks =========== */
28
+ static void cdata_block_callback(void *ctx,
29
+ const char *value, int len)
30
+ {
31
+ VALUE handler = (VALUE) ctx;
32
+
33
+ if (handler != Qnil)
34
+ {
35
+ rb_funcall(handler, cbidOnCdataBlock,1,rb_str_new(value, len));
36
+ }
37
+ }
38
+
39
+ static void characters_callback(void *ctx,
40
+ const char *chars, int len)
41
+ {
42
+ VALUE handler = (VALUE) ctx;
43
+
44
+ if (handler != Qnil)
45
+ {
46
+ VALUE rchars = rb_str_new(chars, len);
47
+ rb_funcall(handler, cbidOnCharacters, 1, rchars);
48
+ }
49
+ }
50
+
51
+ static void comment_callback(void *ctx,
52
+ const char *msg)
53
+ {
54
+ VALUE handler = (VALUE) ctx;
55
+
56
+ if (handler != Qnil)
57
+ {
58
+ rb_funcall(handler, cbidOnComment,1,rb_str_new2(msg));
59
+ }
60
+ }
61
+
62
+ static void end_document_callback(void *ctx)
63
+ {
64
+ VALUE handler = (VALUE) ctx;
65
+
66
+ if (handler != Qnil)
67
+ {
68
+ rb_funcall(handler, cbidOnEndDocument, 0);
69
+ }
70
+ }
71
+
72
+ static void end_element_ns_callback(void *ctx,
73
+ const xmlChar *xlocalname, const xmlChar *xprefix, const xmlChar *xURI)
74
+ {
75
+ VALUE handler = (VALUE) ctx;
76
+
77
+ if (handler == Qnil)
78
+ return;
79
+
80
+ /* Call end element for old-times sake */
81
+ if (rb_respond_to(handler, cbidOnEndElement))
82
+ {
83
+ VALUE name;
84
+ if (xprefix)
85
+ {
86
+ name = rb_str_new2(xprefix);
87
+ rb_str_cat2(name, ":");
88
+ rb_str_cat2(name, xlocalname);
89
+ }
90
+ else
91
+ {
92
+ name = rb_str_new2(xlocalname);
93
+ }
94
+ rb_funcall(handler, cbidOnEndElement, 1, name);
95
+ }
96
+
97
+ rb_funcall(handler, cbidOnEndElementNs, 3,
98
+ rb_str_new2(xlocalname),
99
+ xprefix ? rb_str_new2(xprefix) : Qnil,
100
+ xURI ? rb_str_new2(xURI) : Qnil);
101
+ }
102
+
103
+ static void external_subset_callback(void *ctx, const char *name, const char *extid, const char *sysid)
104
+ {
105
+ VALUE handler = (VALUE) ctx;
106
+
107
+ if (handler != Qnil)
108
+ {
109
+ VALUE rname = name ? rb_str_new2(name) : Qnil;
110
+ VALUE rextid = extid ? rb_str_new2(extid) : Qnil;
111
+ VALUE rsysid = sysid ? rb_str_new2(sysid) : Qnil;
112
+ rb_funcall(handler, cbidOnExternalSubset, 3, rname, rextid, rsysid);
113
+ }
114
+ }
115
+
116
+ static void has_external_subset_callback(void *ctx)
117
+ {
118
+ VALUE handler = (VALUE) ctx;
119
+
120
+ if (handler != Qnil)
121
+ {
122
+ rb_funcall(handler, cbidOnHasExternalSubset, 0);
123
+ }
124
+ }
125
+
126
+ static void has_internal_subset_callback(void *ctx)
127
+ {
128
+ VALUE handler = (VALUE) ctx;
129
+
130
+ if (handler != Qnil)
131
+ {
132
+ rb_funcall(handler, cbidOnHasInternalSubset, 0);
133
+ }
134
+ }
135
+
136
+ static void internal_subset_callback(void *ctx, const char *name, const char *extid, const char *sysid)
137
+ {
138
+ VALUE handler = (VALUE) ctx;
139
+
140
+ if (handler != Qnil)
141
+ {
142
+ VALUE rname = name ? rb_str_new2(name) : Qnil;
143
+ VALUE rextid = extid ? rb_str_new2(extid) : Qnil;
144
+ VALUE rsysid = sysid ? rb_str_new2(sysid) : Qnil;
145
+ rb_funcall(handler, cbidOnInternalSubset, 3, rname, rextid, rsysid);
146
+ }
147
+ }
148
+
149
+ static void is_standalone_callback(void *ctx)
150
+ {
151
+ VALUE handler = (VALUE) ctx;
152
+
153
+ if (handler != Qnil)
154
+ {
155
+ rb_funcall(handler, cbidOnIsStandalone,0);
156
+ }
157
+ }
158
+
159
+ static void processing_instruction_callback(void *ctx, const char *target, const char *data)
160
+ {
161
+ VALUE handler = (VALUE) ctx;
162
+
163
+ if (handler != Qnil)
164
+ {
165
+ VALUE rtarget = target ? rb_str_new2(target) : Qnil;
166
+ VALUE rdata = data ? rb_str_new2(data) : Qnil;
167
+ rb_funcall(handler, cbidOnProcessingInstruction, 2, rtarget, rdata);
168
+ }
169
+ }
170
+
171
+ static void reference_callback(void *ctx, const char *name)
172
+ {
173
+ VALUE handler = (VALUE) ctx;
174
+
175
+ if (handler != Qnil)
176
+ {
177
+ rb_funcall(handler, cbidOnReference,1,rb_str_new2(name));
178
+ }
179
+ }
180
+
181
+ static void start_document_callback(void *ctx)
182
+ {
183
+ VALUE handler = (VALUE) ctx;
184
+
185
+ if (handler != Qnil)
186
+ {
187
+ rb_funcall(handler, cbidOnStartDocument, 0);
188
+ }
189
+ }
190
+
191
+ static void start_element_ns_callback(void *ctx,
192
+ const xmlChar *xlocalname, const xmlChar *xprefix, const xmlChar *xURI,
193
+ int nb_namespaces, const xmlChar **xnamespaces,
194
+ int nb_attributes, int nb_defaulted, const xmlChar **xattributes)
195
+ {
196
+ VALUE handler = (VALUE) ctx;
197
+ VALUE attributes = rb_hash_new();
198
+ VALUE namespaces = rb_hash_new();
199
+
200
+ if (handler == Qnil)
201
+ return;
202
+
203
+ if (xattributes)
204
+ {
205
+ /* Each attribute is an array of [localname, prefix, URI, value, end] */
206
+ int i;
207
+ for (i = 0;i < nb_attributes * 5; i+=5)
208
+ {
209
+ VALUE attrName = rb_str_new2(xattributes[i+0]);
210
+ VALUE attrValue = rb_str_new(xattributes[i+3], xattributes[i+4] - xattributes[i+3]);
211
+ /* VALUE attrPrefix = xattributes[i+1] ? rb_str_new2(xattributes[i+1]) : Qnil;
212
+ VALUE attrURI = xattributes[i+2] ? rb_str_new2(xattributes[i+2]) : Qnil; */
213
+
214
+ rb_hash_aset(attributes, attrName, attrValue);
215
+ }
216
+ }
217
+
218
+ if (xnamespaces)
219
+ {
220
+ int i;
221
+ for (i = 0;i < nb_namespaces * 2; i+=2)
222
+ {
223
+ VALUE nsPrefix = xnamespaces[i+0] ? rb_str_new2(xnamespaces[i+0]) : Qnil;
224
+ VALUE nsURI = xnamespaces[i+1] ? rb_str_new2(xnamespaces[i+1]) : Qnil;
225
+ rb_hash_aset(namespaces, nsPrefix, nsURI);
226
+ }
227
+ }
228
+
229
+ /* Call start element for old-times sake */
230
+ if (rb_respond_to(handler, cbidOnStartElement))
231
+ {
232
+ VALUE name;
233
+ if (xprefix)
234
+ {
235
+ name = rb_str_new2(xprefix);
236
+ rb_str_cat2(name, ":");
237
+ rb_str_cat2(name, xlocalname);
238
+ }
239
+ else
240
+ {
241
+ name = rb_str_new2(xlocalname);
242
+ }
243
+ rb_funcall(handler, cbidOnStartElement, 2, name, attributes);
244
+ }
245
+
246
+ rb_funcall(handler, cbidOnStartElementNs, 5,
247
+ rb_str_new2(xlocalname),
248
+ attributes,
249
+ xprefix ? rb_str_new2(xprefix) : Qnil,
250
+ xURI ? rb_str_new2(xURI) : Qnil,
251
+ namespaces);
252
+ }
253
+
254
+ static void structured_error_callback(void *ctx, xmlErrorPtr xerror)
255
+ {
256
+ /* Older versions of Libxml will pass a NULL context from the sax parser. Fixed on
257
+ Feb 23, 2011. See:
258
+
259
+ http://git.gnome.org/browse/libxml2/commit/?id=241d4a1069e6bedd0ee2295d7b43858109c1c6d1 */
260
+
261
+ VALUE handler;
262
+
263
+ #if LIBXML_VERSION <= 20708
264
+ xmlParserCtxtPtr ctxt = (xmlParserCtxt*)(xerror->ctxt);
265
+ ctx = ctxt->userData;
266
+ #endif
267
+
268
+ handler = (VALUE) ctx;
269
+
270
+ if (handler != Qnil)
271
+ {
272
+ VALUE error = rxml_error_wrap(xerror);
273
+ rb_funcall(handler, cbidOnError, 1, error);
274
+ }
275
+ }
276
+
277
+ /* ====== Handler =========== */
278
+ xmlSAXHandler rxml_sax_handler = {
279
+ (internalSubsetSAXFunc) internal_subset_callback,
280
+ (isStandaloneSAXFunc) is_standalone_callback,
281
+ (hasInternalSubsetSAXFunc) has_internal_subset_callback,
282
+ (hasExternalSubsetSAXFunc) has_external_subset_callback,
283
+ 0, /* resolveEntity */
284
+ 0, /* getEntity */
285
+ 0, /* entityDecl */
286
+ 0, /* notationDecl */
287
+ 0, /* attributeDecl */
288
+ 0, /* elementDecl */
289
+ 0, /* unparsedEntityDecl */
290
+ 0, /* setDocumentLocator */
291
+ (startDocumentSAXFunc) start_document_callback,
292
+ (endDocumentSAXFunc) end_document_callback,
293
+ 0, /* Use start_element_ns_callback instead */
294
+ 0, /* Use end_element_ns_callback instead */
295
+ (referenceSAXFunc) reference_callback,
296
+ (charactersSAXFunc) characters_callback,
297
+ 0, /* ignorableWhitespace */
298
+ (processingInstructionSAXFunc) processing_instruction_callback,
299
+ (commentSAXFunc) comment_callback,
300
+ 0, /* xmlStructuredErrorFunc is used instead */
301
+ 0, /* xmlStructuredErrorFunc is used instead */
302
+ 0, /* xmlStructuredErrorFunc is used instead */
303
+ 0, /* xmlGetParameterEntity */
304
+ (cdataBlockSAXFunc) cdata_block_callback,
305
+ (externalSubsetSAXFunc) external_subset_callback,
306
+ XML_SAX2_MAGIC, /* force SAX2 */
307
+ 0, /* _private */
308
+ (startElementNsSAX2Func) start_element_ns_callback,
309
+ (endElementNsSAX2Func) end_element_ns_callback,
310
+ (xmlStructuredErrorFunc) structured_error_callback
311
+ };
312
+
313
+ void rxml_init_sax2_handler(void)
314
+ {
315
+
316
+ /* SaxCallbacks */
317
+ cbidOnCdataBlock = rb_intern("on_cdata_block");
318
+ cbidOnCharacters = rb_intern("on_characters");
319
+ cbidOnComment = rb_intern("on_comment");
320
+ cbidOnEndDocument = rb_intern("on_end_document");
321
+ cbidOnEndElement = rb_intern("on_end_element");
322
+ cbidOnEndElementNs = rb_intern("on_end_element_ns");
323
+ cbidOnError = rb_intern("on_error");
324
+ cbidOnExternalSubset = rb_intern("on_external_subset");
325
+ cbidOnHasExternalSubset = rb_intern("on_has_external_subset");
326
+ cbidOnHasInternalSubset = rb_intern("on_has_internal_subset");
327
+ cbidOnInternalSubset = rb_intern("on_internal_subset");
328
+ cbidOnIsStandalone = rb_intern("on_is_standalone");
329
+ cbidOnProcessingInstruction = rb_intern("on_processing_instruction");
330
+ cbidOnReference = rb_intern("on_reference");
331
+ cbidOnStartElement = rb_intern("on_start_element");
332
+ cbidOnStartElementNs = rb_intern("on_start_element_ns");
333
+ cbidOnStartDocument = rb_intern("on_start_document");
334
+ }