libxml-ruby 3.2.0 → 3.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/HISTORY +23 -1
- data/README.rdoc +52 -36
- data/Rakefile +24 -16
- data/ext/libxml/ruby_xml.c +4 -0
- data/ext/libxml/ruby_xml_document.c +0 -4
- data/ext/libxml/ruby_xml_encoding.c +1 -13
- data/ext/libxml/ruby_xml_encoding.h +0 -3
- data/ext/libxml/ruby_xml_io.c +14 -18
- data/ext/libxml/ruby_xml_io.h +1 -1
- data/ext/libxml/ruby_xml_namespace.c +1 -0
- data/ext/libxml/ruby_xml_node.c +8 -4
- data/ext/libxml/ruby_xml_schema.c +151 -79
- data/ext/libxml/ruby_xml_schema.h +2 -5
- data/ext/libxml/ruby_xml_schema_attribute.c +23 -71
- data/ext/libxml/ruby_xml_schema_element.c +28 -54
- data/ext/libxml/ruby_xml_schema_facet.c +15 -21
- data/ext/libxml/ruby_xml_schema_type.c +19 -37
- data/ext/libxml/ruby_xml_version.h +3 -3
- data/ext/libxml/ruby_xml_writer.c +189 -192
- data/libxml-ruby.gemspec +1 -1
- data/test/model/shiporder.rnc +2 -2
- data/test/model/shiporder.rng +2 -2
- data/test/model/shiporder.xsd +7 -3
- data/test/model/shiporder_bad.xsd +40 -0
- data/test/model/shiporder_import.xsd +45 -0
- data/test/test_document.rb +111 -110
- data/test/test_dtd.rb +2 -1
- data/test/test_helper.rb +2 -0
- data/test/test_parser.rb +1 -1
- data/test/test_parser_context.rb +3 -9
- data/test/test_reader.rb +2 -1
- data/test/test_sax_parser.rb +13 -6
- data/test/test_schema.rb +92 -29
- data/test/test_writer.rb +48 -25
- data/test/test_xml.rb +2 -1
- metadata +11 -10
- data/ext/libxml/extconf.h +0 -3
@@ -46,9 +46,37 @@ static void rxml_schema_free(xmlSchemaPtr xschema)
|
|
46
46
|
|
47
47
|
VALUE rxml_wrap_schema(xmlSchemaPtr xschema)
|
48
48
|
{
|
49
|
-
|
49
|
+
VALUE result;
|
50
|
+
|
51
|
+
if (!xschema)
|
52
|
+
rb_raise(rb_eArgError, "XML::Schema is required!");
|
53
|
+
|
54
|
+
result = Data_Wrap_Struct(cXMLSchema, NULL, rxml_schema_free, xschema);
|
55
|
+
|
56
|
+
/*
|
57
|
+
* Create these as instance variables to provide the output of inspect/to_str some
|
58
|
+
* idea of what schema this class contains.
|
59
|
+
*/
|
60
|
+
rb_iv_set(result, "@target_namespace", QNIL_OR_STRING(xschema->targetNamespace));
|
61
|
+
rb_iv_set(result, "@name", QNIL_OR_STRING(xschema->name));
|
62
|
+
rb_iv_set(result, "@id", QNIL_OR_STRING(xschema->id));
|
63
|
+
rb_iv_set(result, "@version", QNIL_OR_STRING(xschema->name));
|
64
|
+
|
65
|
+
return result;
|
50
66
|
}
|
51
67
|
|
68
|
+
static VALUE rxml_schema_init(VALUE class, xmlSchemaParserCtxtPtr xparser)
|
69
|
+
{
|
70
|
+
xmlSchemaPtr xschema;
|
71
|
+
|
72
|
+
xschema = xmlSchemaParse(xparser);
|
73
|
+
xmlSchemaFreeParserCtxt(xparser);
|
74
|
+
|
75
|
+
if (!xschema)
|
76
|
+
rxml_raise(&xmlLastError);
|
77
|
+
|
78
|
+
return rxml_wrap_schema(xschema);
|
79
|
+
}
|
52
80
|
|
53
81
|
/*
|
54
82
|
* call-seq:
|
@@ -59,15 +87,15 @@ VALUE rxml_wrap_schema(xmlSchemaPtr xschema)
|
|
59
87
|
static VALUE rxml_schema_init_from_uri(VALUE class, VALUE uri)
|
60
88
|
{
|
61
89
|
xmlSchemaParserCtxtPtr xparser;
|
62
|
-
xmlSchemaPtr xschema;
|
63
90
|
|
64
91
|
Check_Type(uri, T_STRING);
|
65
92
|
|
93
|
+
xmlResetLastError();
|
66
94
|
xparser = xmlSchemaNewParserCtxt(StringValuePtr(uri));
|
67
|
-
|
68
|
-
|
95
|
+
if (!xparser)
|
96
|
+
rxml_raise(&xmlLastError);
|
69
97
|
|
70
|
-
return
|
98
|
+
return rxml_schema_init(class, xparser);
|
71
99
|
}
|
72
100
|
|
73
101
|
/*
|
@@ -79,19 +107,16 @@ static VALUE rxml_schema_init_from_uri(VALUE class, VALUE uri)
|
|
79
107
|
static VALUE rxml_schema_init_from_document(VALUE class, VALUE document)
|
80
108
|
{
|
81
109
|
xmlDocPtr xdoc;
|
82
|
-
xmlSchemaPtr xschema;
|
83
110
|
xmlSchemaParserCtxtPtr xparser;
|
84
111
|
|
85
112
|
Data_Get_Struct(document, xmlDoc, xdoc);
|
86
113
|
|
114
|
+
xmlResetLastError();
|
87
115
|
xparser = xmlSchemaNewDocParserCtxt(xdoc);
|
88
|
-
|
89
|
-
|
116
|
+
if (!xparser)
|
117
|
+
rxml_raise(&xmlLastError);
|
90
118
|
|
91
|
-
|
92
|
-
return Qnil;
|
93
|
-
|
94
|
-
return Data_Wrap_Struct(cXMLSchema, NULL, rxml_schema_free, xschema);
|
119
|
+
return rxml_schema_init(class, xparser);
|
95
120
|
}
|
96
121
|
|
97
122
|
/*
|
@@ -100,57 +125,26 @@ static VALUE rxml_schema_init_from_document(VALUE class, VALUE document)
|
|
100
125
|
*
|
101
126
|
* Create a new schema using the specified string.
|
102
127
|
*/
|
103
|
-
static VALUE rxml_schema_init_from_string(VALUE
|
128
|
+
static VALUE rxml_schema_init_from_string(VALUE class, VALUE schema_str)
|
104
129
|
{
|
105
130
|
xmlSchemaParserCtxtPtr xparser;
|
106
|
-
xmlSchemaPtr xschema;
|
107
131
|
|
108
132
|
Check_Type(schema_str, T_STRING);
|
109
133
|
|
134
|
+
xmlResetLastError();
|
110
135
|
xparser = xmlSchemaNewMemParserCtxt(StringValuePtr(schema_str), (int)strlen(StringValuePtr(schema_str)));
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
return Data_Wrap_Struct(cXMLSchema, NULL, rxml_schema_free, xschema);
|
115
|
-
}
|
116
|
-
|
117
|
-
|
118
|
-
static VALUE rxml_schema_target_namespace(VALUE self)
|
119
|
-
{
|
120
|
-
xmlSchemaPtr xschema;
|
121
|
-
|
122
|
-
Data_Get_Struct(self, xmlSchema, xschema);
|
123
|
-
|
124
|
-
QNIL_OR_STRING(xschema->targetNamespace)
|
125
|
-
}
|
126
|
-
|
127
|
-
static VALUE rxml_schema_name(VALUE self)
|
128
|
-
{
|
129
|
-
xmlSchemaPtr xschema;
|
130
|
-
|
131
|
-
Data_Get_Struct(self, xmlSchema, xschema);
|
136
|
+
if (!xparser)
|
137
|
+
rxml_raise(&xmlLastError);
|
132
138
|
|
133
|
-
|
134
|
-
}
|
135
|
-
|
136
|
-
static VALUE rxml_schema_version(VALUE self)
|
137
|
-
{
|
138
|
-
xmlSchemaPtr xschema;
|
139
|
-
|
140
|
-
Data_Get_Struct(self, xmlSchema, xschema);
|
141
|
-
|
142
|
-
QNIL_OR_STRING(xschema->version)
|
143
|
-
}
|
144
|
-
|
145
|
-
static VALUE rxml_schema_id(VALUE self)
|
146
|
-
{
|
147
|
-
xmlSchemaPtr xschema;
|
148
|
-
|
149
|
-
Data_Get_Struct(self, xmlSchema, xschema);
|
150
|
-
|
151
|
-
QNIL_OR_STRING(xschema->id)
|
139
|
+
return rxml_schema_init(class, xparser);
|
152
140
|
}
|
153
141
|
|
142
|
+
/*
|
143
|
+
* call-seq:
|
144
|
+
* XML::Schema.document -> document
|
145
|
+
*
|
146
|
+
* Return the Schema XML Document
|
147
|
+
*/
|
154
148
|
static VALUE rxml_schema_document(VALUE self)
|
155
149
|
{
|
156
150
|
xmlSchemaPtr xschema;
|
@@ -160,7 +154,7 @@ static VALUE rxml_schema_document(VALUE self)
|
|
160
154
|
return rxml_node_wrap(xmlDocGetRootElement(xschema->doc));
|
161
155
|
}
|
162
156
|
|
163
|
-
static void scan_namespaces(xmlSchemaImportPtr ximport, VALUE array, xmlChar *nsname)
|
157
|
+
static void scan_namespaces(xmlSchemaImportPtr ximport, VALUE array, const xmlChar *nsname)
|
164
158
|
{
|
165
159
|
xmlNodePtr xnode;
|
166
160
|
xmlNsPtr xns;
|
@@ -171,7 +165,7 @@ static void scan_namespaces(xmlSchemaImportPtr ximport, VALUE array, xmlChar *ns
|
|
171
165
|
xns = xnode->nsDef;
|
172
166
|
|
173
167
|
while (xns)
|
174
|
-
|
168
|
+
{
|
175
169
|
VALUE namespace = rxml_namespace_wrap(xns);
|
176
170
|
rb_ary_push(array, namespace);
|
177
171
|
xns = xns->next;
|
@@ -179,6 +173,12 @@ static void scan_namespaces(xmlSchemaImportPtr ximport, VALUE array, xmlChar *ns
|
|
179
173
|
}
|
180
174
|
}
|
181
175
|
|
176
|
+
/*
|
177
|
+
* call-seq:
|
178
|
+
* XML::Schema.namespaces -> array
|
179
|
+
*
|
180
|
+
* Returns an array of Namespaces defined by the schema
|
181
|
+
*/
|
182
182
|
static VALUE rxml_schema_namespaces(VALUE self)
|
183
183
|
{
|
184
184
|
VALUE result;
|
@@ -192,7 +192,7 @@ static VALUE rxml_schema_namespaces(VALUE self)
|
|
192
192
|
return result;
|
193
193
|
}
|
194
194
|
|
195
|
-
static void
|
195
|
+
static void scan_schema_element(xmlSchemaElementPtr xelement, VALUE hash, const xmlChar *name)
|
196
196
|
{
|
197
197
|
VALUE element = rxml_wrap_schema_element(xelement);
|
198
198
|
rb_hash_aset(hash, rb_str_new2((const char*)name), element);
|
@@ -204,40 +204,77 @@ static VALUE rxml_schema_elements(VALUE self)
|
|
204
204
|
xmlSchemaPtr xschema;
|
205
205
|
|
206
206
|
Data_Get_Struct(self, xmlSchema, xschema);
|
207
|
-
xmlHashScan(xschema->elemDecl, (xmlHashScanner)
|
207
|
+
xmlHashScan(xschema->elemDecl, (xmlHashScanner)scan_schema_element, (void *)result);
|
208
208
|
|
209
209
|
return result;
|
210
210
|
}
|
211
211
|
|
212
|
-
static void
|
212
|
+
static void collect_imported_ns_elements(xmlSchemaImportPtr import, VALUE result, const xmlChar *name)
|
213
213
|
{
|
214
|
-
|
215
|
-
|
214
|
+
if (import->imported && import->schema)
|
215
|
+
{
|
216
|
+
VALUE elements = rb_hash_new();
|
217
|
+
xmlHashScan(import->schema->elemDecl, (xmlHashScanner)scan_schema_element, (void *)elements);
|
218
|
+
rb_hash_aset(result, QNIL_OR_STRING(import->schema->targetNamespace), elements);
|
219
|
+
}
|
220
|
+
}
|
221
|
+
|
222
|
+
/*
|
223
|
+
* call-seq:
|
224
|
+
* XML::Schema.imported_ns_elements -> hash
|
225
|
+
*
|
226
|
+
* Returns a hash by namespace of a hash of schema elements within the entire schema including imports
|
227
|
+
*/
|
228
|
+
static VALUE rxml_schema_imported_ns_elements(VALUE self)
|
229
|
+
{
|
230
|
+
xmlSchemaPtr xschema;
|
231
|
+
VALUE result = rb_hash_new();
|
232
|
+
|
233
|
+
Data_Get_Struct(self, xmlSchema, xschema);
|
234
|
+
|
235
|
+
if (xschema)
|
236
|
+
{
|
237
|
+
xmlHashScan(xschema->schemasImports, (xmlHashScanner)collect_imported_ns_elements, (void *)result);
|
238
|
+
}
|
239
|
+
|
240
|
+
return result;
|
241
|
+
}
|
242
|
+
|
243
|
+
static void scan_schema_type(xmlSchemaTypePtr xtype, VALUE hash, const xmlChar *name)
|
244
|
+
{
|
245
|
+
VALUE type = rxml_wrap_schema_type(xtype);
|
246
|
+
rb_hash_aset(hash, rb_str_new2((const char*)name), type);
|
216
247
|
}
|
217
248
|
|
218
249
|
static VALUE rxml_schema_types(VALUE self)
|
219
250
|
{
|
220
|
-
|
221
|
-
|
251
|
+
VALUE result = rb_hash_new();
|
252
|
+
xmlSchemaPtr xschema;
|
222
253
|
|
223
|
-
|
254
|
+
Data_Get_Struct(self, xmlSchema, xschema);
|
224
255
|
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
256
|
+
if (xschema != NULL && xschema->typeDecl != NULL)
|
257
|
+
{
|
258
|
+
xmlHashScan(xschema->typeDecl, (xmlHashScanner)scan_schema_type, (void *)result);
|
259
|
+
}
|
229
260
|
|
230
|
-
|
261
|
+
return result;
|
231
262
|
}
|
232
263
|
|
233
|
-
static void collect_imported_types(xmlSchemaImportPtr import, VALUE result)
|
264
|
+
static void collect_imported_types(xmlSchemaImportPtr import, VALUE result, const xmlChar *name)
|
234
265
|
{
|
235
266
|
if (import->imported && import->schema)
|
236
267
|
{
|
237
|
-
xmlHashScan(import->schema->typeDecl, (xmlHashScanner)
|
268
|
+
xmlHashScan(import->schema->typeDecl, (xmlHashScanner)scan_schema_type, (void *)result);
|
238
269
|
}
|
239
270
|
}
|
240
271
|
|
272
|
+
/*
|
273
|
+
* call-seq:
|
274
|
+
* XML::Schema.imported_types -> hash
|
275
|
+
*
|
276
|
+
* Returns a hash of all types within the entire schema including imports
|
277
|
+
*/
|
241
278
|
static VALUE rxml_schema_imported_types(VALUE self)
|
242
279
|
{
|
243
280
|
xmlSchemaPtr xschema;
|
@@ -247,7 +284,38 @@ static VALUE rxml_schema_imported_types(VALUE self)
|
|
247
284
|
|
248
285
|
if (xschema)
|
249
286
|
{
|
250
|
-
|
287
|
+
xmlHashScan(xschema->schemasImports, (xmlHashScanner)collect_imported_types, (void *)result);
|
288
|
+
}
|
289
|
+
|
290
|
+
return result;
|
291
|
+
}
|
292
|
+
|
293
|
+
static void collect_imported_ns_types(xmlSchemaImportPtr import, VALUE result, const xmlChar *name)
|
294
|
+
{
|
295
|
+
if (import->imported && import->schema)
|
296
|
+
{
|
297
|
+
VALUE types = rb_hash_new();
|
298
|
+
xmlHashScan(import->schema->typeDecl, (xmlHashScanner)scan_schema_type, (void *)types);
|
299
|
+
rb_hash_aset(result, QNIL_OR_STRING(import->schema->targetNamespace), types);
|
300
|
+
}
|
301
|
+
}
|
302
|
+
|
303
|
+
/*
|
304
|
+
* call-seq:
|
305
|
+
* XML::Schema.imported_ns_types -> hash
|
306
|
+
*
|
307
|
+
* Returns a hash by namespace of a hash of schema types within the entire schema including imports
|
308
|
+
*/
|
309
|
+
static VALUE rxml_schema_imported_ns_types(VALUE self)
|
310
|
+
{
|
311
|
+
xmlSchemaPtr xschema;
|
312
|
+
VALUE result = rb_hash_new();
|
313
|
+
|
314
|
+
Data_Get_Struct(self, xmlSchema, xschema);
|
315
|
+
|
316
|
+
if (xschema)
|
317
|
+
{
|
318
|
+
xmlHashScan(xschema->schemasImports, (xmlHashScanner)collect_imported_ns_types, (void *)result);
|
251
319
|
}
|
252
320
|
|
253
321
|
return result;
|
@@ -260,16 +328,20 @@ void rxml_init_schema(void)
|
|
260
328
|
rb_define_singleton_method(cXMLSchema, "from_string", rxml_schema_init_from_string, 1);
|
261
329
|
rb_define_singleton_method(cXMLSchema, "document", rxml_schema_init_from_document, 1);
|
262
330
|
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
331
|
+
/* Create attr_reader methods for the above instance variables */
|
332
|
+
rb_define_attr(cXMLSchema, "target_namespace", 1, 0);
|
333
|
+
rb_define_attr(cXMLSchema, "name", 1, 0);
|
334
|
+
rb_define_attr(cXMLSchema, "id", 1, 0);
|
335
|
+
rb_define_attr(cXMLSchema, "version", 1, 0);
|
268
336
|
|
269
|
-
|
270
|
-
rb_define_method(cXMLSchema, "
|
337
|
+
// These are just methods so as to hide their values and not overly clutter the output of inspect/to_str
|
338
|
+
rb_define_method(cXMLSchema, "document", rxml_schema_document, 0);
|
271
339
|
rb_define_method(cXMLSchema, "namespaces", rxml_schema_namespaces, 0);
|
340
|
+
rb_define_method(cXMLSchema, "elements", rxml_schema_elements, 0);
|
341
|
+
rb_define_method(cXMLSchema, "imported_ns_elements", rxml_schema_imported_ns_elements, 0);
|
272
342
|
rb_define_method(cXMLSchema, "types", rxml_schema_types, 0);
|
343
|
+
rb_define_method(cXMLSchema, "imported_types", rxml_schema_imported_types, 0);
|
344
|
+
rb_define_method(cXMLSchema, "imported_ns_types", rxml_schema_imported_ns_types, 0);
|
273
345
|
|
274
346
|
rxml_init_schema_facet();
|
275
347
|
rxml_init_schema_element();
|
@@ -9,11 +9,8 @@ extern VALUE cXMLSchema;
|
|
9
9
|
|
10
10
|
void rxml_init_schema(void);
|
11
11
|
|
12
|
-
#define QNIL_OR_STRING(slot)
|
13
|
-
|
14
|
-
return Qnil; \
|
15
|
-
else \
|
16
|
-
return rb_str_new2((const char *)slot);
|
12
|
+
#define QNIL_OR_STRING(slot) \
|
13
|
+
(slot == NULL) ? Qnil : rb_str_new2((const char *)slot)
|
17
14
|
|
18
15
|
#define SUBSET_RESTRICTION 1<<0
|
19
16
|
#define SUBSET_EXTENSION 1<<1
|
@@ -12,62 +12,31 @@ static void rxml_schema_attribute_free(xmlSchemaAttributeUsePtr attr)
|
|
12
12
|
|
13
13
|
VALUE rxml_wrap_schema_attribute(xmlSchemaAttributeUsePtr attr)
|
14
14
|
{
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
static VALUE rxml_schema_attribute_namespace(VALUE self)
|
19
|
-
{
|
20
|
-
xmlSchemaAttributeUsePtr attr;
|
21
|
-
const xmlChar *tns;
|
15
|
+
VALUE result;
|
16
|
+
const xmlChar *tns_str, *name_str;
|
22
17
|
|
23
|
-
|
18
|
+
if (!attr)
|
19
|
+
rb_raise(rb_eArgError, "XML::Schema::Attribute required!");
|
24
20
|
|
25
|
-
|
26
|
-
return Qnil;
|
21
|
+
result = Data_Wrap_Struct(cXMLSchemaAttribute, NULL, rxml_schema_attribute_free, attr);
|
27
22
|
|
28
23
|
if (attr->type == XML_SCHEMA_EXTRA_ATTR_USE_PROHIB) {
|
29
|
-
|
24
|
+
tns_str = ((xmlSchemaAttributeUseProhibPtr) attr)->targetNamespace;
|
25
|
+
name_str = ((xmlSchemaAttributeUseProhibPtr) attr)->name;
|
30
26
|
} else if (attr->type == XML_SCHEMA_EXTRA_QNAMEREF) {
|
31
|
-
|
27
|
+
tns_str = ((xmlSchemaQNameRefPtr) attr)->targetNamespace;
|
28
|
+
name_str = ((xmlSchemaQNameRefPtr) attr)->name;
|
32
29
|
} else {
|
33
|
-
|
30
|
+
tns_str = ((xmlSchemaAttributePtr) (attr->attrDecl))->targetNamespace;
|
31
|
+
name_str = ((xmlSchemaAttributePtr) (attr->attrDecl))->name;
|
34
32
|
}
|
33
|
+
rb_iv_set(result, "@target_namespace", QNIL_OR_STRING(tns_str));
|
34
|
+
rb_iv_set(result, "@name", QNIL_OR_STRING(name_str));
|
35
|
+
rb_iv_set(result, "@type", rxml_wrap_schema_type((xmlSchemaTypePtr)attr->attrDecl->subtypes));
|
36
|
+
rb_iv_set(result, "@value", QNIL_OR_STRING(attr->defValue));
|
37
|
+
rb_iv_set(result, "@occurs", INT2NUM(attr->occurs));
|
35
38
|
|
36
|
-
|
37
|
-
}
|
38
|
-
|
39
|
-
static VALUE rxml_schema_attribute_name(VALUE self)
|
40
|
-
{
|
41
|
-
xmlSchemaAttributeUsePtr attr;
|
42
|
-
const xmlChar *name;
|
43
|
-
|
44
|
-
Data_Get_Struct(self, xmlSchemaAttributeUse, attr);
|
45
|
-
|
46
|
-
if (attr == NULL)
|
47
|
-
return Qnil;
|
48
|
-
|
49
|
-
if (attr->type == XML_SCHEMA_EXTRA_ATTR_USE_PROHIB) {
|
50
|
-
name = ((xmlSchemaAttributeUseProhibPtr) attr)->name;
|
51
|
-
} else if (attr->type == XML_SCHEMA_EXTRA_QNAMEREF) {
|
52
|
-
name = ((xmlSchemaQNameRefPtr) attr)->name;
|
53
|
-
} else {
|
54
|
-
xmlSchemaAttributePtr attrDecl = ((xmlSchemaAttributeUsePtr) attr)->attrDecl;
|
55
|
-
name = attrDecl->name;
|
56
|
-
}
|
57
|
-
|
58
|
-
QNIL_OR_STRING(name)
|
59
|
-
}
|
60
|
-
|
61
|
-
static VALUE rxml_schema_attribute_type(VALUE self)
|
62
|
-
{
|
63
|
-
xmlSchemaAttributeUsePtr attr;
|
64
|
-
xmlSchemaTypePtr xtype;
|
65
|
-
|
66
|
-
Data_Get_Struct(self, xmlSchemaAttributeUse, attr);
|
67
|
-
|
68
|
-
xtype = attr->attrDecl->subtypes;
|
69
|
-
|
70
|
-
return rxml_wrap_schema_type((xmlSchemaTypePtr) xtype);
|
39
|
+
return result;
|
71
40
|
}
|
72
41
|
|
73
42
|
static VALUE rxml_schema_attribute_node(VALUE self)
|
@@ -79,31 +48,14 @@ static VALUE rxml_schema_attribute_node(VALUE self)
|
|
79
48
|
return rxml_node_wrap(attr->node);
|
80
49
|
}
|
81
50
|
|
82
|
-
static VALUE rxml_schema_attribute_value(VALUE self)
|
83
|
-
{
|
84
|
-
xmlSchemaAttributeUsePtr attr;
|
85
|
-
|
86
|
-
Data_Get_Struct(self, xmlSchemaAttributeUse, attr);
|
87
|
-
|
88
|
-
QNIL_OR_STRING(attr->defValue)
|
89
|
-
}
|
90
|
-
|
91
|
-
static VALUE rxml_schema_attribute_occurs(VALUE self)
|
92
|
-
{
|
93
|
-
xmlSchemaAttributeUsePtr attr;
|
94
|
-
|
95
|
-
Data_Get_Struct(self, xmlSchemaAttributeUse, attr);
|
96
|
-
|
97
|
-
return INT2NUM(attr->occurs);
|
98
|
-
}
|
99
|
-
|
100
51
|
void rxml_init_schema_attribute(void)
|
101
52
|
{
|
102
53
|
cXMLSchemaAttribute = rb_define_class_under(cXMLSchema, "Attribute", rb_cObject);
|
103
|
-
|
104
|
-
|
105
|
-
|
54
|
+
rb_define_attr(cXMLSchemaAttribute, "name", 1, 0);
|
55
|
+
rb_define_attr(cXMLSchemaAttribute, "type", 1, 0);
|
56
|
+
rb_define_attr(cXMLSchemaAttribute, "namespace", 1, 0);
|
57
|
+
rb_define_attr(cXMLSchemaAttribute, "value", 1, 0);
|
58
|
+
rb_define_attr(cXMLSchemaAttribute, "occurs", 1, 0);
|
59
|
+
|
106
60
|
rb_define_method(cXMLSchemaAttribute, "node", rxml_schema_attribute_node, 0);
|
107
|
-
rb_define_method(cXMLSchemaAttribute, "value", rxml_schema_attribute_value, 0);
|
108
|
-
rb_define_method(cXMLSchemaAttribute, "occurs", rxml_schema_attribute_occurs, 0);
|
109
61
|
}
|
@@ -10,40 +10,21 @@ static void rxml_schema_element_free(xmlSchemaElementPtr xschema_element)
|
|
10
10
|
xmlFree(xschema_element);
|
11
11
|
}
|
12
12
|
|
13
|
-
VALUE rxml_wrap_schema_element(xmlSchemaElementPtr
|
13
|
+
VALUE rxml_wrap_schema_element(xmlSchemaElementPtr xelem)
|
14
14
|
{
|
15
|
-
|
16
|
-
}
|
15
|
+
VALUE result;
|
17
16
|
|
18
|
-
|
19
|
-
|
20
|
-
xmlSchemaElementPtr xelem;
|
17
|
+
if (!xelem)
|
18
|
+
rb_raise(rb_eArgError, "XML::Schema::Element is required!");
|
21
19
|
|
22
|
-
|
20
|
+
result = Data_Wrap_Struct(cXMLSchemaElement, NULL, rxml_schema_element_free, xelem);
|
23
21
|
|
24
|
-
QNIL_OR_STRING(xelem->
|
25
|
-
|
22
|
+
rb_iv_set(result, "@name", QNIL_OR_STRING(xelem->name));
|
23
|
+
rb_iv_set(result, "@value", QNIL_OR_STRING(xelem->value));
|
24
|
+
rb_iv_set(result, "@namespace", QNIL_OR_STRING(xelem->targetNamespace));
|
25
|
+
rb_iv_set(result, "@type", rxml_wrap_schema_type((xmlSchemaTypePtr) (xelem->subtypes)));
|
26
26
|
|
27
|
-
|
28
|
-
{
|
29
|
-
xmlSchemaElementPtr xelem;
|
30
|
-
|
31
|
-
Data_Get_Struct(self, xmlSchemaElement, xelem);
|
32
|
-
|
33
|
-
|
34
|
-
QNIL_OR_STRING(xelem->name)
|
35
|
-
}
|
36
|
-
|
37
|
-
static VALUE rxml_schema_element_type(VALUE self)
|
38
|
-
{
|
39
|
-
xmlSchemaElementPtr xelem;
|
40
|
-
xmlSchemaTypePtr xtype;
|
41
|
-
|
42
|
-
Data_Get_Struct(self, xmlSchemaElement, xelem);
|
43
|
-
|
44
|
-
xtype = xelem->subtypes;
|
45
|
-
|
46
|
-
return rxml_wrap_schema_type((xmlSchemaTypePtr) xtype);
|
27
|
+
return result;
|
47
28
|
}
|
48
29
|
|
49
30
|
static VALUE rxml_schema_element_node(VALUE self)
|
@@ -55,41 +36,34 @@ static VALUE rxml_schema_element_node(VALUE self)
|
|
55
36
|
return rxml_node_wrap(xelem->node);
|
56
37
|
}
|
57
38
|
|
58
|
-
static VALUE
|
39
|
+
static VALUE rxml_schema_element_annot(VALUE self)
|
59
40
|
{
|
60
41
|
xmlSchemaElementPtr xelem;
|
42
|
+
VALUE annotation = Qnil;
|
61
43
|
|
62
44
|
Data_Get_Struct(self, xmlSchemaElement, xelem);
|
63
45
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
{
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
{
|
76
|
-
xmlChar *content = xmlNodeGetContent(xelem->annot->content);
|
77
|
-
if (content)
|
78
|
-
{
|
79
|
-
result = rxml_new_cstr(content, NULL);
|
80
|
-
xmlFree(content);
|
81
|
-
}
|
82
|
-
}
|
83
|
-
return result;
|
46
|
+
if ((xelem->annot != NULL) && (xelem->annot->content != NULL))
|
47
|
+
{
|
48
|
+
xmlChar *content = xmlNodeGetContent(xelem->annot->content);
|
49
|
+
if (content)
|
50
|
+
{
|
51
|
+
annotation = rxml_new_cstr(content, NULL);
|
52
|
+
xmlFree(content);
|
53
|
+
}
|
54
|
+
}
|
55
|
+
|
56
|
+
return annotation;
|
84
57
|
}
|
85
58
|
|
86
59
|
void rxml_init_schema_element(void)
|
87
60
|
{
|
88
61
|
cXMLSchemaElement = rb_define_class_under(cXMLSchema, "Element", rb_cObject);
|
89
|
-
|
90
|
-
|
91
|
-
|
62
|
+
rb_define_attr(cXMLSchemaElement, "name", 1, 0);
|
63
|
+
rb_define_attr(cXMLSchemaElement, "value", 1, 0);
|
64
|
+
rb_define_attr(cXMLSchemaElement, "namespace", 1, 0);
|
65
|
+
rb_define_attr(cXMLSchemaElement, "type", 1, 0);
|
66
|
+
|
92
67
|
rb_define_method(cXMLSchemaElement, "node", rxml_schema_element_node, 0);
|
93
|
-
rb_define_method(cXMLSchemaElement, "value", rxml_schema_element_value, 0);
|
94
68
|
rb_define_method(cXMLSchemaElement, "annotation", rxml_schema_element_annot, 0);
|
95
69
|
}
|
@@ -9,44 +9,38 @@ static void rxml_schema_facet_free(xmlSchemaFacetPtr xschema_type)
|
|
9
9
|
xmlFree(xschema_type);
|
10
10
|
}
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
static VALUE rxml_schema_facet_node(VALUE self)
|
12
|
+
VALUE rxml_wrap_schema_facet(xmlSchemaFacetPtr facet)
|
15
13
|
{
|
16
|
-
|
14
|
+
VALUE result;
|
17
15
|
|
18
|
-
|
16
|
+
if (!facet)
|
17
|
+
rb_raise(rb_eArgError, "XML::Schema::Facet required!");
|
19
18
|
|
20
|
-
|
21
|
-
}
|
19
|
+
result = Data_Wrap_Struct(cXMLSchemaFacet, NULL, rxml_schema_facet_free, facet);
|
22
20
|
|
23
|
-
|
24
|
-
|
25
|
-
xmlSchemaFacetPtr facet;
|
21
|
+
rb_iv_set(result, "@kind", INT2NUM(facet->type));
|
22
|
+
rb_iv_set(result, "@value", QNIL_OR_STRING(facet->value));
|
26
23
|
|
27
|
-
|
24
|
+
return result;
|
28
25
|
|
29
|
-
QNIL_OR_STRING(facet->value)
|
30
26
|
}
|
31
27
|
|
32
|
-
|
28
|
+
/* START FACET*/
|
29
|
+
|
30
|
+
static VALUE rxml_schema_facet_node(VALUE self)
|
33
31
|
{
|
34
32
|
xmlSchemaFacetPtr facet;
|
35
33
|
|
36
34
|
Data_Get_Struct(self, xmlSchemaFacet, facet);
|
37
35
|
|
38
|
-
return
|
39
|
-
}
|
40
|
-
|
41
|
-
VALUE rxml_wrap_schema_facet(xmlSchemaFacetPtr facet)
|
42
|
-
{
|
43
|
-
return Data_Wrap_Struct(cXMLSchemaFacet, NULL, rxml_schema_facet_free, facet);
|
36
|
+
return rxml_node_wrap(facet->node);
|
44
37
|
}
|
45
38
|
|
46
39
|
void rxml_init_schema_facet(void)
|
47
40
|
{
|
48
41
|
cXMLSchemaFacet = rb_define_class_under(cXMLSchema, "Facet", rb_cObject);
|
49
|
-
|
42
|
+
rb_define_attr(cXMLSchemaFacet, "kind", 1, 0);
|
43
|
+
rb_define_attr(cXMLSchemaFacet, "value", 1, 0);
|
44
|
+
|
50
45
|
rb_define_method(cXMLSchemaFacet, "node", rxml_schema_facet_node, 0);
|
51
|
-
rb_define_method(cXMLSchemaFacet, "kind", rxml_schema_facet_kind, 0);
|
52
46
|
}
|