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.
- data/CHANGES +13 -0
- data/ext/libxml/libxml.c +885 -886
- data/ext/libxml/ruby_libxml.h +70 -72
- data/ext/libxml/ruby_xml_attr.c +76 -76
- data/ext/libxml/ruby_xml_attr.h +8 -8
- data/ext/libxml/ruby_xml_attributes.c +36 -36
- data/ext/libxml/ruby_xml_attributes.h +6 -6
- data/ext/libxml/ruby_xml_document.c +133 -220
- data/ext/libxml/ruby_xml_document.h +4 -7
- data/ext/libxml/ruby_xml_dtd.c +30 -109
- data/ext/libxml/ruby_xml_dtd.h +2 -11
- data/ext/libxml/ruby_xml_error.c +10 -10
- data/ext/libxml/ruby_xml_error.h +4 -4
- data/ext/libxml/ruby_xml_html_parser.c +28 -40
- data/ext/libxml/ruby_xml_html_parser.h +4 -4
- data/ext/libxml/ruby_xml_input.c +208 -32
- data/ext/libxml/ruby_xml_input.h +7 -5
- data/ext/libxml/ruby_xml_input_cbg.c +3 -3
- data/ext/libxml/ruby_xml_node.c +217 -217
- data/ext/libxml/ruby_xml_node.h +5 -5
- data/ext/libxml/ruby_xml_ns.c +26 -26
- data/ext/libxml/ruby_xml_ns.h +4 -4
- data/ext/libxml/ruby_xml_parser.c +151 -164
- data/ext/libxml/ruby_xml_parser.h +3 -8
- data/ext/libxml/ruby_xml_parser_context.c +105 -105
- data/ext/libxml/ruby_xml_parser_context.h +4 -4
- data/ext/libxml/ruby_xml_reader.c +145 -162
- data/ext/libxml/ruby_xml_reader.h +4 -4
- data/ext/libxml/ruby_xml_relaxng.c +30 -43
- data/ext/libxml/ruby_xml_relaxng.h +2 -7
- data/ext/libxml/ruby_xml_sax_parser.c +174 -228
- data/ext/libxml/ruby_xml_sax_parser.h +12 -20
- data/ext/libxml/ruby_xml_schema.c +31 -44
- data/ext/libxml/ruby_xml_schema.h +2 -7
- data/ext/libxml/ruby_xml_state.c +6 -6
- data/ext/libxml/ruby_xml_state.h +2 -2
- data/ext/libxml/ruby_xml_xinclude.c +1 -1
- data/ext/libxml/ruby_xml_xinclude.h +3 -3
- data/ext/libxml/ruby_xml_xpath.c +1 -1
- data/ext/libxml/ruby_xml_xpath.h +3 -12
- data/ext/libxml/ruby_xml_xpath_context.c +293 -294
- data/ext/libxml/ruby_xml_xpath_context.h +3 -7
- data/ext/libxml/ruby_xml_xpath_expression.c +11 -11
- data/ext/libxml/ruby_xml_xpath_expression.h +2 -2
- data/ext/libxml/ruby_xml_xpath_object.c +52 -66
- data/ext/libxml/ruby_xml_xpath_object.h +3 -14
- data/ext/libxml/ruby_xml_xpointer.c +11 -12
- data/ext/libxml/ruby_xml_xpointer.h +5 -7
- data/ext/libxml/sax_parser_callbacks.inc +53 -36
- data/ext/libxml/version.h +2 -2
- data/ext/mingw/libxml_ruby.dll.a +0 -0
- data/ext/mingw/libxml_ruby.so +0 -0
- data/ext/vc/libxml_ruby.vcproj +1 -9
- data/lib/libxml/html_parser.rb +5 -5
- data/lib/libxml/parser.rb +4 -4
- data/lib/libxml/sax_parser.rb +24 -0
- data/test/tc_document_write.rb +2 -16
- data/test/tc_html_parser.rb +57 -5
- data/test/tc_input.rb +13 -0
- data/test/tc_parser.rb +11 -3
- data/test/tc_reader.rb +53 -34
- data/test/tc_sax_parser.rb +30 -8
- data/test/test.rb +8 -0
- data/test/test_suite.rb +1 -1
- metadata +5 -6
- data/ext/libxml/ruby_xml_encoding.c +0 -164
- data/ext/libxml/ruby_xml_encoding.h +0 -13
- 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
|
5
|
-
#define
|
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
|
12
|
+
VALUE rxml_reader_new_walker(VALUE self, VALUE doc);
|
13
13
|
|
14
|
-
#endif /*
|
14
|
+
#endif /* __rxml_READER__ */
|
@@ -39,18 +39,8 @@ VALUE cXMLRelaxNG;
|
|
39
39
|
#endif
|
40
40
|
|
41
41
|
static void
|
42
|
-
|
43
|
-
|
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
|
-
|
64
|
-
xmlRelaxNGParserCtxtPtr
|
65
|
-
|
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
|
-
|
70
|
-
|
71
|
-
|
72
|
-
xmlRelaxNGFreeParserCtxt(parser);
|
59
|
+
xparser = xmlRelaxNGNewParserCtxt(StringValuePtr(uri));
|
60
|
+
xrelaxng = xmlRelaxNGParse(xparser);
|
61
|
+
xmlRelaxNGFreeParserCtxt(xparser);
|
73
62
|
|
74
|
-
return Data_Wrap_Struct(cXMLRelaxNG,
|
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
|
-
|
72
|
+
static VALUE
|
73
|
+
rxml_relaxng_init_from_document(VALUE class, VALUE document) {
|
85
74
|
xmlDocPtr xdoc;
|
86
|
-
|
87
|
-
xmlRelaxNGParserCtxtPtr
|
75
|
+
xmlRelaxNGPtr xrelaxng;
|
76
|
+
xmlRelaxNGParserCtxtPtr xparser;
|
88
77
|
|
89
78
|
Data_Get_Struct(document, xmlDoc, xdoc);
|
90
79
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
xmlRelaxNGFreeParserCtxt(parser);
|
80
|
+
xparser = xmlRelaxNGNewDocParserCtxt(xdoc);
|
81
|
+
xrelaxng = xmlRelaxNGParse(xparser);
|
82
|
+
xmlRelaxNGFreeParserCtxt(xparser);
|
95
83
|
|
96
|
-
return Data_Wrap_Struct(cXMLRelaxNG,
|
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
|
-
|
107
|
-
xmlRelaxNGParserCtxtPtr
|
108
|
-
|
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
|
-
|
113
|
-
|
114
|
-
|
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,
|
104
|
+
return Data_Wrap_Struct(cXMLRelaxNG, NULL, rxml_relaxng_free, xrelaxng);
|
118
105
|
}
|
119
106
|
|
120
|
-
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",
|
123
|
-
rb_define_singleton_method(cXMLRelaxNG, "from_string",
|
124
|
-
rb_define_singleton_method(cXMLRelaxNG, "document",
|
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
|
2
|
-
#define
|
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
|
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
|
-
|
44
|
-
VALUE
|
45
|
-
VALUE
|
46
|
-
VALUE
|
47
|
-
VALUE
|
48
|
-
VALUE
|
49
|
-
VALUE
|
50
|
-
VALUE
|
51
|
-
VALUE
|
52
|
-
VALUE
|
53
|
-
VALUE
|
54
|
-
VALUE
|
55
|
-
VALUE
|
56
|
-
VALUE
|
57
|
-
VALUE
|
58
|
-
VALUE
|
59
|
-
VALUE
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
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
|
+
}
|