libxml-ruby 0.9.9-x86-mswin32-60 → 1.0.0-x86-mswin32-60

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,257 +1,257 @@
1
- #include "ruby_libxml.h"
2
- #include "ruby_xml_dtd.h"
3
-
4
- /*
5
- * Document-class: LibXML::XML::Dtd
6
- *
7
- * The XML::Dtd class is used to prepare DTD's for validation of xml
8
- * documents.
9
- *
10
- * DTDs can be created from a string or a pair of public and system identifiers.
11
- * Once a Dtd object is instantiated, an XML document can be validated by the
12
- * XML::Document#validate method providing the XML::Dtd object as parameeter.
13
- * The method will raise an exception if the document is
14
- * not valid.
15
- *
16
- * Basic usage:
17
- *
18
- * # parse DTD
19
- * dtd = XML::Dtd.new(<<EOF)
20
- * <!ELEMENT root (item*) >
21
- * <!ELEMENT item (#PCDATA) >
22
- * EOF
23
- *
24
- * # parse xml document to be validated
25
- * instance = XML::Document.file('instance.xml')
26
- *
27
- * # validate
28
- * instance.validate(dtd)
29
- */
30
-
31
- VALUE cXMLDtd;
32
-
33
- void rxml_dtd_free(xmlDtdPtr xdtd)
34
- {
35
- /* Set _private to NULL so that we won't reuse the
36
- same, freed, Ruby wrapper object later.*/
37
- xdtd->_private = NULL;
38
-
39
- if (xdtd->doc == NULL && xdtd->parent == NULL)
40
- xmlFreeDtd(xdtd);
41
- }
42
-
43
- void rxml_dtd_mark(xmlDtdPtr xdtd)
44
- {
45
- if (xdtd == NULL)
46
- return;
47
-
48
- if (xdtd->_private == NULL)
49
- {
50
- rb_warning("XmlNode is not bound! (%s:%d)", __FILE__, __LINE__);
51
- return;
52
- }
53
-
54
- rxml_node_mark_common((xmlNodePtr) xdtd);
55
- }
56
-
57
-
58
- static VALUE rxml_dtd_alloc(VALUE klass)
59
- {
60
- return Data_Wrap_Struct(klass, rxml_dtd_mark, rxml_dtd_free, NULL);
61
- }
62
-
63
- VALUE rxml_dtd_wrap(xmlDtdPtr xdtd)
64
- {
65
- VALUE result;
66
-
67
- // This node is already wrapped
68
- if (xdtd->_private != NULL)
69
- return (VALUE) xdtd->_private;
70
-
71
- result = Data_Wrap_Struct(cXMLDtd, NULL, NULL, xdtd);
72
-
73
- xdtd->_private = (void*) result;
74
-
75
- return result;
76
- }
77
-
78
- /*
79
- * call-seq:
80
- * dtd.external_id -> "string"
81
- *
82
- * Obtain this dtd's external identifer (for a PUBLIC DTD).
83
- */
84
- static VALUE rxml_dtd_external_id_get(VALUE self)
85
- {
86
- xmlDtdPtr xdtd;
87
- Data_Get_Struct(self, xmlDtd, xdtd);
88
-
89
-
90
- if (xdtd->ExternalID == NULL)
91
- return (Qnil);
92
- else
93
- return (rb_str_new2((const char*) xdtd->ExternalID));
94
- }
95
-
96
- /*
97
- * call-seq:
98
- * dtd.name -> "string"
99
- *
100
- * Obtain this dtd's name.
101
- */
102
- static VALUE rxml_dtd_name_get(VALUE self)
103
- {
104
- xmlDtdPtr xdtd;
105
- Data_Get_Struct(self, xmlDtd, xdtd);
106
-
107
-
108
- if (xdtd->name == NULL)
109
- return (Qnil);
110
- else
111
- return (rb_str_new2((const char*) xdtd->name));
112
- }
113
-
114
-
115
- /*
116
- * call-seq:
117
- * dtd.uri -> "string"
118
- *
119
- * Obtain this dtd's URI (for a SYSTEM or PUBLIC DTD).
120
- */
121
- static VALUE rxml_dtd_uri_get(VALUE self)
122
- {
123
- xmlDtdPtr xdtd;
124
- Data_Get_Struct(self, xmlDtd, xdtd);
125
-
126
-
127
- if (xdtd->SystemID == NULL)
128
- return (Qnil);
129
- else
130
- return (rb_str_new2((const char*) xdtd->SystemID));
131
- }
132
-
133
- /*
134
- * call-seq:
135
- * XML::Dtd.new("DTD string") -> dtd
136
- * XML::Dtd.new("public", "system") -> dtd
137
- * XML::Dtd.new("name", "public", "system", document) -> external subset dtd
138
- * XML::Dtd.new("name", "public", "system", document, false) -> internal subset dtd
139
- * XML::Dtd.new("name", "public", "system", document, true) -> internal subset dtd
140
- *
141
- * Create a new Dtd from the specified public and system
142
- * identifiers.
143
- */
144
- static VALUE rxml_dtd_initialize(int argc, VALUE *argv, VALUE self)
145
- {
146
- VALUE external, system, dtd_string;
147
- xmlParserInputBufferPtr buffer;
148
- xmlCharEncoding enc = XML_CHAR_ENCODING_NONE;
149
- xmlChar *new_string;
150
- xmlDtdPtr xdtd;
151
-
152
- // 1 argument -- string --> parsujeme jako dtd
153
- // 2 arguments -- public, system --> bude se hledat
154
- // 3 arguments -- public, system, name --> creates an external subset (any parameter may be nil)
155
- // 4 arguments -- public, system, name, doc --> creates an external subset (any parameter may be nil)
156
- // 5 arguments -- public, system, name, doc, true --> creates an internal subset (all but last parameter may be nil)
157
- switch (argc)
158
- {
159
- case 3:
160
- case 4:
161
- case 5: {
162
- VALUE name, doc, internal;
163
- const xmlChar *xname = NULL, *xpublic = NULL, *xsystem = NULL;
164
- xmlDocPtr xdoc = NULL;
165
-
166
- rb_scan_args(argc, argv, "32", &external, &system, &name, &doc, &internal);
167
-
168
- if (external != Qnil) {
169
- Check_Type(external, T_STRING);
170
- xpublic = (const xmlChar*) StringValuePtr(external);
171
- }
172
- if (system != Qnil) {
173
- Check_Type(system, T_STRING);
174
- xsystem = (const xmlChar*) StringValuePtr(system);
175
- }
176
- if (name != Qnil) {
177
- Check_Type(name, T_STRING);
178
- xname = (const xmlChar*) StringValuePtr(name);
179
- }
180
- if (doc != Qnil) {
181
- if (rb_obj_is_kind_of(doc, cXMLDocument) == Qfalse)
182
- rb_raise(rb_eTypeError, "Must pass an XML::Document object");
183
- Data_Get_Struct(doc, xmlDoc, xdoc);
184
- }
185
-
186
- if (internal == Qnil || internal == Qfalse)
187
- xdtd = xmlNewDtd(xdoc, xname, xpublic, xsystem);
188
- else
189
- xdtd = xmlCreateIntSubset(xdoc, xname, xpublic, xsystem);
190
-
191
- if (xdtd == NULL)
192
- rxml_raise(&xmlLastError);
193
-
194
- /* Document will free this dtd now. */
195
- RDATA(self)->dfree = NULL;
196
- DATA_PTR(self) = xdtd;
197
-
198
- xmlSetTreeDoc((xmlNodePtr) xdtd, xdoc);
199
- }
200
- break;
201
-
202
- case 2:
203
- rb_scan_args(argc, argv, "20", &external, &system);
204
-
205
- Check_Type(external, T_STRING);
206
- Check_Type(system, T_STRING);
207
-
208
- xdtd = xmlParseDTD((xmlChar*) StringValuePtr(external),
209
- (xmlChar*) StringValuePtr(system));
210
-
211
- if (xdtd == NULL)
212
- rxml_raise(&xmlLastError);
213
-
214
- DATA_PTR(self) = xdtd;
215
-
216
- xmlSetTreeDoc((xmlNodePtr) xdtd, NULL);
217
- break;
218
-
219
- case 1:
220
- rb_scan_args(argc, argv, "10", &dtd_string);
221
- Check_Type(dtd_string, T_STRING);
222
-
223
- /* Note that buffer is freed by xmlParserInputBufferPush*/
224
- buffer = xmlAllocParserInputBuffer(enc);
225
- new_string = xmlStrdup((xmlChar*) StringValuePtr(dtd_string));
226
- xmlParserInputBufferPush(buffer, xmlStrlen(new_string),
227
- (const char*) new_string);
228
-
229
- xdtd = xmlIOParseDTD(NULL, buffer, enc);
230
-
231
- if (xdtd == NULL)
232
- rxml_raise(&xmlLastError);
233
-
234
- xmlFree(new_string);
235
-
236
- DATA_PTR(self) = xdtd;
237
- break;
238
-
239
- default:
240
- rb_raise(rb_eArgError, "wrong number of arguments");
241
- }
242
-
243
- return self;
244
- }
245
-
246
- void rxml_init_dtd()
247
- {
248
- cXMLDtd = rb_define_class_under(mXML, "Dtd", rb_cObject);
249
- rb_define_alloc_func(cXMLDtd, rxml_dtd_alloc);
250
- rb_define_method(cXMLDtd, "initialize", rxml_dtd_initialize, -1);
251
- rb_define_method(cXMLDtd, "external_id", rxml_dtd_external_id_get, 0);
252
- rb_define_method(cXMLDtd, "name", rxml_dtd_name_get, 0);
253
- rb_define_method(cXMLDtd, "uri", rxml_dtd_uri_get, 0);
254
-
255
- rb_define_alias(cXMLDtd, "system_id", "uri");
256
- }
257
-
1
+ #include "ruby_libxml.h"
2
+ #include "ruby_xml_dtd.h"
3
+
4
+ /*
5
+ * Document-class: LibXML::XML::Dtd
6
+ *
7
+ * The XML::Dtd class is used to prepare DTD's for validation of xml
8
+ * documents.
9
+ *
10
+ * DTDs can be created from a string or a pair of public and system identifiers.
11
+ * Once a Dtd object is instantiated, an XML document can be validated by the
12
+ * XML::Document#validate method providing the XML::Dtd object as parameeter.
13
+ * The method will raise an exception if the document is
14
+ * not valid.
15
+ *
16
+ * Basic usage:
17
+ *
18
+ * # parse DTD
19
+ * dtd = XML::Dtd.new(<<EOF)
20
+ * <!ELEMENT root (item*) >
21
+ * <!ELEMENT item (#PCDATA) >
22
+ * EOF
23
+ *
24
+ * # parse xml document to be validated
25
+ * instance = XML::Document.file('instance.xml')
26
+ *
27
+ * # validate
28
+ * instance.validate(dtd)
29
+ */
30
+
31
+ VALUE cXMLDtd;
32
+
33
+ void rxml_dtd_free(xmlDtdPtr xdtd)
34
+ {
35
+ /* Set _private to NULL so that we won't reuse the
36
+ same, freed, Ruby wrapper object later.*/
37
+ xdtd->_private = NULL;
38
+
39
+ if (xdtd->doc == NULL && xdtd->parent == NULL)
40
+ xmlFreeDtd(xdtd);
41
+ }
42
+
43
+ void rxml_dtd_mark(xmlDtdPtr xdtd)
44
+ {
45
+ if (xdtd == NULL)
46
+ return;
47
+
48
+ if (xdtd->_private == NULL)
49
+ {
50
+ rb_warning("XmlNode is not bound! (%s:%d)", __FILE__, __LINE__);
51
+ return;
52
+ }
53
+
54
+ rxml_node_mark_common((xmlNodePtr) xdtd);
55
+ }
56
+
57
+
58
+ static VALUE rxml_dtd_alloc(VALUE klass)
59
+ {
60
+ return Data_Wrap_Struct(klass, rxml_dtd_mark, rxml_dtd_free, NULL);
61
+ }
62
+
63
+ VALUE rxml_dtd_wrap(xmlDtdPtr xdtd)
64
+ {
65
+ VALUE result;
66
+
67
+ // This node is already wrapped
68
+ if (xdtd->_private != NULL)
69
+ return (VALUE) xdtd->_private;
70
+
71
+ result = Data_Wrap_Struct(cXMLDtd, NULL, NULL, xdtd);
72
+
73
+ xdtd->_private = (void*) result;
74
+
75
+ return result;
76
+ }
77
+
78
+ /*
79
+ * call-seq:
80
+ * dtd.external_id -> "string"
81
+ *
82
+ * Obtain this dtd's external identifer (for a PUBLIC DTD).
83
+ */
84
+ static VALUE rxml_dtd_external_id_get(VALUE self)
85
+ {
86
+ xmlDtdPtr xdtd;
87
+ Data_Get_Struct(self, xmlDtd, xdtd);
88
+
89
+
90
+ if (xdtd->ExternalID == NULL)
91
+ return (Qnil);
92
+ else
93
+ return (rb_str_new2((const char*) xdtd->ExternalID));
94
+ }
95
+
96
+ /*
97
+ * call-seq:
98
+ * dtd.name -> "string"
99
+ *
100
+ * Obtain this dtd's name.
101
+ */
102
+ static VALUE rxml_dtd_name_get(VALUE self)
103
+ {
104
+ xmlDtdPtr xdtd;
105
+ Data_Get_Struct(self, xmlDtd, xdtd);
106
+
107
+
108
+ if (xdtd->name == NULL)
109
+ return (Qnil);
110
+ else
111
+ return (rb_str_new2((const char*) xdtd->name));
112
+ }
113
+
114
+
115
+ /*
116
+ * call-seq:
117
+ * dtd.uri -> "string"
118
+ *
119
+ * Obtain this dtd's URI (for a SYSTEM or PUBLIC DTD).
120
+ */
121
+ static VALUE rxml_dtd_uri_get(VALUE self)
122
+ {
123
+ xmlDtdPtr xdtd;
124
+ Data_Get_Struct(self, xmlDtd, xdtd);
125
+
126
+
127
+ if (xdtd->SystemID == NULL)
128
+ return (Qnil);
129
+ else
130
+ return (rb_str_new2((const char*) xdtd->SystemID));
131
+ }
132
+
133
+ /*
134
+ * call-seq:
135
+ * XML::Dtd.new("DTD string") -> dtd
136
+ * XML::Dtd.new("public", "system") -> dtd
137
+ * XML::Dtd.new("name", "public", "system", document) -> external subset dtd
138
+ * XML::Dtd.new("name", "public", "system", document, false) -> internal subset dtd
139
+ * XML::Dtd.new("name", "public", "system", document, true) -> internal subset dtd
140
+ *
141
+ * Create a new Dtd from the specified public and system
142
+ * identifiers.
143
+ */
144
+ static VALUE rxml_dtd_initialize(int argc, VALUE *argv, VALUE self)
145
+ {
146
+ VALUE external, system, dtd_string;
147
+ xmlParserInputBufferPtr buffer;
148
+ xmlCharEncoding enc = XML_CHAR_ENCODING_NONE;
149
+ xmlChar *new_string;
150
+ xmlDtdPtr xdtd;
151
+
152
+ // 1 argument -- string --> parsujeme jako dtd
153
+ // 2 arguments -- public, system --> bude se hledat
154
+ // 3 arguments -- public, system, name --> creates an external subset (any parameter may be nil)
155
+ // 4 arguments -- public, system, name, doc --> creates an external subset (any parameter may be nil)
156
+ // 5 arguments -- public, system, name, doc, true --> creates an internal subset (all but last parameter may be nil)
157
+ switch (argc)
158
+ {
159
+ case 3:
160
+ case 4:
161
+ case 5: {
162
+ VALUE name, doc, internal;
163
+ const xmlChar *xname = NULL, *xpublic = NULL, *xsystem = NULL;
164
+ xmlDocPtr xdoc = NULL;
165
+
166
+ rb_scan_args(argc, argv, "32", &external, &system, &name, &doc, &internal);
167
+
168
+ if (external != Qnil) {
169
+ Check_Type(external, T_STRING);
170
+ xpublic = (const xmlChar*) StringValuePtr(external);
171
+ }
172
+ if (system != Qnil) {
173
+ Check_Type(system, T_STRING);
174
+ xsystem = (const xmlChar*) StringValuePtr(system);
175
+ }
176
+ if (name != Qnil) {
177
+ Check_Type(name, T_STRING);
178
+ xname = (const xmlChar*) StringValuePtr(name);
179
+ }
180
+ if (doc != Qnil) {
181
+ if (rb_obj_is_kind_of(doc, cXMLDocument) == Qfalse)
182
+ rb_raise(rb_eTypeError, "Must pass an XML::Document object");
183
+ Data_Get_Struct(doc, xmlDoc, xdoc);
184
+ }
185
+
186
+ if (internal == Qnil || internal == Qfalse)
187
+ xdtd = xmlNewDtd(xdoc, xname, xpublic, xsystem);
188
+ else
189
+ xdtd = xmlCreateIntSubset(xdoc, xname, xpublic, xsystem);
190
+
191
+ if (xdtd == NULL)
192
+ rxml_raise(&xmlLastError);
193
+
194
+ /* Document will free this dtd now. */
195
+ RDATA(self)->dfree = NULL;
196
+ DATA_PTR(self) = xdtd;
197
+
198
+ xmlSetTreeDoc((xmlNodePtr) xdtd, xdoc);
199
+ }
200
+ break;
201
+
202
+ case 2:
203
+ rb_scan_args(argc, argv, "20", &external, &system);
204
+
205
+ Check_Type(external, T_STRING);
206
+ Check_Type(system, T_STRING);
207
+
208
+ xdtd = xmlParseDTD((xmlChar*) StringValuePtr(external),
209
+ (xmlChar*) StringValuePtr(system));
210
+
211
+ if (xdtd == NULL)
212
+ rxml_raise(&xmlLastError);
213
+
214
+ DATA_PTR(self) = xdtd;
215
+
216
+ xmlSetTreeDoc((xmlNodePtr) xdtd, NULL);
217
+ break;
218
+
219
+ case 1:
220
+ rb_scan_args(argc, argv, "10", &dtd_string);
221
+ Check_Type(dtd_string, T_STRING);
222
+
223
+ /* Note that buffer is freed by xmlParserInputBufferPush*/
224
+ buffer = xmlAllocParserInputBuffer(enc);
225
+ new_string = xmlStrdup((xmlChar*) StringValuePtr(dtd_string));
226
+ xmlParserInputBufferPush(buffer, xmlStrlen(new_string),
227
+ (const char*) new_string);
228
+
229
+ xdtd = xmlIOParseDTD(NULL, buffer, enc);
230
+
231
+ if (xdtd == NULL)
232
+ rxml_raise(&xmlLastError);
233
+
234
+ xmlFree(new_string);
235
+
236
+ DATA_PTR(self) = xdtd;
237
+ break;
238
+
239
+ default:
240
+ rb_raise(rb_eArgError, "wrong number of arguments");
241
+ }
242
+
243
+ return self;
244
+ }
245
+
246
+ void rxml_init_dtd()
247
+ {
248
+ cXMLDtd = rb_define_class_under(mXML, "Dtd", rb_cObject);
249
+ rb_define_alloc_func(cXMLDtd, rxml_dtd_alloc);
250
+ rb_define_method(cXMLDtd, "initialize", rxml_dtd_initialize, -1);
251
+ rb_define_method(cXMLDtd, "external_id", rxml_dtd_external_id_get, 0);
252
+ rb_define_method(cXMLDtd, "name", rxml_dtd_name_get, 0);
253
+ rb_define_method(cXMLDtd, "uri", rxml_dtd_uri_get, 0);
254
+
255
+ rb_define_alias(cXMLDtd, "system_id", "uri");
256
+ }
257
+