libxml-ruby 0.9.2-x86-mswin32-60 → 0.9.3-x86-mswin32-60

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. data/CHANGES +13 -0
  2. data/ext/libxml/libxml.c +885 -886
  3. data/ext/libxml/ruby_libxml.h +70 -72
  4. data/ext/libxml/ruby_xml_attr.c +76 -76
  5. data/ext/libxml/ruby_xml_attr.h +8 -8
  6. data/ext/libxml/ruby_xml_attributes.c +36 -36
  7. data/ext/libxml/ruby_xml_attributes.h +6 -6
  8. data/ext/libxml/ruby_xml_document.c +133 -220
  9. data/ext/libxml/ruby_xml_document.h +4 -7
  10. data/ext/libxml/ruby_xml_dtd.c +30 -109
  11. data/ext/libxml/ruby_xml_dtd.h +2 -11
  12. data/ext/libxml/ruby_xml_error.c +10 -10
  13. data/ext/libxml/ruby_xml_error.h +4 -4
  14. data/ext/libxml/ruby_xml_html_parser.c +28 -40
  15. data/ext/libxml/ruby_xml_html_parser.h +4 -4
  16. data/ext/libxml/ruby_xml_input.c +208 -32
  17. data/ext/libxml/ruby_xml_input.h +7 -5
  18. data/ext/libxml/ruby_xml_input_cbg.c +3 -3
  19. data/ext/libxml/ruby_xml_node.c +217 -217
  20. data/ext/libxml/ruby_xml_node.h +5 -5
  21. data/ext/libxml/ruby_xml_ns.c +26 -26
  22. data/ext/libxml/ruby_xml_ns.h +4 -4
  23. data/ext/libxml/ruby_xml_parser.c +151 -164
  24. data/ext/libxml/ruby_xml_parser.h +3 -8
  25. data/ext/libxml/ruby_xml_parser_context.c +105 -105
  26. data/ext/libxml/ruby_xml_parser_context.h +4 -4
  27. data/ext/libxml/ruby_xml_reader.c +145 -162
  28. data/ext/libxml/ruby_xml_reader.h +4 -4
  29. data/ext/libxml/ruby_xml_relaxng.c +30 -43
  30. data/ext/libxml/ruby_xml_relaxng.h +2 -7
  31. data/ext/libxml/ruby_xml_sax_parser.c +174 -228
  32. data/ext/libxml/ruby_xml_sax_parser.h +12 -20
  33. data/ext/libxml/ruby_xml_schema.c +31 -44
  34. data/ext/libxml/ruby_xml_schema.h +2 -7
  35. data/ext/libxml/ruby_xml_state.c +6 -6
  36. data/ext/libxml/ruby_xml_state.h +2 -2
  37. data/ext/libxml/ruby_xml_xinclude.c +1 -1
  38. data/ext/libxml/ruby_xml_xinclude.h +3 -3
  39. data/ext/libxml/ruby_xml_xpath.c +1 -1
  40. data/ext/libxml/ruby_xml_xpath.h +3 -12
  41. data/ext/libxml/ruby_xml_xpath_context.c +293 -294
  42. data/ext/libxml/ruby_xml_xpath_context.h +3 -7
  43. data/ext/libxml/ruby_xml_xpath_expression.c +11 -11
  44. data/ext/libxml/ruby_xml_xpath_expression.h +2 -2
  45. data/ext/libxml/ruby_xml_xpath_object.c +52 -66
  46. data/ext/libxml/ruby_xml_xpath_object.h +3 -14
  47. data/ext/libxml/ruby_xml_xpointer.c +11 -12
  48. data/ext/libxml/ruby_xml_xpointer.h +5 -7
  49. data/ext/libxml/sax_parser_callbacks.inc +53 -36
  50. data/ext/libxml/version.h +2 -2
  51. data/ext/mingw/libxml_ruby.dll.a +0 -0
  52. data/ext/mingw/libxml_ruby.so +0 -0
  53. data/ext/vc/libxml_ruby.vcproj +1 -9
  54. data/lib/libxml/html_parser.rb +5 -5
  55. data/lib/libxml/parser.rb +4 -4
  56. data/lib/libxml/sax_parser.rb +24 -0
  57. data/test/tc_document_write.rb +2 -16
  58. data/test/tc_html_parser.rb +57 -5
  59. data/test/tc_input.rb +13 -0
  60. data/test/tc_parser.rb +11 -3
  61. data/test/tc_reader.rb +53 -34
  62. data/test/tc_sax_parser.rb +30 -8
  63. data/test/test.rb +8 -0
  64. data/test/test_suite.rb +1 -1
  65. metadata +5 -6
  66. data/ext/libxml/ruby_xml_encoding.c +0 -164
  67. data/ext/libxml/ruby_xml_encoding.h +0 -13
  68. data/test/tc_encoding.rb +0 -13
@@ -1,14 +1,14 @@
1
1
  /* Copyright (c) 2006 Apple Computer Inc.
2
2
  * Please see the LICENSE file for copyright and distribution information. */
3
3
 
4
- #ifndef __RUBY_XML_READER__
5
- #define __RUBY_XML_READER__
4
+ #ifndef __rxml_READER__
5
+ #define __rxml_READER__
6
6
 
7
7
  extern VALUE cXMLReader;
8
8
 
9
9
  void ruby_init_xml_reader(void);
10
10
 
11
11
  /* Exported to be used by XML::Document#reader */
12
- VALUE ruby_xml_reader_new_walker(VALUE self, VALUE doc);
12
+ VALUE rxml_reader_new_walker(VALUE self, VALUE doc);
13
13
 
14
- #endif /* __RUBY_XML_READER__ */
14
+ #endif /* __rxml_READER__ */
@@ -39,18 +39,8 @@ VALUE cXMLRelaxNG;
39
39
  #endif
40
40
 
41
41
  static void
42
- ruby_xml_relaxng_mark(ruby_xml_relaxng *rxrelaxng) {
43
- return;
44
- }
45
-
46
- void
47
- ruby_xml_relaxng_free(ruby_xml_relaxng *rxrelaxng) {
48
- if (rxrelaxng->relaxng != NULL) {
49
- xmlRelaxNGFree(rxrelaxng->relaxng);
50
- rxrelaxng->relaxng = NULL;
51
- }
52
-
53
- ruby_xfree(rxrelaxng);
42
+ rxml_relaxng_free(xmlRelaxNGPtr xrelaxng) {
43
+ xmlRelaxNGFree(xrelaxng);
54
44
  }
55
45
 
56
46
  /*
@@ -59,19 +49,18 @@ ruby_xml_relaxng_free(ruby_xml_relaxng *rxrelaxng) {
59
49
  *
60
50
  * Create a new relaxng from the specified URI.
61
51
  */
62
- VALUE
63
- ruby_xml_relaxng_init_from_uri(VALUE class, VALUE uri) {
64
- xmlRelaxNGParserCtxtPtr parser;
65
- ruby_xml_relaxng *relaxng;
52
+ static VALUE
53
+ rxml_relaxng_init_from_uri(VALUE class, VALUE uri) {
54
+ xmlRelaxNGParserCtxtPtr xparser;
55
+ xmlRelaxNGPtr xrelaxng;
66
56
 
67
57
  Check_Type(uri, T_STRING);
68
58
 
69
- parser = xmlRelaxNGNewParserCtxt(StringValuePtr(uri));
70
- relaxng = ALLOC(ruby_xml_relaxng);
71
- relaxng->relaxng = xmlRelaxNGParse(parser);
72
- xmlRelaxNGFreeParserCtxt(parser);
59
+ xparser = xmlRelaxNGNewParserCtxt(StringValuePtr(uri));
60
+ xrelaxng = xmlRelaxNGParse(xparser);
61
+ xmlRelaxNGFreeParserCtxt(xparser);
73
62
 
74
- return Data_Wrap_Struct(cXMLRelaxNG, ruby_xml_relaxng_mark, ruby_xml_relaxng_free, relaxng);
63
+ return Data_Wrap_Struct(cXMLRelaxNG, NULL, rxml_relaxng_free, xrelaxng);
75
64
  }
76
65
 
77
66
  /*
@@ -80,20 +69,19 @@ ruby_xml_relaxng_init_from_uri(VALUE class, VALUE uri) {
80
69
  *
81
70
  * Create a new relaxng from the specified document.
82
71
  */
83
- VALUE
84
- ruby_xml_relaxng_init_from_document(VALUE class, VALUE document) {
72
+ static VALUE
73
+ rxml_relaxng_init_from_document(VALUE class, VALUE document) {
85
74
  xmlDocPtr xdoc;
86
- ruby_xml_relaxng *relaxng;
87
- xmlRelaxNGParserCtxtPtr parser;
75
+ xmlRelaxNGPtr xrelaxng;
76
+ xmlRelaxNGParserCtxtPtr xparser;
88
77
 
89
78
  Data_Get_Struct(document, xmlDoc, xdoc);
90
79
 
91
- parser = xmlRelaxNGNewDocParserCtxt(xdoc);
92
- relaxng = ALLOC(ruby_xml_relaxng);
93
- relaxng->relaxng = xmlRelaxNGParse(parser);
94
- xmlRelaxNGFreeParserCtxt(parser);
80
+ xparser = xmlRelaxNGNewDocParserCtxt(xdoc);
81
+ xrelaxng = xmlRelaxNGParse(xparser);
82
+ xmlRelaxNGFreeParserCtxt(xparser);
95
83
 
96
- return Data_Wrap_Struct(cXMLRelaxNG, ruby_xml_relaxng_mark, ruby_xml_relaxng_free, relaxng);
84
+ return Data_Wrap_Struct(cXMLRelaxNG, NULL, rxml_relaxng_free, xrelaxng);
97
85
  }
98
86
 
99
87
  /*
@@ -102,25 +90,24 @@ ruby_xml_relaxng_init_from_document(VALUE class, VALUE document) {
102
90
  *
103
91
  * Create a new relaxng using the specified string.
104
92
  */
105
- VALUE
106
- ruby_xml_relaxng_init_from_string(VALUE self, VALUE relaxng_str) {
107
- xmlRelaxNGParserCtxtPtr parser;
108
- ruby_xml_relaxng *rxrelaxng;
93
+ static VALUE
94
+ rxml_relaxng_init_from_string(VALUE self, VALUE relaxng_str) {
95
+ xmlRelaxNGParserCtxtPtr xparser;
96
+ xmlRelaxNGPtr xrelaxng;
109
97
 
110
98
  Check_Type(relaxng_str, T_STRING);
111
99
 
112
- parser = xmlRelaxNGNewMemParserCtxt(StringValuePtr(relaxng_str), strlen(StringValuePtr(relaxng_str)));
113
- rxrelaxng = ALLOC(ruby_xml_relaxng);
114
- rxrelaxng->relaxng = xmlRelaxNGParse(parser);
115
- xmlRelaxNGFreeParserCtxt(parser);
100
+ xparser = xmlRelaxNGNewMemParserCtxt(StringValuePtr(relaxng_str), strlen(StringValuePtr(relaxng_str)));
101
+ xrelaxng = xmlRelaxNGParse(xparser);
102
+ xmlRelaxNGFreeParserCtxt(xparser);
116
103
 
117
- return Data_Wrap_Struct(cXMLRelaxNG, ruby_xml_relaxng_mark, ruby_xml_relaxng_free, rxrelaxng);
104
+ return Data_Wrap_Struct(cXMLRelaxNG, NULL, rxml_relaxng_free, xrelaxng);
118
105
  }
119
106
 
120
- void ruby_init_xml_relaxng(void) {
107
+ void ruby_init_xml_relaxng(void) {
121
108
  cXMLRelaxNG = rb_define_class_under(mXML, "RelaxNG", rb_cObject);
122
- rb_define_singleton_method(cXMLRelaxNG, "new", ruby_xml_relaxng_init_from_uri, 1);
123
- rb_define_singleton_method(cXMLRelaxNG, "from_string", ruby_xml_relaxng_init_from_string, 1);
124
- rb_define_singleton_method(cXMLRelaxNG, "document", ruby_xml_relaxng_init_from_document, 1);
109
+ rb_define_singleton_method(cXMLRelaxNG, "new", rxml_relaxng_init_from_uri, 1);
110
+ rb_define_singleton_method(cXMLRelaxNG, "from_string", rxml_relaxng_init_from_string, 1);
111
+ rb_define_singleton_method(cXMLRelaxNG, "document", rxml_relaxng_init_from_document, 1);
125
112
  }
126
113
 
@@ -1,15 +1,10 @@
1
- #ifndef __RUBY_XML_RELAXNG__
2
- #define __RUBY_XML_RELAXNG__
1
+ #ifndef __rxml_RELAXNG__
2
+ #define __rxml_RELAXNG__
3
3
 
4
4
  #include <libxml/relaxng.h>
5
5
 
6
6
  extern VALUE cXMLRelaxNG;
7
7
 
8
- typedef struct rxp_relaxng {
9
- xmlRelaxNGPtr relaxng; /* RelaxNG interface */
10
- } ruby_xml_relaxng;
11
-
12
8
  void ruby_init_xml_relaxng(void);
13
- void ruby_relaxng_free(ruby_xml_relaxng *rxs);
14
9
  #endif
15
10
 
@@ -1,228 +1,174 @@
1
- /* $Id: ruby_xml_sax_parser.c 604 2008-11-19 18:01:55Z cfis $ */
2
-
3
- /* Please see the LICENSE file for copyright and distribution information */
4
-
5
- #include "ruby_libxml.h"
6
- #include "ruby_xml_sax_parser.h"
7
-
8
- /*
9
- * Document-class: LibXML::XML::SaxParser
10
- *
11
- * XML::SaxParser provides a callback based API for parsing documents,
12
- * in contrast to XML::Parser's tree based API and XML::Reader's stream
13
- * based API.
14
- *
15
- * Note that the XML::SaxParser API is fairly complex, not well standardized,
16
- * and does not directly support validation making entity, namespace and
17
- * base processing relatively hard.
18
- *
19
- * To use the XML::SaxParser, register a callback class via the
20
- * XML::SaxParser#callbacks=. It is easiest to include the
21
- * XML::SaxParser::Callbacks module in your class and override
22
- * the methods as needed.
23
- *
24
- * Basic example:
25
- *
26
- * class MyCallbacks
27
- * include XML::SaxParser::Callbacks
28
- * def on_start_element(element, attributes)
29
- * puts #Element started: #{element}"
30
- * end
31
- * end
32
- *
33
- * parser = XML::SaxParser.new
34
- * parser.callbacks = MyCallbacks.new
35
- * parser.parse
36
- */
37
-
38
- VALUE cXMLSaxParser;
39
- VALUE mXMLSaxParserCallbacks;
40
-
41
- static ID INPUT_ATTR;
42
-
43
- VALUE cbidOnInternalSubset;
44
- VALUE cbidOnIsStandalone;
45
- VALUE cbidOnHasInternalSubset;
46
- VALUE cbidOnHasExternalSubset;
47
- VALUE cbidOnStartDocument;
48
- VALUE cbidOnEndDocument;
49
- VALUE cbidOnStartElement;
50
- VALUE cbidOnEndElement;
51
- VALUE cbidOnReference;
52
- VALUE cbidOnCharacters;
53
- VALUE cbidOnProcessingInstruction;
54
- VALUE cbidOnComment;
55
- VALUE cbidOnXmlParserWarning;
56
- VALUE cbidOnXmlParserError;
57
- VALUE cbidOnXmlParserFatalError;
58
- VALUE cbidOnCdataBlock;
59
- VALUE cbidOnExternalSubset;
60
-
61
- #include "sax_parser_callbacks.inc"
62
-
63
- void
64
- ruby_xml_sax_parser_free(ruby_xml_sax_parser *rxsp) {
65
- xfree(rxsp);
66
- }
67
-
68
- void
69
- ruby_xml_sax_parser_mark(ruby_xml_sax_parser *rxsp) {
70
- if (rxsp->callbackHandler != Qnil) {
71
- rb_gc_mark(rxsp->callbackHandler);
72
- }
73
-
74
- if (rxsp->filename != Qnil) {
75
- rb_gc_mark(rxsp->filename);
76
- }
77
-
78
- if (rxsp->str != Qnil) {
79
- rb_gc_mark(rxsp->str);
80
- }
81
- }
82
-
83
- VALUE
84
- ruby_xml_sax_parser_alloc(VALUE klass) {
85
- ruby_xml_sax_parser *rxsp = ALLOC(ruby_xml_sax_parser);
86
- rxsp->xsh = &rubySAXHandlerStruct;
87
- rxsp->callbackHandler = Qnil;
88
- rxsp->xpc = NULL;
89
- rxsp->filename = Qnil;
90
- rxsp->str = Qnil;
91
-
92
- return Data_Wrap_Struct(cXMLSaxParser,
93
- ruby_xml_sax_parser_mark, ruby_xml_sax_parser_free,
94
- rxsp);
95
- }
96
-
97
-
98
- /*
99
- * call-seq:
100
- * sax_parser.initialize -> sax_parser
101
- *
102
- * Initiliazes instance of parser.
103
- */
104
- VALUE
105
- ruby_xml_sax_parser_initialize(VALUE self) {
106
- VALUE input = rb_class_new_instance(0, NULL, cXMLInput);
107
- rb_iv_set(self, "@input", input);
108
- return self;
109
- }
110
-
111
- /*
112
- * call-seq:
113
- * sax_parser.callbacks -> #<XML::SaxParser::Callbacks subclass>
114
- *
115
- * Obtain the callbacks used by this parser.
116
- */
117
- VALUE
118
- ruby_xml_sax_parser_callbacks_get(VALUE self) {
119
- ruby_xml_sax_parser *rxsp;
120
- Data_Get_Struct(self, ruby_xml_sax_parser, rxsp);
121
- return(rxsp->callbackHandler);
122
- }
123
-
124
-
125
- /*
126
- * call-seq:
127
- * sax_parser.callbacks = #<XML::SaxParser::Callbacks subclass>
128
- *
129
- * Set the callbacks used by this parser. The value assigned to
130
- * this attributesibute will usually be an object that extends the the
131
- * XML::SaxParser::Callbacks module, overriding the callbacks it
132
- * wishes to process.
133
- */
134
- VALUE
135
- ruby_xml_sax_parser_callbacks_set(VALUE self, VALUE callbacks) {
136
- ruby_xml_sax_parser *rxsp;
137
- Data_Get_Struct(self, ruby_xml_sax_parser, rxsp);
138
- rxsp->callbackHandler = callbacks;
139
- return(rxsp->callbackHandler);
140
- }
141
-
142
- /*
143
- * call-seq:
144
- * parser.parse -> (true|false)
145
- *
146
- * Parse the input XML, generating callbacks to the object
147
- * registered via the +callbacks+ attributesibute.
148
- */
149
- VALUE
150
- ruby_xml_sax_parser_parse(VALUE self) {
151
- char *str;
152
- int status = 1;
153
- ruby_xml_sax_parser *rxsp;
154
- VALUE source;
155
- VALUE input = rb_ivar_get(self, INPUT_ATTR);
156
-
157
- Data_Get_Struct(self, ruby_xml_sax_parser, rxsp);
158
-
159
- if (rb_ivar_get(input, FILE_ATTR) != Qnil)
160
- {
161
- source = rb_ivar_get(input, FILE_ATTR);
162
- status = xmlSAXUserParseFile(rxsp->xsh, rxsp, StringValuePtr(source));
163
- }
164
- else if (rb_ivar_get(input, STRING_ATTR) != Qnil)
165
- {
166
- source = rb_ivar_get(input, STRING_ATTR);
167
- str = StringValueCStr(source);
168
- status = xmlSAXUserParseMemory(rxsp->xsh, rxsp, str, strlen(str));
169
- }
170
- else
171
- {
172
- rb_raise(rb_eArgError, "You must specify a parser data source");
173
- }
174
-
175
- if (status)
176
- {
177
- ruby_xml_raise(&xmlLastError);
178
- return Qfalse;
179
- }
180
- else
181
- {
182
- return(Qtrue);
183
- }
184
- }
185
-
186
- // Rdoc needs to know
187
- #ifdef RDOC_NEVER_DEFINED
188
- mLibXML = rb_define_module("LibXML");
189
- mXML = rb_define_module_under(mLibXML, "XML");
190
- #endif
191
-
192
- void
193
- ruby_init_xml_sax_parser(void) {
194
- /* SaxParser */
195
- cXMLSaxParser = rb_define_class_under(mXML, "SaxParser", rb_cObject);
196
- rb_define_alloc_func(cXMLSaxParser, ruby_xml_sax_parser_alloc);
197
- rb_define_method(cXMLSaxParser, "callbacks", ruby_xml_sax_parser_callbacks_get, 0);
198
- rb_define_method(cXMLSaxParser, "callbacks=", ruby_xml_sax_parser_callbacks_set, 1);
199
- rb_define_method(cXMLSaxParser, "parse", ruby_xml_sax_parser_parse, 0);
200
-
201
- /* Atributes */
202
- rb_define_attr(cXMLSaxParser, "input", 1, 0);
203
-
204
- /* Instance Methods */
205
- rb_define_method(cXMLSaxParser, "initialize", ruby_xml_sax_parser_initialize, 0);
206
-
207
-
208
- INPUT_ATTR = rb_intern("@input");
209
-
210
- /* SaxCallbacks */
211
- cbidOnInternalSubset = rb_intern("on_internal_subset");
212
- cbidOnIsStandalone = rb_intern("on_is_standalone");
213
- cbidOnHasInternalSubset = rb_intern("on_has_internal_subset");
214
- cbidOnHasExternalSubset = rb_intern("on_has_external_subset");
215
- cbidOnStartDocument = rb_intern("on_start_document");
216
- cbidOnEndDocument = rb_intern("on_end_document");
217
- cbidOnStartElement = rb_intern("on_start_element");
218
- cbidOnEndElement = rb_intern("on_end_element");
219
- cbidOnReference = rb_intern("on_reference");
220
- cbidOnCharacters = rb_intern("on_characters");
221
- cbidOnProcessingInstruction = rb_intern("on_processing_instruction");
222
- cbidOnComment = rb_intern("on_comment");
223
- cbidOnXmlParserWarning = rb_intern("on_parser_warning");
224
- cbidOnXmlParserError = rb_intern("on_parser_error");
225
- cbidOnXmlParserFatalError = rb_intern("on_parser_fatal_error");
226
- cbidOnCdataBlock = rb_intern("on_cdata_block");
227
- cbidOnExternalSubset = rb_intern("on_external_subset");
228
- }
1
+ /* $Id: ruby_xml_sax_parser.c 616 2008-11-22 09:25:12Z cfis $ */
2
+
3
+ /* Please see the LICENSE file for copyright and distribution information */
4
+
5
+ #include "ruby_libxml.h"
6
+ #include "ruby_xml_sax_parser.h"
7
+
8
+ /*
9
+ * Document-class: LibXML::XML::SaxParser
10
+ *
11
+ * XML::SaxParser provides a callback based API for parsing documents,
12
+ * in contrast to XML::Parser's tree based API and XML::Reader's stream
13
+ * based API.
14
+ *
15
+ * Note that the XML::SaxParser API is fairly complex, not well standardized,
16
+ * and does not directly support validation making entity, namespace and
17
+ * base processing relatively hard.
18
+ *
19
+ * To use the XML::SaxParser, register a callback class via the
20
+ * XML::SaxParser#callbacks=. It is easiest to include the
21
+ * XML::SaxParser::Callbacks module in your class and override
22
+ * the methods as needed.
23
+ *
24
+ * Basic example:
25
+ *
26
+ * class MyCallbacks
27
+ * include XML::SaxParser::Callbacks
28
+ * def on_start_element(element, attributes)
29
+ * puts #Element started: #{element}"
30
+ * end
31
+ * end
32
+ *
33
+ * parser = XML::SaxParser.new
34
+ * parser.callbacks = MyCallbacks.new
35
+ * parser.parse
36
+ */
37
+
38
+ VALUE cXMLSaxParser;
39
+ VALUE mXMLSaxParserCallbacks;
40
+
41
+ static ID INPUT_ATTR;
42
+ static ID CALLBACKS_ATTR;
43
+
44
+ VALUE cbidOnInternalSubset;
45
+ VALUE cbidOnIsStandalone;
46
+ VALUE cbidOnHasInternalSubset;
47
+ VALUE cbidOnHasExternalSubset;
48
+ VALUE cbidOnStartDocument;
49
+ VALUE cbidOnEndDocument;
50
+ VALUE cbidOnStartElement;
51
+ VALUE cbidOnEndElement;
52
+ VALUE cbidOnReference;
53
+ VALUE cbidOnCharacters;
54
+ VALUE cbidOnProcessingInstruction;
55
+ VALUE cbidOnComment;
56
+ VALUE cbidOnXmlParserWarning;
57
+ VALUE cbidOnXmlParserError;
58
+ VALUE cbidOnXmlParserFatalError;
59
+ VALUE cbidOnCdataBlock;
60
+ VALUE cbidOnExternalSubset;
61
+
62
+ #include "sax_parser_callbacks.inc"
63
+
64
+ /*
65
+ * call-seq:
66
+ * sax_parser.initialize -> sax_parser
67
+ *
68
+ * Initiliazes instance of parser.
69
+ */
70
+ static VALUE
71
+ rxml_sax_parser_initialize(VALUE self) {
72
+ VALUE input = rb_class_new_instance(0, NULL, cXMLInput);
73
+ rb_iv_set(self, "@input", input);
74
+ return self;
75
+ }
76
+
77
+
78
+ /* Parsing data sources */
79
+ static int
80
+ rxml_sax_parser_parse_file(VALUE self, VALUE input) {
81
+ VALUE file = rb_ivar_get(input, FILE_ATTR);
82
+ return xmlSAXUserParseFile(&rxml_sax_hander_struct, self, StringValuePtr(file));
83
+ }
84
+
85
+ static int
86
+ rxml_sax_parser_parse_string(VALUE self, VALUE input) {
87
+ VALUE str = rb_ivar_get(input, STRING_ATTR);
88
+ return xmlSAXUserParseMemory(&rxml_sax_hander_struct, self, StringValuePtr(str), RSTRING_LEN(str));
89
+ }
90
+
91
+ static int
92
+ rxml_sax_parser_parse_io(VALUE self, VALUE input) {
93
+ VALUE io = rb_ivar_get(input, IO_ATTR);
94
+ VALUE encoding = rb_ivar_get(input, ENCODING_ATTR);
95
+ xmlCharEncoding xmlEncoding = NUM2INT(encoding);
96
+ xmlParserCtxtPtr ctxt = xmlCreateIOParserCtxt(&rxml_sax_hander_struct, self,
97
+ (xmlInputReadCallback) rxml_read_callback,
98
+ NULL, io, xmlEncoding);
99
+ return xmlParseDocument(ctxt);
100
+ }
101
+
102
+
103
+ /*
104
+ * call-seq:
105
+ * parser.parse -> (true|false)
106
+ *
107
+ * Parse the input XML, generating callbacks to the object
108
+ * registered via the +callbacks+ attributesibute.
109
+ */
110
+ static VALUE
111
+ rxml_sax_parser_parse(VALUE self) {
112
+ int status;
113
+ VALUE input = rb_ivar_get(self, INPUT_ATTR);
114
+
115
+ if (rb_ivar_get(input, FILE_ATTR) != Qnil)
116
+ status = rxml_sax_parser_parse_file(self, input);
117
+ else if (rb_ivar_get(input, STRING_ATTR) != Qnil)
118
+ status = rxml_sax_parser_parse_string(self, input);
119
+ else if (rb_ivar_get(input, IO_ATTR) != Qnil)
120
+ status = rxml_sax_parser_parse_io(self, input);
121
+ else
122
+ rb_raise(rb_eArgError, "You must specify a parser data source");
123
+
124
+ if (status)
125
+ {
126
+ rxml_raise(&xmlLastError);
127
+ return Qfalse;
128
+ }
129
+ else
130
+ {
131
+ return(Qtrue);
132
+ }
133
+ }
134
+
135
+ // Rdoc needs to know
136
+ #ifdef RDOC_NEVER_DEFINED
137
+ mLibXML = rb_define_module("LibXML");
138
+ mXML = rb_define_module_under(mLibXML, "XML");
139
+ #endif
140
+
141
+ void
142
+ ruby_init_xml_sax_parser(void) {
143
+ /* SaxParser */
144
+ cXMLSaxParser = rb_define_class_under(mXML, "SaxParser", rb_cObject);
145
+
146
+ /* Atributes */
147
+ CALLBACKS_ATTR = rb_intern("@callbacks");
148
+ INPUT_ATTR = rb_intern("@input");
149
+ rb_define_attr(cXMLSaxParser, "callbacks", 1, 1);
150
+ rb_define_attr(cXMLSaxParser, "input", 1, 0);
151
+
152
+ /* Instance Methods */
153
+ rb_define_method(cXMLSaxParser, "initialize", rxml_sax_parser_initialize, 0);
154
+ rb_define_method(cXMLSaxParser, "parse", rxml_sax_parser_parse, 0);
155
+
156
+ /* SaxCallbacks */
157
+ cbidOnInternalSubset = rb_intern("on_internal_subset");
158
+ cbidOnIsStandalone = rb_intern("on_is_standalone");
159
+ cbidOnHasInternalSubset = rb_intern("on_has_internal_subset");
160
+ cbidOnHasExternalSubset = rb_intern("on_has_external_subset");
161
+ cbidOnStartDocument = rb_intern("on_start_document");
162
+ cbidOnEndDocument = rb_intern("on_end_document");
163
+ cbidOnStartElement = rb_intern("on_start_element");
164
+ cbidOnEndElement = rb_intern("on_end_element");
165
+ cbidOnReference = rb_intern("on_reference");
166
+ cbidOnCharacters = rb_intern("on_characters");
167
+ cbidOnProcessingInstruction = rb_intern("on_processing_instruction");
168
+ cbidOnComment = rb_intern("on_comment");
169
+ cbidOnXmlParserWarning = rb_intern("on_parser_warning");
170
+ cbidOnXmlParserError = rb_intern("on_parser_error");
171
+ cbidOnXmlParserFatalError = rb_intern("on_parser_fatal_error");
172
+ cbidOnCdataBlock = rb_intern("on_cdata_block");
173
+ cbidOnExternalSubset = rb_intern("on_external_subset");
174
+ }