libxml-ruby 4.1.2 → 6.0.0
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.
- checksums.yaml +4 -4
- data/{HISTORY → CHANGELOG.md} +875 -887
- data/LICENSE +20 -20
- data/README.md +67 -0
- data/Rakefile +77 -98
- data/ext/libxml/extconf.rb +39 -20
- data/ext/libxml/libxml.c +67 -79
- data/ext/libxml/ruby_libxml.h +43 -44
- data/ext/libxml/ruby_xml.c +556 -899
- data/ext/libxml/ruby_xml.h +9 -10
- data/ext/libxml/ruby_xml_attr.c +338 -333
- data/ext/libxml/ruby_xml_attr.h +13 -12
- data/ext/libxml/ruby_xml_attr_decl.c +19 -12
- data/ext/libxml/ruby_xml_attr_decl.h +11 -11
- data/ext/libxml/ruby_xml_attributes.c +18 -9
- data/ext/libxml/ruby_xml_attributes.h +17 -15
- data/ext/libxml/ruby_xml_document.c +1142 -1129
- data/ext/libxml/ruby_xml_document.h +12 -11
- data/ext/libxml/ruby_xml_dtd.c +287 -248
- data/ext/libxml/ruby_xml_dtd.h +10 -9
- data/ext/libxml/ruby_xml_encoding.c +250 -250
- data/ext/libxml/ruby_xml_encoding.h +20 -18
- data/ext/libxml/ruby_xml_error.c +1003 -996
- data/ext/libxml/ruby_xml_error.h +14 -14
- data/ext/libxml/ruby_xml_html_parser.c +91 -91
- data/ext/libxml/ruby_xml_html_parser.h +10 -10
- data/ext/libxml/ruby_xml_html_parser_context.c +364 -337
- data/ext/libxml/ruby_xml_html_parser_context.h +11 -10
- data/ext/libxml/ruby_xml_html_parser_options.c +48 -48
- data/ext/libxml/ruby_xml_html_parser_options.h +10 -10
- data/ext/libxml/ruby_xml_input_cbg.c +216 -188
- data/ext/libxml/ruby_xml_input_cbg.h +20 -20
- data/ext/libxml/ruby_xml_io.c +49 -47
- data/ext/libxml/ruby_xml_io.h +10 -10
- data/ext/libxml/ruby_xml_namespace.c +159 -154
- data/ext/libxml/ruby_xml_namespace.h +11 -10
- data/ext/libxml/ruby_xml_namespaces.c +313 -293
- data/ext/libxml/ruby_xml_namespaces.h +9 -9
- data/ext/libxml/ruby_xml_node.c +1433 -1398
- data/ext/libxml/ruby_xml_node.h +15 -13
- data/ext/libxml/ruby_xml_parser.c +91 -91
- data/ext/libxml/ruby_xml_parser.h +10 -10
- data/ext/libxml/ruby_xml_parser_context.c +1016 -1001
- data/ext/libxml/ruby_xml_parser_context.h +11 -10
- data/ext/libxml/ruby_xml_parser_options.c +74 -66
- data/ext/libxml/ruby_xml_parser_options.h +10 -10
- data/ext/libxml/ruby_xml_reader.c +40 -31
- data/ext/libxml/ruby_xml_reader.h +14 -14
- data/ext/libxml/ruby_xml_registry.c +31 -0
- data/ext/libxml/ruby_xml_registry.h +22 -0
- data/ext/libxml/ruby_xml_relaxng.c +21 -5
- data/ext/libxml/ruby_xml_relaxng.h +9 -8
- data/ext/libxml/ruby_xml_sax2_handler.c +326 -326
- data/ext/libxml/ruby_xml_sax2_handler.h +10 -10
- data/ext/libxml/ruby_xml_sax_parser.c +108 -116
- data/ext/libxml/ruby_xml_sax_parser.h +10 -10
- data/ext/libxml/ruby_xml_schema.c +22 -15
- data/ext/libxml/ruby_xml_schema.h +26 -25
- data/ext/libxml/ruby_xml_schema_attribute.c +7 -7
- data/ext/libxml/ruby_xml_schema_attribute.h +37 -37
- data/ext/libxml/ruby_xml_schema_element.c +8 -8
- data/ext/libxml/ruby_xml_schema_element.h +11 -11
- data/ext/libxml/ruby_xml_schema_facet.c +50 -50
- data/ext/libxml/ruby_xml_schema_facet.h +9 -9
- data/ext/libxml/ruby_xml_schema_type.c +12 -19
- data/ext/libxml/ruby_xml_schema_type.h +9 -9
- data/ext/libxml/ruby_xml_version.h +9 -9
- data/ext/libxml/ruby_xml_writer.c +183 -185
- data/ext/libxml/ruby_xml_writer.h +6 -6
- data/ext/libxml/ruby_xml_xinclude.c +20 -20
- data/ext/libxml/ruby_xml_xinclude.h +11 -11
- data/ext/libxml/ruby_xml_xpath.c +195 -195
- data/ext/libxml/ruby_xml_xpath.h +15 -15
- data/ext/libxml/ruby_xml_xpath_context.c +408 -362
- data/ext/libxml/ruby_xml_xpath_context.h +9 -9
- data/ext/libxml/ruby_xml_xpath_expression.c +12 -6
- data/ext/libxml/ruby_xml_xpath_expression.h +11 -10
- data/ext/libxml/ruby_xml_xpath_object.c +69 -54
- data/ext/libxml/ruby_xml_xpath_object.h +19 -17
- data/ext/vc/libxml_ruby/libxml_ruby.vcxproj +271 -0
- data/ext/xcode/libxml-ruby.xcodeproj/project.pbxproj +633 -0
- data/ext/xcode/libxml-ruby.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
- data/ext/xcode/libxml-ruby.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
- data/ext/xcode/libxml-ruby.xcodeproj/xcshareddata/xcschemes/libxml-ruby.xcscheme +80 -0
- data/lib/libxml/attr.rb +122 -122
- data/lib/libxml/attr_decl.rb +80 -80
- data/lib/libxml/attributes.rb +13 -13
- data/lib/libxml/document.rb +165 -194
- data/lib/libxml/error.rb +122 -95
- data/lib/libxml/html_parser.rb +80 -96
- data/lib/libxml/namespace.rb +61 -61
- data/lib/libxml/namespaces.rb +37 -37
- data/lib/libxml/node.rb +321 -323
- data/lib/libxml/parser.rb +94 -100
- data/lib/libxml/sax_callbacks.rb +179 -179
- data/lib/libxml/sax_parser.rb +40 -40
- data/lib/libxml/schema/attribute.rb +27 -19
- data/lib/libxml/schema/element.rb +20 -0
- data/lib/libxml/schema/type.rb +44 -21
- data/lib/libxml/schema.rb +47 -47
- data/lib/libxml/tree.rb +28 -28
- data/lib/libxml-ruby.rb +30 -30
- data/libxml-ruby.gemspec +46 -48
- data/test/c14n/result/1-1-without-comments/example-1 +3 -3
- data/test/c14n/result/1-1-without-comments/example-2 +10 -10
- data/test/c14n/result/1-1-without-comments/example-3 +13 -13
- data/test/c14n/result/1-1-without-comments/example-4 +8 -8
- data/test/c14n/result/1-1-without-comments/example-5 +2 -2
- data/test/c14n/result/with-comments/example-1 +5 -5
- data/test/c14n/result/with-comments/example-2 +10 -10
- data/test/c14n/result/with-comments/example-3 +13 -13
- data/test/c14n/result/with-comments/example-4 +8 -8
- data/test/c14n/result/with-comments/example-5 +3 -3
- data/test/c14n/result/without-comments/example-1 +3 -3
- data/test/c14n/result/without-comments/example-2 +10 -10
- data/test/c14n/result/without-comments/example-3 +13 -13
- data/test/c14n/result/without-comments/example-4 +8 -8
- data/test/c14n/result/without-comments/example-5 +2 -2
- data/test/test_attr.rb +179 -180
- data/test/test_attr_decl.rb +131 -131
- data/test/test_attributes.rb +135 -135
- data/test/test_canonicalize.rb +122 -120
- data/test/test_document.rb +138 -132
- data/test/test_document_write.rb +142 -145
- data/test/test_dtd.rb +134 -129
- data/test/test_encoding.rb +126 -129
- data/test/test_encoding_sax.rb +114 -114
- data/test/test_error.rb +197 -194
- data/test/test_helper.rb +21 -13
- data/test/test_html_parser.rb +166 -162
- data/test/test_html_parser_context.rb +22 -22
- data/test/test_input_callbacks.rb +36 -0
- data/test/test_namespace.rb +58 -60
- data/test/test_namespaces.rb +200 -200
- data/test/test_node.rb +251 -237
- data/test/test_node_cdata.rb +50 -50
- data/test/test_node_comment.rb +32 -32
- data/test/test_node_copy.rb +40 -40
- data/test/test_node_edit.rb +176 -158
- data/test/test_node_pi.rb +37 -37
- data/test/test_node_text.rb +69 -69
- data/test/test_node_write.rb +93 -96
- data/test/test_node_xlink.rb +28 -28
- data/test/test_parser.rb +297 -324
- data/test/test_parser_context.rb +198 -198
- data/test/test_properties.rb +38 -38
- data/test/test_reader.rb +413 -364
- data/test/test_relaxng.rb +59 -53
- data/test/test_sax_parser.rb +345 -326
- data/test/test_schema.rb +28 -0
- data/test/test_traversal.rb +152 -152
- data/test/test_writer.rb +469 -468
- data/test/test_xinclude.rb +20 -20
- data/test/test_xml.rb +164 -267
- data/test/test_xpath.rb +244 -244
- data/test/test_xpath_context.rb +87 -87
- data/test/test_xpath_expression.rb +37 -37
- metadata +49 -31
- data/README.rdoc +0 -217
- data/ext/libxml/extconf.h +0 -3
- data/ext/libxml/ruby_xml_cbg.c +0 -85
- data/lib/libxml/hpricot.rb +0 -78
- data/lib/libxml.rb +0 -5
- data/lib/xml/libxml.rb +0 -10
- data/lib/xml.rb +0 -14
- data/script/benchmark/depixelate +0 -634
- data/script/benchmark/hamlet.xml +0 -9055
- data/script/benchmark/parsecount +0 -170
- data/script/benchmark/sock_entries.xml +0 -507
- data/script/benchmark/throughput +0 -41
- data/script/test +0 -6
- data/test/test_deprecated_require.rb +0 -12
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
/* Please see the LICENSE file for copyright and distribution information */
|
|
2
|
-
|
|
3
|
-
#ifndef __RXML_DOCUMENT__
|
|
4
|
-
#define __RXML_DOCUMENT__
|
|
5
|
-
|
|
6
|
-
extern VALUE cXMLDocument;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
/* Please see the LICENSE file for copyright and distribution information */
|
|
2
|
+
|
|
3
|
+
#ifndef __RXML_DOCUMENT__
|
|
4
|
+
#define __RXML_DOCUMENT__
|
|
5
|
+
|
|
6
|
+
extern VALUE cXMLDocument;
|
|
7
|
+
extern const rb_data_type_t rxml_document_data_type;
|
|
8
|
+
void rxml_init_document(void);
|
|
9
|
+
VALUE rxml_document_wrap(xmlDocPtr xnode);
|
|
10
|
+
|
|
11
|
+
typedef xmlChar * xmlCharPtr;
|
|
12
|
+
#endif
|
data/ext/libxml/ruby_xml_dtd.c
CHANGED
|
@@ -1,248 +1,287 @@
|
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
if (xdtd && xdtd->
|
|
42
|
-
|
|
43
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
+
#ifndef TYPED_DATA_EMBEDDED
|
|
32
|
+
#define TYPED_DATA_EMBEDDED ((VALUE)1)
|
|
33
|
+
#endif
|
|
34
|
+
|
|
35
|
+
VALUE cXMLDtd;
|
|
36
|
+
|
|
37
|
+
static void rxml_dtd_free(void* data)
|
|
38
|
+
{
|
|
39
|
+
xmlDtdPtr xdtd = (xmlDtdPtr)data;
|
|
40
|
+
if (!xdtd) return;
|
|
41
|
+
if (xdtd->doc == NULL && xdtd->parent == NULL)
|
|
42
|
+
xmlFreeDtd(xdtd);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
static void rxml_dtd_mark(void* data)
|
|
46
|
+
{
|
|
47
|
+
xmlDtdPtr xdtd = (xmlDtdPtr)data;
|
|
48
|
+
if (xdtd && xdtd->doc)
|
|
49
|
+
{
|
|
50
|
+
VALUE doc = rxml_registry_lookup(xdtd->doc);
|
|
51
|
+
if (!NIL_P(doc))
|
|
52
|
+
rb_gc_mark(doc);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const rb_data_type_t rxml_dtd_data_type = {
|
|
57
|
+
.wrap_struct_name = "LibXML::XML::Dtd",
|
|
58
|
+
.function = { .dmark = rxml_dtd_mark, .dfree = NULL },
|
|
59
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY,
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
static const rb_data_type_t rxml_dtd_managed_data_type = {
|
|
63
|
+
.wrap_struct_name = "LibXML::XML::Dtd (managed)",
|
|
64
|
+
.function = { .dmark = rxml_dtd_mark, .dfree = rxml_dtd_free },
|
|
65
|
+
.parent = &rxml_dtd_data_type,
|
|
66
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY,
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
static VALUE rxml_dtd_alloc(VALUE klass)
|
|
70
|
+
{
|
|
71
|
+
return TypedData_Wrap_Struct(klass, &rxml_dtd_managed_data_type, NULL);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
VALUE rxml_dtd_wrap(xmlDtdPtr xdtd)
|
|
75
|
+
{
|
|
76
|
+
return TypedData_Wrap_Struct(cXMLDtd, &rxml_dtd_data_type, xdtd);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/*
|
|
80
|
+
* call-seq:
|
|
81
|
+
* dtd.external_id -> "string"
|
|
82
|
+
*
|
|
83
|
+
* Obtain this dtd's external identifer (for a PUBLIC DTD).
|
|
84
|
+
*/
|
|
85
|
+
static VALUE rxml_dtd_external_id_get(VALUE self)
|
|
86
|
+
{
|
|
87
|
+
xmlDtdPtr xdtd;
|
|
88
|
+
TypedData_Get_Struct(self, xmlDtd, &rxml_dtd_data_type, xdtd);
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
if (xdtd->ExternalID == NULL)
|
|
92
|
+
return (Qnil);
|
|
93
|
+
else
|
|
94
|
+
return (rxml_new_cstr( xdtd->ExternalID, NULL));
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/*
|
|
98
|
+
* call-seq:
|
|
99
|
+
* dtd.name -> "string"
|
|
100
|
+
*
|
|
101
|
+
* Obtain this dtd's name.
|
|
102
|
+
*/
|
|
103
|
+
static VALUE rxml_dtd_name_get(VALUE self)
|
|
104
|
+
{
|
|
105
|
+
xmlDtdPtr xdtd;
|
|
106
|
+
TypedData_Get_Struct(self, xmlDtd, &rxml_dtd_data_type, xdtd);
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
if (xdtd->name == NULL)
|
|
110
|
+
return (Qnil);
|
|
111
|
+
else
|
|
112
|
+
return (rxml_new_cstr( xdtd->name, NULL));
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
/*
|
|
117
|
+
* call-seq:
|
|
118
|
+
* dtd.uri -> "string"
|
|
119
|
+
*
|
|
120
|
+
* Obtain this dtd's URI (for a SYSTEM or PUBLIC DTD).
|
|
121
|
+
*/
|
|
122
|
+
static VALUE rxml_dtd_uri_get(VALUE self)
|
|
123
|
+
{
|
|
124
|
+
xmlDtdPtr xdtd;
|
|
125
|
+
TypedData_Get_Struct(self, xmlDtd, &rxml_dtd_data_type, xdtd);
|
|
126
|
+
|
|
127
|
+
if (xdtd->SystemID == NULL)
|
|
128
|
+
return (Qnil);
|
|
129
|
+
else
|
|
130
|
+
return (rxml_new_cstr( xdtd->SystemID, NULL));
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/*
|
|
134
|
+
* call-seq:
|
|
135
|
+
* node.type -> num
|
|
136
|
+
*
|
|
137
|
+
* Obtain this node's type identifier.
|
|
138
|
+
*/
|
|
139
|
+
static VALUE rxml_dtd_type(VALUE self)
|
|
140
|
+
{
|
|
141
|
+
xmlDtdPtr xdtd;
|
|
142
|
+
TypedData_Get_Struct(self, xmlDtd, &rxml_dtd_data_type, xdtd);
|
|
143
|
+
return (INT2NUM(xdtd->type));
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/*
|
|
147
|
+
* call-seq:
|
|
148
|
+
* XML::Dtd.new(dtd_string) -> dtd
|
|
149
|
+
* XML::Dtd.new(external_id, system_id) -> dtd
|
|
150
|
+
* XML::Dtd.new(external_id, system_id, name, document, internal) -> dtd
|
|
151
|
+
*
|
|
152
|
+
* Create a new Dtd from the specified public and system identifiers:
|
|
153
|
+
*
|
|
154
|
+
* * The first usage creates a DTD from a string and requires 1 parameter.
|
|
155
|
+
* * The second usage loads and parses an external DTD and requires 2 parameters.
|
|
156
|
+
* * The third usage creates a new internal or external DTD and requires 2 parameters and 3 optional parameters.
|
|
157
|
+
* The DTD is then attached to the specified document if it is not nil.
|
|
158
|
+
*
|
|
159
|
+
* Parameters:
|
|
160
|
+
*
|
|
161
|
+
* dtd_string - A string that contains a complete DTD
|
|
162
|
+
* external_id - A string that specifies the DTD's external name. For example, "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
|
163
|
+
* system_id - A string that specififies the DTD's system name. For example, "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
|
|
164
|
+
* name - A string that specifies the DTD's name. For example "xhtml1".
|
|
165
|
+
* document - A xml document.
|
|
166
|
+
* internal - Boolean value indicating whether this is an internal or external DTD. Optional. If not specified
|
|
167
|
+
* then external is assumed.
|
|
168
|
+
*/
|
|
169
|
+
static VALUE rxml_dtd_initialize(int argc, VALUE *argv, VALUE self)
|
|
170
|
+
{
|
|
171
|
+
xmlDtdPtr xdtd;
|
|
172
|
+
VALUE external, system;
|
|
173
|
+
|
|
174
|
+
switch (argc)
|
|
175
|
+
{
|
|
176
|
+
case 3:
|
|
177
|
+
case 4:
|
|
178
|
+
case 5:
|
|
179
|
+
{
|
|
180
|
+
const xmlChar *xname = NULL, *xpublic = NULL, *xsystem = NULL;
|
|
181
|
+
xmlDocPtr xdoc = NULL;
|
|
182
|
+
|
|
183
|
+
VALUE name, doc, internal;
|
|
184
|
+
rb_scan_args(argc, argv, "23", &external, &system, &name, &doc, &internal);
|
|
185
|
+
|
|
186
|
+
if (external != Qnil)
|
|
187
|
+
{
|
|
188
|
+
Check_Type(external, T_STRING);
|
|
189
|
+
xpublic = (const xmlChar*) StringValuePtr(external);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
if (system != Qnil)
|
|
193
|
+
{
|
|
194
|
+
Check_Type(system, T_STRING);
|
|
195
|
+
xsystem = (const xmlChar*) StringValuePtr(system);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
if (name != Qnil)
|
|
199
|
+
{
|
|
200
|
+
Check_Type(name, T_STRING);
|
|
201
|
+
xname = (const xmlChar*)StringValuePtr(name);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
if (doc != Qnil)
|
|
205
|
+
{
|
|
206
|
+
if (rb_obj_is_kind_of(doc, cXMLDocument) == Qfalse)
|
|
207
|
+
rb_raise(rb_eTypeError, "Must pass an LibXML::XML::Document object");
|
|
208
|
+
TypedData_Get_Struct(doc, xmlDoc, &rxml_document_data_type, xdoc);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
if (internal == Qnil || internal == Qfalse)
|
|
212
|
+
xdtd = xmlNewDtd(xdoc, xname, xpublic, xsystem);
|
|
213
|
+
else
|
|
214
|
+
xdtd = xmlCreateIntSubset(xdoc, xname, xpublic, xsystem);
|
|
215
|
+
|
|
216
|
+
if (xdtd == NULL)
|
|
217
|
+
rxml_raise(xmlGetLastError());
|
|
218
|
+
|
|
219
|
+
/* The document will free the dtd so Ruby should not */
|
|
220
|
+
{
|
|
221
|
+
VALUE *type_ptr = (VALUE *)&RTYPEDDATA(self)->type;
|
|
222
|
+
*type_ptr = (*type_ptr & TYPED_DATA_EMBEDDED) | (VALUE)&rxml_dtd_data_type;
|
|
223
|
+
}
|
|
224
|
+
RTYPEDDATA_DATA(self) = xdtd;
|
|
225
|
+
|
|
226
|
+
xmlSetTreeDoc((xmlNodePtr) xdtd, xdoc);
|
|
227
|
+
}
|
|
228
|
+
break;
|
|
229
|
+
|
|
230
|
+
case 2:
|
|
231
|
+
{
|
|
232
|
+
rb_scan_args(argc, argv, "20", &external, &system);
|
|
233
|
+
|
|
234
|
+
Check_Type(external, T_STRING);
|
|
235
|
+
Check_Type(system, T_STRING);
|
|
236
|
+
|
|
237
|
+
xdtd = xmlParseDTD((xmlChar*) StringValuePtr(external), (xmlChar*) StringValuePtr(system));
|
|
238
|
+
|
|
239
|
+
if (xdtd == NULL)
|
|
240
|
+
rxml_raise(xmlGetLastError());
|
|
241
|
+
|
|
242
|
+
RTYPEDDATA_DATA(self) = xdtd;
|
|
243
|
+
|
|
244
|
+
xmlSetTreeDoc((xmlNodePtr) xdtd, NULL);
|
|
245
|
+
break;
|
|
246
|
+
}
|
|
247
|
+
case 1:
|
|
248
|
+
{
|
|
249
|
+
VALUE dtd_string;
|
|
250
|
+
rb_scan_args(argc, argv, "10", &dtd_string);
|
|
251
|
+
Check_Type(dtd_string, T_STRING);
|
|
252
|
+
|
|
253
|
+
/* Note that buffer is freed by xmlParserInputBufferPush*/
|
|
254
|
+
xmlCharEncoding enc = XML_CHAR_ENCODING_NONE;
|
|
255
|
+
xmlParserInputBufferPtr buffer = xmlAllocParserInputBuffer(enc);
|
|
256
|
+
xmlChar *new_string = xmlStrdup((xmlChar*) StringValuePtr(dtd_string));
|
|
257
|
+
xmlParserInputBufferPush(buffer, xmlStrlen(new_string),
|
|
258
|
+
(const char*) new_string);
|
|
259
|
+
|
|
260
|
+
xdtd = xmlIOParseDTD(NULL, buffer, enc);
|
|
261
|
+
|
|
262
|
+
if (xdtd == NULL)
|
|
263
|
+
rxml_raise(xmlGetLastError());
|
|
264
|
+
|
|
265
|
+
xmlFree(new_string);
|
|
266
|
+
|
|
267
|
+
RTYPEDDATA_DATA(self) = xdtd;
|
|
268
|
+
break;
|
|
269
|
+
}
|
|
270
|
+
default:
|
|
271
|
+
rb_raise(rb_eArgError, "wrong number of arguments");
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
return self;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
void rxml_init_dtd(void)
|
|
278
|
+
{
|
|
279
|
+
cXMLDtd = rb_define_class_under(mXML, "Dtd", rb_cObject);
|
|
280
|
+
rb_define_alloc_func(cXMLDtd, rxml_dtd_alloc);
|
|
281
|
+
rb_define_method(cXMLDtd, "initialize", rxml_dtd_initialize, -1);
|
|
282
|
+
rb_define_method(cXMLDtd, "external_id", rxml_dtd_external_id_get, 0);
|
|
283
|
+
rb_define_method(cXMLDtd, "name", rxml_dtd_name_get, 0);
|
|
284
|
+
rb_define_method(cXMLDtd, "uri", rxml_dtd_uri_get, 0);
|
|
285
|
+
rb_define_method(cXMLDtd, "node_type", rxml_dtd_type, 0);
|
|
286
|
+
rb_define_alias(cXMLDtd, "system_id", "uri");
|
|
287
|
+
}
|
data/ext/libxml/ruby_xml_dtd.h
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
#ifndef __RXML_DTD__
|
|
2
|
-
#define __RXML_DTD__
|
|
3
|
-
|
|
4
|
-
extern VALUE cXMLDtd;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
#ifndef __RXML_DTD__
|
|
2
|
+
#define __RXML_DTD__
|
|
3
|
+
|
|
4
|
+
extern VALUE cXMLDtd;
|
|
5
|
+
extern const rb_data_type_t rxml_dtd_data_type;
|
|
6
|
+
|
|
7
|
+
void rxml_init_dtd(void);
|
|
8
|
+
VALUE rxml_dtd_wrap(xmlDtdPtr xdtd);
|
|
9
|
+
|
|
10
|
+
#endif
|