libxml-ruby 5.0.4 → 5.0.5

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.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/HISTORY +10 -6
  3. data/README.rdoc +1 -1
  4. data/ext/libxml/extconf.rb +5 -0
  5. data/ext/libxml/ruby_xml.c +556 -556
  6. data/ext/libxml/ruby_xml_attributes.h +17 -17
  7. data/ext/libxml/ruby_xml_document.c +1129 -1129
  8. data/ext/libxml/ruby_xml_dtd.c +257 -257
  9. data/ext/libxml/ruby_xml_encoding.c +250 -250
  10. data/ext/libxml/ruby_xml_error.c +1003 -1003
  11. data/ext/libxml/ruby_xml_error.h +14 -14
  12. data/ext/libxml/ruby_xml_html_parser_context.c +351 -351
  13. data/ext/libxml/ruby_xml_input_cbg.c +188 -188
  14. data/ext/libxml/ruby_xml_namespace.c +151 -151
  15. data/ext/libxml/ruby_xml_parser.h +10 -10
  16. data/ext/libxml/ruby_xml_parser_context.c +1009 -1009
  17. data/ext/libxml/ruby_xml_parser_options.c +74 -74
  18. data/ext/libxml/ruby_xml_parser_options.h +10 -10
  19. data/ext/libxml/ruby_xml_sax2_handler.c +326 -326
  20. data/ext/libxml/ruby_xml_sax_parser.c +108 -108
  21. data/ext/libxml/ruby_xml_version.h +9 -9
  22. data/lib/libxml/attr.rb +122 -122
  23. data/lib/libxml/attr_decl.rb +80 -80
  24. data/lib/libxml/attributes.rb +13 -13
  25. data/lib/libxml/document.rb +194 -194
  26. data/lib/libxml/error.rb +95 -95
  27. data/lib/libxml/hpricot.rb +77 -77
  28. data/lib/libxml/html_parser.rb +96 -96
  29. data/lib/libxml/namespace.rb +61 -61
  30. data/lib/libxml/namespaces.rb +37 -37
  31. data/lib/libxml/node.rb +323 -323
  32. data/lib/libxml/parser.rb +102 -102
  33. data/lib/libxml/sax_callbacks.rb +179 -179
  34. data/lib/libxml/sax_parser.rb +40 -40
  35. data/lib/libxml/tree.rb +28 -28
  36. data/lib/libxml.rb +4 -4
  37. data/lib/xml/libxml.rb +10 -10
  38. data/lib/xml.rb +13 -13
  39. data/libxml-ruby.gemspec +50 -49
  40. data/test/test_document.rb +140 -140
  41. data/test/test_document_write.rb +142 -142
  42. data/test/test_dtd.rb +126 -126
  43. data/test/test_encoding.rb +126 -126
  44. data/test/test_error.rb +194 -194
  45. data/test/test_helper.rb +20 -20
  46. data/test/test_namespace.rb +58 -58
  47. data/test/test_node.rb +235 -235
  48. data/test/test_node_write.rb +93 -93
  49. data/test/test_parser.rb +333 -333
  50. data/test/test_reader.rb +364 -364
  51. data/test/test_xml.rb +168 -168
  52. metadata +5 -4
@@ -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
- if (xdtd->doc == NULL && xdtd->parent == NULL)
36
- xmlFreeDtd(xdtd);
37
- }
38
-
39
- void rxml_dtd_mark(xmlDtdPtr xdtd)
40
- {
41
- if (xdtd && xdtd->doc)
42
- {
43
- VALUE doc = (VALUE)xdtd->doc->_private;
44
- rb_gc_mark(doc);
45
- }
46
- }
47
-
48
- static VALUE rxml_dtd_alloc(VALUE klass)
49
- {
50
- return Data_Wrap_Struct(klass, rxml_dtd_mark, rxml_dtd_free, NULL);
51
- }
52
-
53
- VALUE rxml_dtd_wrap(xmlDtdPtr xdtd)
54
- {
55
- return Data_Wrap_Struct(cXMLDtd, NULL, NULL, xdtd);
56
- }
57
-
58
- /*
59
- * call-seq:
60
- * dtd.external_id -> "string"
61
- *
62
- * Obtain this dtd's external identifer (for a PUBLIC DTD).
63
- */
64
- static VALUE rxml_dtd_external_id_get(VALUE self)
65
- {
66
- xmlDtdPtr xdtd;
67
- Data_Get_Struct(self, xmlDtd, xdtd);
68
-
69
-
70
- if (xdtd->ExternalID == NULL)
71
- return (Qnil);
72
- else
73
- return (rxml_new_cstr( xdtd->ExternalID, NULL));
74
- }
75
-
76
- /*
77
- * call-seq:
78
- * dtd.name -> "string"
79
- *
80
- * Obtain this dtd's name.
81
- */
82
- static VALUE rxml_dtd_name_get(VALUE self)
83
- {
84
- xmlDtdPtr xdtd;
85
- Data_Get_Struct(self, xmlDtd, xdtd);
86
-
87
-
88
- if (xdtd->name == NULL)
89
- return (Qnil);
90
- else
91
- return (rxml_new_cstr( xdtd->name, NULL));
92
- }
93
-
94
-
95
- /*
96
- * call-seq:
97
- * dtd.uri -> "string"
98
- *
99
- * Obtain this dtd's URI (for a SYSTEM or PUBLIC DTD).
100
- */
101
- static VALUE rxml_dtd_uri_get(VALUE self)
102
- {
103
- xmlDtdPtr xdtd;
104
- Data_Get_Struct(self, xmlDtd, xdtd);
105
-
106
- if (xdtd->SystemID == NULL)
107
- return (Qnil);
108
- else
109
- return (rxml_new_cstr( xdtd->SystemID, NULL));
110
- }
111
-
112
- /*
113
- * call-seq:
114
- * node.type -> num
115
- *
116
- * Obtain this node's type identifier.
117
- */
118
- static VALUE rxml_dtd_type(VALUE self)
119
- {
120
- xmlDtdPtr xdtd;
121
- Data_Get_Struct(self, xmlDtd, xdtd);
122
- return (INT2NUM(xdtd->type));
123
- }
124
-
125
- /*
126
- * call-seq:
127
- * XML::Dtd.new(dtd_string) -> dtd
128
- * XML::Dtd.new(external_id, system_id) -> dtd
129
- * XML::Dtd.new(external_id, system_id, name, document, internal) -> dtd
130
- *
131
- * Create a new Dtd from the specified public and system identifiers:
132
- *
133
- * * The first usage creates a DTD from a string and requires 1 parameter.
134
- * * The second usage loads and parses an external DTD and requires 2 parameters.
135
- * * The third usage creates a new internal or external DTD and requires 2 parameters and 3 optional parameters.
136
- * The DTD is then attached to the specified document if it is not nil.
137
- *
138
- * Parameters:
139
- *
140
- * dtd_string - A string that contains a complete DTD
141
- * external_id - A string that specifies the DTD's external name. For example, "-//W3C//DTD XHTML 1.0 Transitional//EN"
142
- * system_id - A string that specififies the DTD's system name. For example, "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
143
- * name - A string that specifies the DTD's name. For example "xhtml1".
144
- * document - A xml document.
145
- * internal - Boolean value indicating whether this is an internal or external DTD. Optional. If not specified
146
- * then external is assumed.
147
- */
148
- static VALUE rxml_dtd_initialize(int argc, VALUE *argv, VALUE self)
149
- {
150
- xmlDtdPtr xdtd;
151
- VALUE external, system;
152
-
153
- switch (argc)
154
- {
155
- case 3:
156
- case 4:
157
- case 5:
158
- {
159
- const xmlChar *xname = NULL, *xpublic = NULL, *xsystem = NULL;
160
- xmlDocPtr xdoc = NULL;
161
-
162
- VALUE name, doc, internal;
163
- rb_scan_args(argc, argv, "23", &external, &system, &name, &doc, &internal);
164
-
165
- Check_Type(external, T_STRING);
166
- xpublic = (const xmlChar*) StringValuePtr(external);
167
-
168
- Check_Type(system, T_STRING);
169
- xsystem = (const xmlChar*) StringValuePtr(system);
170
-
171
- if (name != Qnil)
172
- {
173
- Check_Type(name, T_STRING);
174
- xname = (const xmlChar*)StringValuePtr(name);
175
- }
176
-
177
- if (doc != Qnil)
178
- {
179
- if (rb_obj_is_kind_of(doc, cXMLDocument) == Qfalse)
180
- rb_raise(rb_eTypeError, "Must pass an LibXML::XML::Document object");
181
- Data_Get_Struct(doc, xmlDoc, xdoc);
182
- }
183
-
184
- if (internal == Qnil || internal == Qfalse)
185
- xdtd = xmlNewDtd(xdoc, xname, xpublic, xsystem);
186
- else
187
- xdtd = xmlCreateIntSubset(xdoc, xname, xpublic, xsystem);
188
-
189
- if (xdtd == NULL)
190
- rxml_raise(xmlGetLastError());
191
-
192
- /* The document will free the dtd so Ruby should not */
193
- RDATA(self)->dfree = NULL;
194
- DATA_PTR(self) = xdtd;
195
-
196
- xmlSetTreeDoc((xmlNodePtr) xdtd, xdoc);
197
- }
198
- break;
199
-
200
- case 2:
201
- {
202
- rb_scan_args(argc, argv, "20", &external, &system);
203
-
204
- Check_Type(external, T_STRING);
205
- Check_Type(system, T_STRING);
206
-
207
- xdtd = xmlParseDTD((xmlChar*) StringValuePtr(external), (xmlChar*) StringValuePtr(system));
208
-
209
- if (xdtd == NULL)
210
- rxml_raise(xmlGetLastError());
211
-
212
- DATA_PTR(self) = xdtd;
213
-
214
- xmlSetTreeDoc((xmlNodePtr) xdtd, NULL);
215
- break;
216
- }
217
- case 1:
218
- {
219
- VALUE dtd_string;
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
- xmlCharEncoding enc = XML_CHAR_ENCODING_NONE;
225
- xmlParserInputBufferPtr buffer = xmlAllocParserInputBuffer(enc);
226
- xmlChar *new_string = xmlStrdup((xmlChar*) StringValuePtr(dtd_string));
227
- xmlParserInputBufferPush(buffer, xmlStrlen(new_string),
228
- (const char*) new_string);
229
-
230
- xdtd = xmlIOParseDTD(NULL, buffer, enc);
231
-
232
- if (xdtd == NULL)
233
- rxml_raise(xmlGetLastError());
234
-
235
- xmlFree(new_string);
236
-
237
- DATA_PTR(self) = xdtd;
238
- break;
239
- }
240
- default:
241
- rb_raise(rb_eArgError, "wrong number of arguments");
242
- }
243
-
244
- return self;
245
- }
246
-
247
- void rxml_init_dtd(void)
248
- {
249
- cXMLDtd = rb_define_class_under(mXML, "Dtd", rb_cObject);
250
- rb_define_alloc_func(cXMLDtd, rxml_dtd_alloc);
251
- rb_define_method(cXMLDtd, "initialize", rxml_dtd_initialize, -1);
252
- rb_define_method(cXMLDtd, "external_id", rxml_dtd_external_id_get, 0);
253
- rb_define_method(cXMLDtd, "name", rxml_dtd_name_get, 0);
254
- rb_define_method(cXMLDtd, "uri", rxml_dtd_uri_get, 0);
255
- rb_define_method(cXMLDtd, "node_type", rxml_dtd_type, 0);
256
- rb_define_alias(cXMLDtd, "system_id", "uri");
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
+ if (xdtd->doc == NULL && xdtd->parent == NULL)
36
+ xmlFreeDtd(xdtd);
37
+ }
38
+
39
+ void rxml_dtd_mark(xmlDtdPtr xdtd)
40
+ {
41
+ if (xdtd && xdtd->doc)
42
+ {
43
+ VALUE doc = (VALUE)xdtd->doc->_private;
44
+ rb_gc_mark(doc);
45
+ }
46
+ }
47
+
48
+ static VALUE rxml_dtd_alloc(VALUE klass)
49
+ {
50
+ return Data_Wrap_Struct(klass, rxml_dtd_mark, rxml_dtd_free, NULL);
51
+ }
52
+
53
+ VALUE rxml_dtd_wrap(xmlDtdPtr xdtd)
54
+ {
55
+ return Data_Wrap_Struct(cXMLDtd, NULL, NULL, xdtd);
56
+ }
57
+
58
+ /*
59
+ * call-seq:
60
+ * dtd.external_id -> "string"
61
+ *
62
+ * Obtain this dtd's external identifer (for a PUBLIC DTD).
63
+ */
64
+ static VALUE rxml_dtd_external_id_get(VALUE self)
65
+ {
66
+ xmlDtdPtr xdtd;
67
+ Data_Get_Struct(self, xmlDtd, xdtd);
68
+
69
+
70
+ if (xdtd->ExternalID == NULL)
71
+ return (Qnil);
72
+ else
73
+ return (rxml_new_cstr( xdtd->ExternalID, NULL));
74
+ }
75
+
76
+ /*
77
+ * call-seq:
78
+ * dtd.name -> "string"
79
+ *
80
+ * Obtain this dtd's name.
81
+ */
82
+ static VALUE rxml_dtd_name_get(VALUE self)
83
+ {
84
+ xmlDtdPtr xdtd;
85
+ Data_Get_Struct(self, xmlDtd, xdtd);
86
+
87
+
88
+ if (xdtd->name == NULL)
89
+ return (Qnil);
90
+ else
91
+ return (rxml_new_cstr( xdtd->name, NULL));
92
+ }
93
+
94
+
95
+ /*
96
+ * call-seq:
97
+ * dtd.uri -> "string"
98
+ *
99
+ * Obtain this dtd's URI (for a SYSTEM or PUBLIC DTD).
100
+ */
101
+ static VALUE rxml_dtd_uri_get(VALUE self)
102
+ {
103
+ xmlDtdPtr xdtd;
104
+ Data_Get_Struct(self, xmlDtd, xdtd);
105
+
106
+ if (xdtd->SystemID == NULL)
107
+ return (Qnil);
108
+ else
109
+ return (rxml_new_cstr( xdtd->SystemID, NULL));
110
+ }
111
+
112
+ /*
113
+ * call-seq:
114
+ * node.type -> num
115
+ *
116
+ * Obtain this node's type identifier.
117
+ */
118
+ static VALUE rxml_dtd_type(VALUE self)
119
+ {
120
+ xmlDtdPtr xdtd;
121
+ Data_Get_Struct(self, xmlDtd, xdtd);
122
+ return (INT2NUM(xdtd->type));
123
+ }
124
+
125
+ /*
126
+ * call-seq:
127
+ * XML::Dtd.new(dtd_string) -> dtd
128
+ * XML::Dtd.new(external_id, system_id) -> dtd
129
+ * XML::Dtd.new(external_id, system_id, name, document, internal) -> dtd
130
+ *
131
+ * Create a new Dtd from the specified public and system identifiers:
132
+ *
133
+ * * The first usage creates a DTD from a string and requires 1 parameter.
134
+ * * The second usage loads and parses an external DTD and requires 2 parameters.
135
+ * * The third usage creates a new internal or external DTD and requires 2 parameters and 3 optional parameters.
136
+ * The DTD is then attached to the specified document if it is not nil.
137
+ *
138
+ * Parameters:
139
+ *
140
+ * dtd_string - A string that contains a complete DTD
141
+ * external_id - A string that specifies the DTD's external name. For example, "-//W3C//DTD XHTML 1.0 Transitional//EN"
142
+ * system_id - A string that specififies the DTD's system name. For example, "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
143
+ * name - A string that specifies the DTD's name. For example "xhtml1".
144
+ * document - A xml document.
145
+ * internal - Boolean value indicating whether this is an internal or external DTD. Optional. If not specified
146
+ * then external is assumed.
147
+ */
148
+ static VALUE rxml_dtd_initialize(int argc, VALUE *argv, VALUE self)
149
+ {
150
+ xmlDtdPtr xdtd;
151
+ VALUE external, system;
152
+
153
+ switch (argc)
154
+ {
155
+ case 3:
156
+ case 4:
157
+ case 5:
158
+ {
159
+ const xmlChar *xname = NULL, *xpublic = NULL, *xsystem = NULL;
160
+ xmlDocPtr xdoc = NULL;
161
+
162
+ VALUE name, doc, internal;
163
+ rb_scan_args(argc, argv, "23", &external, &system, &name, &doc, &internal);
164
+
165
+ Check_Type(external, T_STRING);
166
+ xpublic = (const xmlChar*) StringValuePtr(external);
167
+
168
+ Check_Type(system, T_STRING);
169
+ xsystem = (const xmlChar*) StringValuePtr(system);
170
+
171
+ if (name != Qnil)
172
+ {
173
+ Check_Type(name, T_STRING);
174
+ xname = (const xmlChar*)StringValuePtr(name);
175
+ }
176
+
177
+ if (doc != Qnil)
178
+ {
179
+ if (rb_obj_is_kind_of(doc, cXMLDocument) == Qfalse)
180
+ rb_raise(rb_eTypeError, "Must pass an LibXML::XML::Document object");
181
+ Data_Get_Struct(doc, xmlDoc, xdoc);
182
+ }
183
+
184
+ if (internal == Qnil || internal == Qfalse)
185
+ xdtd = xmlNewDtd(xdoc, xname, xpublic, xsystem);
186
+ else
187
+ xdtd = xmlCreateIntSubset(xdoc, xname, xpublic, xsystem);
188
+
189
+ if (xdtd == NULL)
190
+ rxml_raise(xmlGetLastError());
191
+
192
+ /* The document will free the dtd so Ruby should not */
193
+ RDATA(self)->dfree = NULL;
194
+ DATA_PTR(self) = xdtd;
195
+
196
+ xmlSetTreeDoc((xmlNodePtr) xdtd, xdoc);
197
+ }
198
+ break;
199
+
200
+ case 2:
201
+ {
202
+ rb_scan_args(argc, argv, "20", &external, &system);
203
+
204
+ Check_Type(external, T_STRING);
205
+ Check_Type(system, T_STRING);
206
+
207
+ xdtd = xmlParseDTD((xmlChar*) StringValuePtr(external), (xmlChar*) StringValuePtr(system));
208
+
209
+ if (xdtd == NULL)
210
+ rxml_raise(xmlGetLastError());
211
+
212
+ DATA_PTR(self) = xdtd;
213
+
214
+ xmlSetTreeDoc((xmlNodePtr) xdtd, NULL);
215
+ break;
216
+ }
217
+ case 1:
218
+ {
219
+ VALUE dtd_string;
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
+ xmlCharEncoding enc = XML_CHAR_ENCODING_NONE;
225
+ xmlParserInputBufferPtr buffer = xmlAllocParserInputBuffer(enc);
226
+ xmlChar *new_string = xmlStrdup((xmlChar*) StringValuePtr(dtd_string));
227
+ xmlParserInputBufferPush(buffer, xmlStrlen(new_string),
228
+ (const char*) new_string);
229
+
230
+ xdtd = xmlIOParseDTD(NULL, buffer, enc);
231
+
232
+ if (xdtd == NULL)
233
+ rxml_raise(xmlGetLastError());
234
+
235
+ xmlFree(new_string);
236
+
237
+ DATA_PTR(self) = xdtd;
238
+ break;
239
+ }
240
+ default:
241
+ rb_raise(rb_eArgError, "wrong number of arguments");
242
+ }
243
+
244
+ return self;
245
+ }
246
+
247
+ void rxml_init_dtd(void)
248
+ {
249
+ cXMLDtd = rb_define_class_under(mXML, "Dtd", rb_cObject);
250
+ rb_define_alloc_func(cXMLDtd, rxml_dtd_alloc);
251
+ rb_define_method(cXMLDtd, "initialize", rxml_dtd_initialize, -1);
252
+ rb_define_method(cXMLDtd, "external_id", rxml_dtd_external_id_get, 0);
253
+ rb_define_method(cXMLDtd, "name", rxml_dtd_name_get, 0);
254
+ rb_define_method(cXMLDtd, "uri", rxml_dtd_uri_get, 0);
255
+ rb_define_method(cXMLDtd, "node_type", rxml_dtd_type, 0);
256
+ rb_define_alias(cXMLDtd, "system_id", "uri");
257
+ }