libxml-ruby 2.8.0 → 2.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/HISTORY +15 -0
  3. data/README.rdoc +7 -7
  4. data/Rakefile +80 -78
  5. data/ext/libxml/extconf.h +4 -0
  6. data/ext/libxml/extconf.rb +57 -116
  7. data/ext/libxml/libxml.c +4 -0
  8. data/ext/libxml/ruby_xml.c +977 -893
  9. data/ext/libxml/ruby_xml.h +20 -10
  10. data/ext/libxml/ruby_xml_attr.c +333 -333
  11. data/ext/libxml/ruby_xml_attr_decl.c +2 -2
  12. data/ext/libxml/ruby_xml_cbg.c +85 -85
  13. data/ext/libxml/ruby_xml_document.c +1133 -1147
  14. data/ext/libxml/ruby_xml_dtd.c +261 -268
  15. data/ext/libxml/ruby_xml_encoding.c +262 -260
  16. data/ext/libxml/ruby_xml_encoding.h +19 -19
  17. data/ext/libxml/ruby_xml_html_parser_context.c +337 -338
  18. data/ext/libxml/ruby_xml_input_cbg.c +191 -191
  19. data/ext/libxml/ruby_xml_io.c +52 -50
  20. data/ext/libxml/ruby_xml_namespace.c +2 -2
  21. data/ext/libxml/ruby_xml_node.c +1446 -1452
  22. data/ext/libxml/ruby_xml_parser_context.c +999 -1001
  23. data/ext/libxml/ruby_xml_reader.c +1226 -1228
  24. data/ext/libxml/ruby_xml_relaxng.c +110 -111
  25. data/ext/libxml/ruby_xml_sax2_handler.c +326 -328
  26. data/ext/libxml/ruby_xml_schema.c +300 -301
  27. data/ext/libxml/ruby_xml_version.h +3 -3
  28. data/ext/libxml/ruby_xml_writer.c +14 -15
  29. data/ext/libxml/ruby_xml_xpath.c +188 -188
  30. data/ext/libxml/ruby_xml_xpath_context.c +360 -361
  31. data/ext/libxml/ruby_xml_xpath_object.c +335 -335
  32. data/libxml-ruby.gemspec +47 -44
  33. data/test/tc_attr.rb +5 -7
  34. data/test/tc_attr_decl.rb +5 -6
  35. data/test/tc_attributes.rb +1 -2
  36. data/test/tc_canonicalize.rb +1 -2
  37. data/test/tc_deprecated_require.rb +1 -2
  38. data/test/tc_document.rb +4 -5
  39. data/test/tc_document_write.rb +2 -3
  40. data/test/tc_dtd.rb +4 -5
  41. data/test/tc_encoding.rb +126 -126
  42. data/test/tc_encoding_sax.rb +4 -3
  43. data/test/tc_error.rb +14 -15
  44. data/test/tc_html_parser.rb +15 -7
  45. data/test/tc_html_parser_context.rb +1 -2
  46. data/test/tc_namespace.rb +2 -3
  47. data/test/tc_namespaces.rb +5 -6
  48. data/test/tc_node.rb +2 -3
  49. data/test/tc_node_cdata.rb +2 -3
  50. data/test/tc_node_comment.rb +1 -2
  51. data/test/tc_node_copy.rb +1 -2
  52. data/test/tc_node_edit.rb +5 -7
  53. data/test/tc_node_pi.rb +1 -2
  54. data/test/tc_node_text.rb +2 -3
  55. data/test/tc_node_write.rb +2 -3
  56. data/test/tc_node_xlink.rb +1 -2
  57. data/test/tc_parser.rb +18 -24
  58. data/test/tc_parser_context.rb +6 -7
  59. data/test/tc_properties.rb +1 -2
  60. data/test/tc_reader.rb +9 -10
  61. data/test/tc_relaxng.rb +4 -5
  62. data/test/tc_sax_parser.rb +9 -10
  63. data/test/tc_schema.rb +4 -5
  64. data/test/tc_traversal.rb +1 -2
  65. data/test/tc_writer.rb +1 -2
  66. data/test/tc_xinclude.rb +1 -2
  67. data/test/tc_xml.rb +1 -2
  68. data/test/tc_xpath.rb +8 -9
  69. data/test/tc_xpath_context.rb +3 -4
  70. data/test/tc_xpath_expression.rb +3 -4
  71. data/test/tc_xpointer.rb +1 -3
  72. data/test/test_helper.rb +3 -1
  73. data/test/test_suite.rb +0 -1
  74. metadata +47 -11
  75. data/test/etc_doc_to_s.rb +0 -21
  76. data/test/ets_doc_file.rb +0 -17
  77. data/test/ets_doc_to_s.rb +0 -23
  78. data/test/ets_gpx.rb +0 -28
  79. data/test/ets_node_gc.rb +0 -23
  80. data/test/ets_test.xml +0 -2
  81. data/test/ets_tsr.rb +0 -11
@@ -1,301 +1,300 @@
1
- #include "ruby_libxml.h"
2
- #define LIBXML_OUTPUT_ENABLED
3
- #define DUMP_CONTENT_MODEL
4
- #include "ruby_xml_schema.h"
5
-
6
- #include "ruby_xml_schema_type.h"
7
- #include "ruby_xml_schema_element.h"
8
- #include "ruby_xml_schema_attribute.h"
9
- #include "ruby_xml_schema_facet.h"
10
-
11
-
12
- /*
13
- * Document-class: LibXML::XML::Schema
14
- *
15
- * The XML::Schema class is used to prepare XML Schemas for validation of xml
16
- * documents.
17
- *
18
- * Schemas can be created from XML documents, strinings or URIs using the
19
- * corresponding methods (new for URIs).
20
- *
21
- * Once a schema is prepared, an XML document can be validated by the
22
- * XML::Document#validate_schema method providing the XML::Schema object
23
- * as parameter. The method return true if the document validates, false
24
- * otherwise.
25
- *
26
- * Basic usage:
27
- *
28
- * # parse schema as xml document
29
- * schema_document = XML::Document.file('schema.rng')
30
- *
31
- * # prepare schema for validation
32
- * schema = XML::Schema.document(schema_document)
33
- *
34
- * # parse xml document to be validated
35
- * instance = XML::Document.file('instance.xml')
36
- *
37
- * # validate
38
- * instance.validate_schema(schema)
39
- */
40
-
41
- VALUE cXMLSchema;
42
-
43
- static void rxml_schema_free(xmlSchemaPtr xschema)
44
- {
45
- xmlSchemaFree(xschema);
46
- }
47
-
48
- VALUE rxml_wrap_schema(xmlSchemaPtr xschema)
49
- {
50
- return Data_Wrap_Struct(cXMLSchema, NULL, rxml_schema_free, xschema);
51
- }
52
-
53
-
54
- /*
55
- * call-seq:
56
- * XML::Schema.initialize(schema_uri) -> schema
57
- *
58
- * Create a new schema from the specified URI.
59
- */
60
- static VALUE rxml_schema_init_from_uri(VALUE class, VALUE uri)
61
- {
62
- xmlSchemaParserCtxtPtr xparser;
63
- xmlSchemaPtr xschema;
64
-
65
- Check_Type(uri, T_STRING);
66
-
67
- xparser = xmlSchemaNewParserCtxt(StringValuePtr(uri));
68
- xschema = xmlSchemaParse(xparser);
69
- xmlSchemaFreeParserCtxt(xparser);
70
-
71
- return Data_Wrap_Struct(cXMLSchema, NULL, rxml_schema_free, xschema);
72
- }
73
-
74
- /*
75
- * call-seq:
76
- * XML::Schema.document(document) -> schema
77
- *
78
- * Create a new schema from the specified document.
79
- */
80
- static VALUE rxml_schema_init_from_document(VALUE class, VALUE document)
81
- {
82
- xmlDocPtr xdoc;
83
- xmlSchemaPtr xschema;
84
- xmlSchemaParserCtxtPtr xparser;
85
-
86
- Data_Get_Struct(document, xmlDoc, xdoc);
87
-
88
- xparser = xmlSchemaNewDocParserCtxt(xdoc);
89
- xschema = xmlSchemaParse(xparser);
90
- xmlSchemaFreeParserCtxt(xparser);
91
-
92
- if (xschema == NULL)
93
- return Qnil;
94
-
95
- return Data_Wrap_Struct(cXMLSchema, NULL, rxml_schema_free, xschema);
96
- }
97
-
98
- /*
99
- * call-seq:
100
- * XML::Schema.from_string("schema_data") -> "value"
101
- *
102
- * Create a new schema using the specified string.
103
- */
104
- static VALUE rxml_schema_init_from_string(VALUE self, VALUE schema_str)
105
- {
106
- xmlSchemaParserCtxtPtr xparser;
107
- xmlSchemaPtr xschema;
108
-
109
- Check_Type(schema_str, T_STRING);
110
-
111
- xparser = xmlSchemaNewMemParserCtxt(StringValuePtr(schema_str), strlen(
112
- StringValuePtr(schema_str)));
113
- xschema = xmlSchemaParse(xparser);
114
- xmlSchemaFreeParserCtxt(xparser);
115
-
116
- return Data_Wrap_Struct(cXMLSchema, NULL, rxml_schema_free, xschema);
117
- }
118
-
119
-
120
- static VALUE rxml_schema_target_namespace(VALUE self)
121
- {
122
- xmlSchemaPtr xschema;
123
-
124
- Data_Get_Struct(self, xmlSchema, xschema);
125
-
126
- QNIL_OR_STRING(xschema->targetNamespace)
127
- }
128
-
129
- static VALUE rxml_schema_name(VALUE self)
130
- {
131
- xmlSchemaPtr xschema;
132
-
133
- Data_Get_Struct(self, xmlSchema, xschema);
134
-
135
- QNIL_OR_STRING(xschema->name)
136
- }
137
-
138
- static VALUE rxml_schema_version(VALUE self)
139
- {
140
- xmlSchemaPtr xschema;
141
-
142
- Data_Get_Struct(self, xmlSchema, xschema);
143
-
144
- QNIL_OR_STRING(xschema->version)
145
- }
146
-
147
- static VALUE rxml_schema_id(VALUE self)
148
- {
149
- xmlSchemaPtr xschema;
150
-
151
- Data_Get_Struct(self, xmlSchema, xschema);
152
-
153
- QNIL_OR_STRING(xschema->id)
154
- }
155
-
156
-
157
- static VALUE rxml_schema_document(VALUE self)
158
- {
159
- xmlSchemaPtr xschema;
160
-
161
- Data_Get_Struct(self, xmlSchema, xschema);
162
-
163
- return rxml_node_wrap(xmlDocGetRootElement(xschema->doc));
164
- }
165
-
166
- static void storeNs(xmlSchemaImportPtr import, VALUE self, xmlChar *nsname)
167
- {
168
- VALUE schemas;
169
- xmlNodePtr xnode;
170
- xmlNsPtr xns;
171
-
172
- schemas = rb_iv_get(self, "@namespaces");
173
- if (import->doc) {
174
- xnode = xmlDocGetRootElement(import->doc);
175
-
176
- xns = xnode->nsDef;
177
-
178
- while (xns) {
179
- VALUE anamespace = rxml_namespace_wrap(xns);
180
- rb_ary_push(schemas, anamespace);
181
- xns = xns->next;
182
- }
183
- }
184
- }
185
-
186
- static VALUE rxml_schema_namespaces(VALUE self)
187
- {
188
- VALUE schemas;
189
- xmlSchemaPtr xschema;
190
-
191
- Data_Get_Struct(self, xmlSchema, xschema);
192
-
193
- if (rb_iv_get(self, "@namespaces") == Qnil) {
194
- schemas = rb_ary_new();
195
- rb_iv_set(self, "@namespaces", schemas);
196
- xmlHashScan(xschema->schemasImports, (xmlHashScanner) storeNs, (void *)self);
197
- }
198
-
199
- return rb_iv_get(self, "@namespaces");
200
- }
201
-
202
- static void storeType(xmlSchemaTypePtr type, VALUE self, xmlChar *name)
203
- {
204
- VALUE types;
205
- VALUE rtype;
206
-
207
- types = rb_iv_get(self, "@types");
208
- rtype = rxml_wrap_schema_type(type);
209
-
210
- rb_hash_aset(types, rb_str_new2(name), rtype);
211
- }
212
-
213
- static VALUE rxml_schema_collect_types(VALUE self);
214
-
215
- static VALUE rxml_schema_types(VALUE self)
216
- {
217
- VALUE types;
218
- xmlSchemaPtr xschema;
219
-
220
- Data_Get_Struct(self, xmlSchema, xschema);
221
-
222
- if (rb_iv_get(self, "@types") == Qnil) {
223
- types = rb_hash_new();
224
- rb_iv_set(self, "@types", types);
225
- rxml_schema_collect_types(self);
226
- if(xschema != NULL && xschema->typeDecl != NULL)
227
- xmlHashScan(xschema->typeDecl, (xmlHashScanner) storeType, (void *)self);
228
- }
229
-
230
- return rb_iv_get(self, "@types");
231
- }
232
-
233
- static void storeElement(xmlSchemaElementPtr element, VALUE self, xmlChar *name)
234
- {
235
- VALUE elements;
236
- VALUE relement;
237
-
238
- elements = rb_iv_get(self, "@elements");
239
- relement = rxml_wrap_schema_element(element);
240
- rb_hash_aset(elements, rb_str_new2(name), relement);
241
- }
242
-
243
- static VALUE rxml_schema_elements(VALUE self)
244
- {
245
- VALUE elements;
246
- xmlSchemaPtr xschema;
247
-
248
- Data_Get_Struct(self, xmlSchema, xschema);
249
-
250
- if (rb_iv_get(self, "@elements") == Qnil) {
251
- elements = rb_hash_new();
252
- rb_iv_set(self, "@elements", elements);
253
- xmlHashScan(xschema->elemDecl, (xmlHashScanner) storeElement, (void *)self);
254
- }
255
-
256
- return rb_iv_get(self, "@elements");
257
- }
258
-
259
- static void collectSchemaTypes(xmlSchemaImportPtr import, VALUE self)
260
- {
261
- if (import->imported && import->schema) {
262
- xmlHashScan(import->schema->typeDecl, (xmlHashScanner) storeType, (void *)self);
263
- }
264
- }
265
-
266
- static VALUE rxml_schema_collect_types(VALUE self)
267
- {
268
- xmlSchemaPtr xschema;
269
-
270
- Data_Get_Struct(self, xmlSchema, xschema);
271
-
272
- if(xschema){
273
- xmlHashScan(xschema->schemasImports, (xmlHashScanner) collectSchemaTypes, (void *)self);
274
- }
275
-
276
- return Qnil;
277
- }
278
-
279
- void rxml_init_schema(void)
280
- {
281
- cXMLSchema = rb_define_class_under(mXML, "Schema", rb_cObject);
282
- rb_define_singleton_method(cXMLSchema, "new", rxml_schema_init_from_uri, 1);
283
- rb_define_singleton_method(cXMLSchema, "from_string", rxml_schema_init_from_string, 1);
284
- rb_define_singleton_method(cXMLSchema, "document", rxml_schema_init_from_document, 1);
285
-
286
- rb_define_method(cXMLSchema, "target_namespace", rxml_schema_target_namespace, 0);
287
- rb_define_method(cXMLSchema, "name", rxml_schema_name, 0);
288
- rb_define_method(cXMLSchema, "id", rxml_schema_id, 0);
289
- rb_define_method(cXMLSchema, "version", rxml_schema_version, 0);
290
- rb_define_method(cXMLSchema, "document", rxml_schema_document, 0);
291
-
292
- rb_define_method(cXMLSchema, "_namespaces", rxml_schema_namespaces, 0);
293
- rb_define_method(cXMLSchema, "_collect_types", rxml_schema_collect_types, 0);
294
- rb_define_method(cXMLSchema, "types", rxml_schema_types, 0);
295
- rb_define_method(cXMLSchema, "elements", rxml_schema_elements, 0);
296
-
297
- rxml_init_schema_facet();
298
- rxml_init_schema_element();
299
- rxml_init_schema_attribute();
300
- rxml_init_schema_type();
301
- }
1
+ #include "ruby_libxml.h"
2
+ #define LIBXML_OUTPUT_ENABLED
3
+ #define DUMP_CONTENT_MODEL
4
+ #include "ruby_xml_schema.h"
5
+
6
+ #include "ruby_xml_schema_type.h"
7
+ #include "ruby_xml_schema_element.h"
8
+ #include "ruby_xml_schema_attribute.h"
9
+ #include "ruby_xml_schema_facet.h"
10
+
11
+
12
+ /*
13
+ * Document-class: LibXML::XML::Schema
14
+ *
15
+ * The XML::Schema class is used to prepare XML Schemas for validation of xml
16
+ * documents.
17
+ *
18
+ * Schemas can be created from XML documents, strinings or URIs using the
19
+ * corresponding methods (new for URIs).
20
+ *
21
+ * Once a schema is prepared, an XML document can be validated by the
22
+ * XML::Document#validate_schema method providing the XML::Schema object
23
+ * as parameter. The method return true if the document validates, false
24
+ * otherwise.
25
+ *
26
+ * Basic usage:
27
+ *
28
+ * # parse schema as xml document
29
+ * schema_document = XML::Document.file('schema.rng')
30
+ *
31
+ * # prepare schema for validation
32
+ * schema = XML::Schema.document(schema_document)
33
+ *
34
+ * # parse xml document to be validated
35
+ * instance = XML::Document.file('instance.xml')
36
+ *
37
+ * # validate
38
+ * instance.validate_schema(schema)
39
+ */
40
+
41
+ VALUE cXMLSchema;
42
+
43
+ static void rxml_schema_free(xmlSchemaPtr xschema)
44
+ {
45
+ xmlSchemaFree(xschema);
46
+ }
47
+
48
+ VALUE rxml_wrap_schema(xmlSchemaPtr xschema)
49
+ {
50
+ return Data_Wrap_Struct(cXMLSchema, NULL, rxml_schema_free, xschema);
51
+ }
52
+
53
+
54
+ /*
55
+ * call-seq:
56
+ * XML::Schema.initialize(schema_uri) -> schema
57
+ *
58
+ * Create a new schema from the specified URI.
59
+ */
60
+ static VALUE rxml_schema_init_from_uri(VALUE class, VALUE uri)
61
+ {
62
+ xmlSchemaParserCtxtPtr xparser;
63
+ xmlSchemaPtr xschema;
64
+
65
+ Check_Type(uri, T_STRING);
66
+
67
+ xparser = xmlSchemaNewParserCtxt(StringValuePtr(uri));
68
+ xschema = xmlSchemaParse(xparser);
69
+ xmlSchemaFreeParserCtxt(xparser);
70
+
71
+ return Data_Wrap_Struct(cXMLSchema, NULL, rxml_schema_free, xschema);
72
+ }
73
+
74
+ /*
75
+ * call-seq:
76
+ * XML::Schema.document(document) -> schema
77
+ *
78
+ * Create a new schema from the specified document.
79
+ */
80
+ static VALUE rxml_schema_init_from_document(VALUE class, VALUE document)
81
+ {
82
+ xmlDocPtr xdoc;
83
+ xmlSchemaPtr xschema;
84
+ xmlSchemaParserCtxtPtr xparser;
85
+
86
+ Data_Get_Struct(document, xmlDoc, xdoc);
87
+
88
+ xparser = xmlSchemaNewDocParserCtxt(xdoc);
89
+ xschema = xmlSchemaParse(xparser);
90
+ xmlSchemaFreeParserCtxt(xparser);
91
+
92
+ if (xschema == NULL)
93
+ return Qnil;
94
+
95
+ return Data_Wrap_Struct(cXMLSchema, NULL, rxml_schema_free, xschema);
96
+ }
97
+
98
+ /*
99
+ * call-seq:
100
+ * XML::Schema.from_string("schema_data") -> "value"
101
+ *
102
+ * Create a new schema using the specified string.
103
+ */
104
+ static VALUE rxml_schema_init_from_string(VALUE self, VALUE schema_str)
105
+ {
106
+ xmlSchemaParserCtxtPtr xparser;
107
+ xmlSchemaPtr xschema;
108
+
109
+ Check_Type(schema_str, T_STRING);
110
+
111
+ xparser = xmlSchemaNewMemParserCtxt(StringValuePtr(schema_str), (int)strlen(StringValuePtr(schema_str)));
112
+ xschema = xmlSchemaParse(xparser);
113
+ xmlSchemaFreeParserCtxt(xparser);
114
+
115
+ return Data_Wrap_Struct(cXMLSchema, NULL, rxml_schema_free, xschema);
116
+ }
117
+
118
+
119
+ static VALUE rxml_schema_target_namespace(VALUE self)
120
+ {
121
+ xmlSchemaPtr xschema;
122
+
123
+ Data_Get_Struct(self, xmlSchema, xschema);
124
+
125
+ QNIL_OR_STRING(xschema->targetNamespace)
126
+ }
127
+
128
+ static VALUE rxml_schema_name(VALUE self)
129
+ {
130
+ xmlSchemaPtr xschema;
131
+
132
+ Data_Get_Struct(self, xmlSchema, xschema);
133
+
134
+ QNIL_OR_STRING(xschema->name)
135
+ }
136
+
137
+ static VALUE rxml_schema_version(VALUE self)
138
+ {
139
+ xmlSchemaPtr xschema;
140
+
141
+ Data_Get_Struct(self, xmlSchema, xschema);
142
+
143
+ QNIL_OR_STRING(xschema->version)
144
+ }
145
+
146
+ static VALUE rxml_schema_id(VALUE self)
147
+ {
148
+ xmlSchemaPtr xschema;
149
+
150
+ Data_Get_Struct(self, xmlSchema, xschema);
151
+
152
+ QNIL_OR_STRING(xschema->id)
153
+ }
154
+
155
+
156
+ static VALUE rxml_schema_document(VALUE self)
157
+ {
158
+ xmlSchemaPtr xschema;
159
+
160
+ Data_Get_Struct(self, xmlSchema, xschema);
161
+
162
+ return rxml_node_wrap(xmlDocGetRootElement(xschema->doc));
163
+ }
164
+
165
+ static void storeNs(xmlSchemaImportPtr import, VALUE self, xmlChar *nsname)
166
+ {
167
+ VALUE schemas;
168
+ xmlNodePtr xnode;
169
+ xmlNsPtr xns;
170
+
171
+ schemas = rb_iv_get(self, "@namespaces");
172
+ if (import->doc) {
173
+ xnode = xmlDocGetRootElement(import->doc);
174
+
175
+ xns = xnode->nsDef;
176
+
177
+ while (xns) {
178
+ VALUE anamespace = rxml_namespace_wrap(xns);
179
+ rb_ary_push(schemas, anamespace);
180
+ xns = xns->next;
181
+ }
182
+ }
183
+ }
184
+
185
+ static VALUE rxml_schema_namespaces(VALUE self)
186
+ {
187
+ VALUE schemas;
188
+ xmlSchemaPtr xschema;
189
+
190
+ Data_Get_Struct(self, xmlSchema, xschema);
191
+
192
+ if (rb_iv_get(self, "@namespaces") == Qnil) {
193
+ schemas = rb_ary_new();
194
+ rb_iv_set(self, "@namespaces", schemas);
195
+ xmlHashScan(xschema->schemasImports, (xmlHashScanner) storeNs, (void *)self);
196
+ }
197
+
198
+ return rb_iv_get(self, "@namespaces");
199
+ }
200
+
201
+ static void storeType(xmlSchemaTypePtr type, VALUE self, xmlChar *name)
202
+ {
203
+ VALUE types;
204
+ VALUE rtype;
205
+
206
+ types = rb_iv_get(self, "@types");
207
+ rtype = rxml_wrap_schema_type(type);
208
+
209
+ rb_hash_aset(types, rb_str_new2((const char*)name), rtype);
210
+ }
211
+
212
+ static VALUE rxml_schema_collect_types(VALUE self);
213
+
214
+ static VALUE rxml_schema_types(VALUE self)
215
+ {
216
+ VALUE types;
217
+ xmlSchemaPtr xschema;
218
+
219
+ Data_Get_Struct(self, xmlSchema, xschema);
220
+
221
+ if (rb_iv_get(self, "@types") == Qnil) {
222
+ types = rb_hash_new();
223
+ rb_iv_set(self, "@types", types);
224
+ rxml_schema_collect_types(self);
225
+ if(xschema != NULL && xschema->typeDecl != NULL)
226
+ xmlHashScan(xschema->typeDecl, (xmlHashScanner) storeType, (void *)self);
227
+ }
228
+
229
+ return rb_iv_get(self, "@types");
230
+ }
231
+
232
+ static void storeElement(xmlSchemaElementPtr element, VALUE self, xmlChar *name)
233
+ {
234
+ VALUE elements;
235
+ VALUE relement;
236
+
237
+ elements = rb_iv_get(self, "@elements");
238
+ relement = rxml_wrap_schema_element(element);
239
+ rb_hash_aset(elements, rb_str_new2((const char*)name), relement);
240
+ }
241
+
242
+ static VALUE rxml_schema_elements(VALUE self)
243
+ {
244
+ VALUE elements;
245
+ xmlSchemaPtr xschema;
246
+
247
+ Data_Get_Struct(self, xmlSchema, xschema);
248
+
249
+ if (rb_iv_get(self, "@elements") == Qnil) {
250
+ elements = rb_hash_new();
251
+ rb_iv_set(self, "@elements", elements);
252
+ xmlHashScan(xschema->elemDecl, (xmlHashScanner) storeElement, (void *)self);
253
+ }
254
+
255
+ return rb_iv_get(self, "@elements");
256
+ }
257
+
258
+ static void collectSchemaTypes(xmlSchemaImportPtr import, VALUE self)
259
+ {
260
+ if (import->imported && import->schema) {
261
+ xmlHashScan(import->schema->typeDecl, (xmlHashScanner) storeType, (void *)self);
262
+ }
263
+ }
264
+
265
+ static VALUE rxml_schema_collect_types(VALUE self)
266
+ {
267
+ xmlSchemaPtr xschema;
268
+
269
+ Data_Get_Struct(self, xmlSchema, xschema);
270
+
271
+ if(xschema){
272
+ xmlHashScan(xschema->schemasImports, (xmlHashScanner) collectSchemaTypes, (void *)self);
273
+ }
274
+
275
+ return Qnil;
276
+ }
277
+
278
+ void rxml_init_schema(void)
279
+ {
280
+ cXMLSchema = rb_define_class_under(mXML, "Schema", rb_cObject);
281
+ rb_define_singleton_method(cXMLSchema, "new", rxml_schema_init_from_uri, 1);
282
+ rb_define_singleton_method(cXMLSchema, "from_string", rxml_schema_init_from_string, 1);
283
+ rb_define_singleton_method(cXMLSchema, "document", rxml_schema_init_from_document, 1);
284
+
285
+ rb_define_method(cXMLSchema, "target_namespace", rxml_schema_target_namespace, 0);
286
+ rb_define_method(cXMLSchema, "name", rxml_schema_name, 0);
287
+ rb_define_method(cXMLSchema, "id", rxml_schema_id, 0);
288
+ rb_define_method(cXMLSchema, "version", rxml_schema_version, 0);
289
+ rb_define_method(cXMLSchema, "document", rxml_schema_document, 0);
290
+
291
+ rb_define_method(cXMLSchema, "_namespaces", rxml_schema_namespaces, 0);
292
+ rb_define_method(cXMLSchema, "_collect_types", rxml_schema_collect_types, 0);
293
+ rb_define_method(cXMLSchema, "types", rxml_schema_types, 0);
294
+ rb_define_method(cXMLSchema, "elements", rxml_schema_elements, 0);
295
+
296
+ rxml_init_schema_facet();
297
+ rxml_init_schema_element();
298
+ rxml_init_schema_attribute();
299
+ rxml_init_schema_type();
300
+ }