libxml-ruby 2.7.0 → 2.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +6 -14
- data/HISTORY +33 -11
- data/README.rdoc +7 -7
- data/Rakefile +80 -77
- data/ext/libxml/extconf.h +4 -5
- data/ext/libxml/extconf.rb +57 -118
- data/ext/libxml/libxml.c +4 -0
- data/ext/libxml/ruby_xml.c +977 -893
- data/ext/libxml/ruby_xml.h +20 -10
- data/ext/libxml/ruby_xml_attr.c +333 -333
- data/ext/libxml/ruby_xml_attr_decl.c +2 -2
- data/ext/libxml/ruby_xml_cbg.c +85 -85
- data/ext/libxml/ruby_xml_document.c +1133 -1147
- data/ext/libxml/ruby_xml_dtd.c +261 -268
- data/ext/libxml/ruby_xml_encoding.c +262 -260
- data/ext/libxml/ruby_xml_encoding.h +19 -19
- data/ext/libxml/ruby_xml_html_parser_context.c +337 -338
- data/ext/libxml/ruby_xml_input_cbg.c +191 -191
- data/ext/libxml/ruby_xml_io.c +52 -50
- data/ext/libxml/ruby_xml_namespace.c +2 -2
- data/ext/libxml/ruby_xml_node.c +1446 -1452
- data/ext/libxml/ruby_xml_parser_context.c +999 -1001
- data/ext/libxml/ruby_xml_reader.c +1226 -1228
- data/ext/libxml/ruby_xml_relaxng.c +110 -111
- data/ext/libxml/ruby_xml_sax2_handler.c +326 -328
- data/ext/libxml/ruby_xml_schema.c +300 -301
- data/ext/libxml/ruby_xml_version.h +3 -3
- data/ext/libxml/ruby_xml_writer.c +34 -16
- data/ext/libxml/ruby_xml_xpath.c +188 -187
- data/ext/libxml/ruby_xml_xpath_context.c +360 -361
- data/ext/libxml/ruby_xml_xpath_object.c +335 -335
- data/libxml-ruby.gemspec +47 -44
- data/test/tc_attr.rb +5 -7
- data/test/tc_attr_decl.rb +5 -6
- data/test/tc_attributes.rb +1 -2
- data/test/tc_canonicalize.rb +1 -2
- data/test/tc_deprecated_require.rb +1 -2
- data/test/tc_document.rb +4 -5
- data/test/tc_document_write.rb +2 -3
- data/test/tc_dtd.rb +4 -5
- data/test/tc_encoding.rb +126 -126
- data/test/tc_encoding_sax.rb +4 -3
- data/test/tc_error.rb +14 -15
- data/test/tc_html_parser.rb +15 -7
- data/test/tc_html_parser_context.rb +1 -2
- data/test/tc_namespace.rb +2 -3
- data/test/tc_namespaces.rb +5 -6
- data/test/tc_node.rb +2 -3
- data/test/tc_node_cdata.rb +2 -3
- data/test/tc_node_comment.rb +1 -2
- data/test/tc_node_copy.rb +1 -2
- data/test/tc_node_edit.rb +5 -7
- data/test/tc_node_pi.rb +1 -2
- data/test/tc_node_text.rb +2 -3
- data/test/tc_node_write.rb +2 -3
- data/test/tc_node_xlink.rb +1 -2
- data/test/tc_parser.rb +18 -24
- data/test/tc_parser_context.rb +6 -7
- data/test/tc_properties.rb +1 -2
- data/test/tc_reader.rb +9 -10
- data/test/tc_relaxng.rb +4 -5
- data/test/tc_sax_parser.rb +9 -10
- data/test/tc_schema.rb +4 -5
- data/test/tc_traversal.rb +1 -2
- data/test/tc_writer.rb +1 -2
- data/test/tc_xinclude.rb +1 -2
- data/test/tc_xml.rb +1 -2
- data/test/tc_xpath.rb +8 -9
- data/test/tc_xpath_context.rb +3 -4
- data/test/tc_xpath_expression.rb +3 -4
- data/test/tc_xpointer.rb +1 -3
- data/test/test_helper.rb +3 -1
- data/test/test_suite.rb +0 -1
- metadata +90 -72
- data/test/etc_doc_to_s.rb +0 -21
- data/test/ets_doc_file.rb +0 -17
- data/test/ets_doc_to_s.rb +0 -23
- data/test/ets_gpx.rb +0 -28
- data/test/ets_node_gc.rb +0 -23
- data/test/ets_test.xml +0 -2
- data/test/ets_tsr.rb +0 -11
- data/test/model/kml_sample.xml +0 -915
- data/test/remove_test.rb +0 -9
- data/test/tc_gc.rb +0 -86
- data/test/tc_parser.rb.orig +0 -384
data/ext/libxml/ruby_xml_dtd.c
CHANGED
@@ -1,268 +1,261 @@
|
|
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
|
-
/*
|
36
|
-
same, freed, Ruby wrapper object later.*/
|
37
|
-
xdtd
|
38
|
-
|
39
|
-
if (xdtd->doc == NULL && xdtd->parent == NULL)
|
40
|
-
xmlFreeDtd(xdtd);
|
41
|
-
}
|
42
|
-
|
43
|
-
void rxml_dtd_mark(xmlDtdPtr xdtd)
|
44
|
-
{
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
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
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
if (
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
cXMLDtd
|
260
|
-
|
261
|
-
|
262
|
-
rb_define_method(cXMLDtd, "external_id", rxml_dtd_external_id_get, 0);
|
263
|
-
rb_define_method(cXMLDtd, "name", rxml_dtd_name_get, 0);
|
264
|
-
rb_define_method(cXMLDtd, "uri", rxml_dtd_uri_get, 0);
|
265
|
-
rb_define_method(cXMLDtd, "node_type", rxml_dtd_type, 0);
|
266
|
-
rb_define_alias(cXMLDtd, "system_id", "uri");
|
267
|
-
}
|
268
|
-
|
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
|
+
/* Clear our private pointer so that we won't reuse the
|
36
|
+
same, freed, Ruby wrapper object later.*/
|
37
|
+
rxml_unregister_dtd(xdtd);
|
38
|
+
|
39
|
+
if (xdtd->doc == NULL && xdtd->parent == NULL)
|
40
|
+
xmlFreeDtd(xdtd);
|
41
|
+
}
|
42
|
+
|
43
|
+
void rxml_dtd_mark(xmlDtdPtr xdtd)
|
44
|
+
{
|
45
|
+
VALUE doc = Qnil;
|
46
|
+
|
47
|
+
if (xdtd == NULL)
|
48
|
+
return;
|
49
|
+
|
50
|
+
doc = rxml_lookup_doc(xdtd->doc);
|
51
|
+
rb_gc_mark(doc);
|
52
|
+
}
|
53
|
+
|
54
|
+
static VALUE rxml_dtd_alloc(VALUE klass)
|
55
|
+
{
|
56
|
+
return Data_Wrap_Struct(klass, rxml_dtd_mark, rxml_dtd_free, NULL);
|
57
|
+
}
|
58
|
+
|
59
|
+
VALUE rxml_dtd_wrap(xmlDtdPtr xdtd)
|
60
|
+
{
|
61
|
+
VALUE result = rxml_lookup_dtd(xdtd);
|
62
|
+
|
63
|
+
// This node is already wrapped
|
64
|
+
if (result == Qnil) {
|
65
|
+
result = Data_Wrap_Struct(cXMLDtd, NULL, NULL, xdtd);
|
66
|
+
rxml_register_dtd(xdtd, result);
|
67
|
+
}
|
68
|
+
return result;
|
69
|
+
}
|
70
|
+
|
71
|
+
/*
|
72
|
+
* call-seq:
|
73
|
+
* dtd.external_id -> "string"
|
74
|
+
*
|
75
|
+
* Obtain this dtd's external identifer (for a PUBLIC DTD).
|
76
|
+
*/
|
77
|
+
static VALUE rxml_dtd_external_id_get(VALUE self)
|
78
|
+
{
|
79
|
+
xmlDtdPtr xdtd;
|
80
|
+
Data_Get_Struct(self, xmlDtd, xdtd);
|
81
|
+
|
82
|
+
|
83
|
+
if (xdtd->ExternalID == NULL)
|
84
|
+
return (Qnil);
|
85
|
+
else
|
86
|
+
return (rxml_new_cstr( xdtd->ExternalID, NULL));
|
87
|
+
}
|
88
|
+
|
89
|
+
/*
|
90
|
+
* call-seq:
|
91
|
+
* dtd.name -> "string"
|
92
|
+
*
|
93
|
+
* Obtain this dtd's name.
|
94
|
+
*/
|
95
|
+
static VALUE rxml_dtd_name_get(VALUE self)
|
96
|
+
{
|
97
|
+
xmlDtdPtr xdtd;
|
98
|
+
Data_Get_Struct(self, xmlDtd, xdtd);
|
99
|
+
|
100
|
+
|
101
|
+
if (xdtd->name == NULL)
|
102
|
+
return (Qnil);
|
103
|
+
else
|
104
|
+
return (rxml_new_cstr( xdtd->name, NULL));
|
105
|
+
}
|
106
|
+
|
107
|
+
|
108
|
+
/*
|
109
|
+
* call-seq:
|
110
|
+
* dtd.uri -> "string"
|
111
|
+
*
|
112
|
+
* Obtain this dtd's URI (for a SYSTEM or PUBLIC DTD).
|
113
|
+
*/
|
114
|
+
static VALUE rxml_dtd_uri_get(VALUE self)
|
115
|
+
{
|
116
|
+
xmlDtdPtr xdtd;
|
117
|
+
Data_Get_Struct(self, xmlDtd, xdtd);
|
118
|
+
|
119
|
+
if (xdtd->SystemID == NULL)
|
120
|
+
return (Qnil);
|
121
|
+
else
|
122
|
+
return (rxml_new_cstr( xdtd->SystemID, NULL));
|
123
|
+
}
|
124
|
+
|
125
|
+
/*
|
126
|
+
* call-seq:
|
127
|
+
* node.type -> num
|
128
|
+
*
|
129
|
+
* Obtain this node's type identifier.
|
130
|
+
*/
|
131
|
+
static VALUE rxml_dtd_type(VALUE self)
|
132
|
+
{
|
133
|
+
xmlDtdPtr xdtd;
|
134
|
+
Data_Get_Struct(self, xmlDtd, xdtd);
|
135
|
+
return (INT2NUM(xdtd->type));
|
136
|
+
}
|
137
|
+
|
138
|
+
/*
|
139
|
+
* call-seq:
|
140
|
+
* XML::Dtd.new("DTD string") -> dtd
|
141
|
+
* XML::Dtd.new("public", "system") -> dtd
|
142
|
+
* XML::Dtd.new("name", "public", "system", document) -> external subset dtd
|
143
|
+
* XML::Dtd.new("name", "public", "system", document, false) -> internal subset dtd
|
144
|
+
* XML::Dtd.new("name", "public", "system", document, true) -> internal subset dtd
|
145
|
+
*
|
146
|
+
* Create a new Dtd from the specified public and system
|
147
|
+
* identifiers.
|
148
|
+
*/
|
149
|
+
static VALUE rxml_dtd_initialize(int argc, VALUE *argv, VALUE self)
|
150
|
+
{
|
151
|
+
VALUE external, system, dtd_string;
|
152
|
+
xmlParserInputBufferPtr buffer;
|
153
|
+
xmlCharEncoding enc = XML_CHAR_ENCODING_NONE;
|
154
|
+
xmlChar *new_string;
|
155
|
+
xmlDtdPtr xdtd;
|
156
|
+
|
157
|
+
// 1 argument -- string --> parsujeme jako dtd
|
158
|
+
// 2 arguments -- public, system --> bude se hledat
|
159
|
+
// 3 arguments -- public, system, name --> creates an external subset (any parameter may be nil)
|
160
|
+
// 4 arguments -- public, system, name, doc --> creates an external subset (any parameter may be nil)
|
161
|
+
// 5 arguments -- public, system, name, doc, true --> creates an internal subset (all but last parameter may be nil)
|
162
|
+
switch (argc)
|
163
|
+
{
|
164
|
+
case 3:
|
165
|
+
case 4:
|
166
|
+
case 5: {
|
167
|
+
VALUE name, doc, internal;
|
168
|
+
const xmlChar *xname = NULL, *xpublic = NULL, *xsystem = NULL;
|
169
|
+
xmlDocPtr xdoc = NULL;
|
170
|
+
|
171
|
+
rb_scan_args(argc, argv, "32", &external, &system, &name, &doc, &internal);
|
172
|
+
|
173
|
+
if (external != Qnil) {
|
174
|
+
Check_Type(external, T_STRING);
|
175
|
+
xpublic = (const xmlChar*) StringValuePtr(external);
|
176
|
+
}
|
177
|
+
if (system != Qnil) {
|
178
|
+
Check_Type(system, T_STRING);
|
179
|
+
xsystem = (const xmlChar*) StringValuePtr(system);
|
180
|
+
}
|
181
|
+
if (name != Qnil) {
|
182
|
+
Check_Type(name, T_STRING);
|
183
|
+
xname = (const xmlChar*) StringValuePtr(name);
|
184
|
+
}
|
185
|
+
if (doc != Qnil) {
|
186
|
+
if (rb_obj_is_kind_of(doc, cXMLDocument) == Qfalse)
|
187
|
+
rb_raise(rb_eTypeError, "Must pass an XML::Document object");
|
188
|
+
Data_Get_Struct(doc, xmlDoc, xdoc);
|
189
|
+
}
|
190
|
+
|
191
|
+
if (internal == Qnil || internal == Qfalse)
|
192
|
+
xdtd = xmlNewDtd(xdoc, xname, xpublic, xsystem);
|
193
|
+
else
|
194
|
+
xdtd = xmlCreateIntSubset(xdoc, xname, xpublic, xsystem);
|
195
|
+
|
196
|
+
if (xdtd == NULL)
|
197
|
+
rxml_raise(&xmlLastError);
|
198
|
+
|
199
|
+
/* Document will free this dtd now. */
|
200
|
+
RDATA(self)->dfree = NULL;
|
201
|
+
DATA_PTR(self) = xdtd;
|
202
|
+
|
203
|
+
xmlSetTreeDoc((xmlNodePtr) xdtd, xdoc);
|
204
|
+
}
|
205
|
+
break;
|
206
|
+
|
207
|
+
case 2:
|
208
|
+
rb_scan_args(argc, argv, "20", &external, &system);
|
209
|
+
|
210
|
+
Check_Type(external, T_STRING);
|
211
|
+
Check_Type(system, T_STRING);
|
212
|
+
|
213
|
+
xdtd = xmlParseDTD((xmlChar*) StringValuePtr(external),
|
214
|
+
(xmlChar*) StringValuePtr(system));
|
215
|
+
|
216
|
+
if (xdtd == NULL)
|
217
|
+
rxml_raise(&xmlLastError);
|
218
|
+
|
219
|
+
DATA_PTR(self) = xdtd;
|
220
|
+
|
221
|
+
xmlSetTreeDoc((xmlNodePtr) xdtd, NULL);
|
222
|
+
break;
|
223
|
+
|
224
|
+
case 1:
|
225
|
+
rb_scan_args(argc, argv, "10", &dtd_string);
|
226
|
+
Check_Type(dtd_string, T_STRING);
|
227
|
+
|
228
|
+
/* Note that buffer is freed by xmlParserInputBufferPush*/
|
229
|
+
buffer = xmlAllocParserInputBuffer(enc);
|
230
|
+
new_string = xmlStrdup((xmlChar*) StringValuePtr(dtd_string));
|
231
|
+
xmlParserInputBufferPush(buffer, xmlStrlen(new_string),
|
232
|
+
(const char*) new_string);
|
233
|
+
|
234
|
+
xdtd = xmlIOParseDTD(NULL, buffer, enc);
|
235
|
+
|
236
|
+
if (xdtd == NULL)
|
237
|
+
rxml_raise(&xmlLastError);
|
238
|
+
|
239
|
+
xmlFree(new_string);
|
240
|
+
|
241
|
+
DATA_PTR(self) = xdtd;
|
242
|
+
break;
|
243
|
+
|
244
|
+
default:
|
245
|
+
rb_raise(rb_eArgError, "wrong number of arguments");
|
246
|
+
}
|
247
|
+
|
248
|
+
return self;
|
249
|
+
}
|
250
|
+
|
251
|
+
void rxml_init_dtd()
|
252
|
+
{
|
253
|
+
cXMLDtd = rb_define_class_under(mXML, "Dtd", rb_cObject);
|
254
|
+
rb_define_alloc_func(cXMLDtd, rxml_dtd_alloc);
|
255
|
+
rb_define_method(cXMLDtd, "initialize", rxml_dtd_initialize, -1);
|
256
|
+
rb_define_method(cXMLDtd, "external_id", rxml_dtd_external_id_get, 0);
|
257
|
+
rb_define_method(cXMLDtd, "name", rxml_dtd_name_get, 0);
|
258
|
+
rb_define_method(cXMLDtd, "uri", rxml_dtd_uri_get, 0);
|
259
|
+
rb_define_method(cXMLDtd, "node_type", rxml_dtd_type, 0);
|
260
|
+
rb_define_alias(cXMLDtd, "system_id", "uri");
|
261
|
+
}
|