@@ -93,23 +93,34 @@ static VALUE validate_file(VALUE self, VALUE rb_filename)
93
93
*
94
94
* Create a new Schema from the contents of +string+
95
95
*/
96
- static VALUE read_memory (VALUE klass , VALUE content )
96
+ static VALUE read_memory (int argc , VALUE * argv , VALUE klass )
97
97
{
98
+ VALUE content ;
99
+ VALUE parse_options ;
100
+ int parse_options_int ;
101
+ xmlSchemaParserCtxtPtr ctx ;
98
102
xmlSchemaPtr schema ;
99
- xmlSchemaParserCtxtPtr ctx = xmlSchemaNewMemParserCtxt (
100
- (const char * )StringValuePtr (content ),
101
- (int )RSTRING_LEN (content )
102
- );
103
+ VALUE errors ;
103
104
VALUE rb_schema ;
104
- VALUE errors = rb_ary_new ();
105
+ int scanned_args = 0 ;
106
+
107
+ scanned_args = rb_scan_args (argc , argv , "11" , & content , & parse_options );
108
+ if (scanned_args == 1 ) {
109
+ parse_options = rb_const_get (rb_const_get (mNokogiriXml , rb_intern ("ParseOptions" )), rb_intern ("DEFAULT_SCHEMA" ));
110
+ }
111
+ parse_options_int = (int )NUM2INT (rb_funcall (parse_options , rb_intern ("to_i" ), 0 ));
112
+
113
+ ctx = xmlSchemaNewMemParserCtxt ((const char * )StringValuePtr (content ), (int )RSTRING_LEN (content ));
114
+
115
+ errors = rb_ary_new ();
105
116
xmlSetStructuredErrorFunc ((void * )errors , Nokogiri_error_array_pusher );
106
117
107
118
#ifdef HAVE_XMLSCHEMASETPARSERSTRUCTUREDERRORS
108
119
xmlSchemaSetParserStructuredErrors (
109
120
ctx ,
110
121
Nokogiri_error_array_pusher ,
111
122
(void * )errors
112
- );
123
+ );
113
124
#endif
114
125
115
126
schema = xmlSchemaParse (ctx );
@@ -129,6 +140,7 @@ static VALUE read_memory(VALUE klass, VALUE content)
129
140
130
141
rb_schema = Data_Wrap_Struct (klass , 0 , dealloc , schema );
131
142
rb_iv_set (rb_schema , "@errors" , errors );
143
+ rb_iv_set (rb_schema , "@parse_options" , parse_options );
132
144
133
145
return rb_schema ;
134
146
}
@@ -164,18 +176,27 @@ static int has_blank_nodes_p(VALUE cache)
164
176
*
165
177
* Create a new Schema from the Nokogiri::XML::Document +doc+
166
178
*/
167
- static VALUE from_document (VALUE klass , VALUE document )
179
+ static VALUE from_document (int argc , VALUE * argv , VALUE klass )
168
180
{
181
+ VALUE document ;
182
+ VALUE parse_options ;
183
+ int parse_options_int ;
169
184
xmlDocPtr doc ;
170
185
xmlSchemaParserCtxtPtr ctx ;
171
186
xmlSchemaPtr schema ;
172
187
VALUE errors ;
173
188
VALUE rb_schema ;
189
+ int scanned_args = 0 ;
190
+
191
+ scanned_args = rb_scan_args (argc , argv , "11" , & document , & parse_options );
174
192
175
193
Data_Get_Struct (document , xmlDoc , doc );
194
+ doc = doc -> doc ; /* In case someone passes us a node. ugh. */
176
195
177
- /* In case someone passes us a node. ugh. */
178
- doc = doc -> doc ;
196
+ if (scanned_args == 1 ) {
197
+ parse_options = rb_const_get (rb_const_get (mNokogiriXml , rb_intern ("ParseOptions" )), rb_intern ("DEFAULT_SCHEMA" ));
198
+ }
199
+ parse_options_int = (int )NUM2INT (rb_funcall (parse_options , rb_intern ("to_i" ), 0 ));
179
200
180
201
if (has_blank_nodes_p (DOC_NODE_CACHE (doc ))) {
181
202
rb_raise (rb_eArgError , "Creating a schema from a document that has blank nodes exposed to Ruby is dangerous" );
@@ -211,6 +232,7 @@ static VALUE from_document(VALUE klass, VALUE document)
211
232
212
233
rb_schema = Data_Wrap_Struct (klass , 0 , dealloc , schema );
213
234
rb_iv_set (rb_schema , "@errors" , errors );
235
+ rb_iv_set (rb_schema , "@parse_options" , parse_options );
214
236
215
237
return rb_schema ;
216
238
@@ -226,8 +248,8 @@ void init_xml_schema()
226
248
227
249
cNokogiriXmlSchema = klass ;
228
250
229
- rb_define_singleton_method (klass , "read_memory" , read_memory , 1 );
230
- rb_define_singleton_method (klass , "from_document" , from_document , 1 );
251
+ rb_define_singleton_method (klass , "read_memory" , read_memory , - 1 );
252
+ rb_define_singleton_method (klass , "from_document" , from_document , - 1 );
231
253
232
254
rb_define_private_method (klass , "validate_document" , validate_document , 1 );
233
255
rb_define_private_method (klass , "validate_file" , validate_file , 1 );
0 commit comments