libxml-ruby 2.8.0 → 3.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/HISTORY +842 -775
- data/LICENSE +20 -20
- data/MANIFEST +166 -166
- data/README.rdoc +217 -184
- data/Rakefile +90 -78
- data/ext/libxml/extconf.h +3 -0
- data/ext/libxml/extconf.rb +61 -116
- data/ext/libxml/libxml.c +80 -76
- data/ext/libxml/ruby_libxml.h +67 -75
- data/ext/libxml/ruby_xml.c +933 -893
- data/ext/libxml/ruby_xml.h +10 -10
- data/ext/libxml/ruby_xml_attr.c +333 -333
- data/ext/libxml/ruby_xml_attr.h +12 -12
- data/ext/libxml/ruby_xml_attr_decl.c +153 -153
- data/ext/libxml/ruby_xml_attr_decl.h +11 -11
- data/ext/libxml/ruby_xml_attributes.c +275 -275
- data/ext/libxml/ruby_xml_attributes.h +15 -15
- data/ext/libxml/ruby_xml_cbg.c +85 -85
- data/ext/libxml/ruby_xml_document.c +1123 -1147
- data/ext/libxml/ruby_xml_document.h +11 -11
- data/ext/libxml/ruby_xml_dtd.c +248 -268
- data/ext/libxml/ruby_xml_dtd.h +9 -9
- data/ext/libxml/ruby_xml_encoding.c +250 -260
- data/ext/libxml/ruby_xml_encoding.h +16 -19
- data/ext/libxml/ruby_xml_error.c +996 -996
- data/ext/libxml/ruby_xml_error.h +12 -12
- data/ext/libxml/ruby_xml_html_parser.c +89 -92
- data/ext/libxml/ruby_xml_html_parser.h +10 -10
- data/ext/libxml/ruby_xml_html_parser_context.c +337 -338
- data/ext/libxml/ruby_xml_html_parser_context.h +10 -10
- data/ext/libxml/ruby_xml_html_parser_options.c +46 -46
- data/ext/libxml/ruby_xml_html_parser_options.h +10 -10
- data/ext/libxml/ruby_xml_input_cbg.c +191 -191
- data/ext/libxml/ruby_xml_input_cbg.h +20 -20
- data/ext/libxml/ruby_xml_io.c +47 -50
- data/ext/libxml/ruby_xml_io.h +10 -10
- data/ext/libxml/ruby_xml_namespace.c +153 -153
- data/ext/libxml/ruby_xml_namespace.h +10 -10
- data/ext/libxml/ruby_xml_namespaces.c +293 -293
- data/ext/libxml/ruby_xml_namespaces.h +9 -9
- data/ext/libxml/ruby_xml_node.c +1402 -1452
- data/ext/libxml/ruby_xml_node.h +13 -11
- data/ext/libxml/ruby_xml_parser.c +91 -94
- data/ext/libxml/ruby_xml_parser.h +12 -12
- data/ext/libxml/ruby_xml_parser_context.c +999 -1001
- data/ext/libxml/ruby_xml_parser_context.h +10 -10
- data/ext/libxml/ruby_xml_parser_options.c +66 -66
- data/ext/libxml/ruby_xml_parser_options.h +12 -12
- data/ext/libxml/ruby_xml_reader.c +1239 -1228
- data/ext/libxml/ruby_xml_reader.h +17 -17
- data/ext/libxml/ruby_xml_relaxng.c +110 -111
- data/ext/libxml/ruby_xml_relaxng.h +10 -10
- data/ext/libxml/ruby_xml_sax2_handler.c +326 -328
- data/ext/libxml/ruby_xml_sax2_handler.h +10 -10
- data/ext/libxml/ruby_xml_sax_parser.c +116 -120
- data/ext/libxml/ruby_xml_sax_parser.h +10 -10
- data/ext/libxml/ruby_xml_schema.c +278 -301
- data/ext/libxml/ruby_xml_schema.h +809 -809
- data/ext/libxml/ruby_xml_schema_attribute.c +109 -109
- data/ext/libxml/ruby_xml_schema_attribute.h +15 -15
- data/ext/libxml/ruby_xml_schema_element.c +95 -94
- data/ext/libxml/ruby_xml_schema_element.h +14 -14
- data/ext/libxml/ruby_xml_schema_facet.c +52 -52
- data/ext/libxml/ruby_xml_schema_facet.h +13 -13
- data/ext/libxml/ruby_xml_schema_type.c +232 -259
- 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 +1133 -1137
- data/ext/libxml/ruby_xml_writer.h +10 -10
- data/ext/libxml/ruby_xml_xinclude.c +16 -16
- data/ext/libxml/ruby_xml_xinclude.h +11 -11
- data/ext/libxml/ruby_xml_xpath.c +194 -188
- data/ext/libxml/ruby_xml_xpath.h +13 -13
- data/ext/libxml/ruby_xml_xpath_context.c +360 -361
- data/ext/libxml/ruby_xml_xpath_context.h +9 -9
- data/ext/libxml/ruby_xml_xpath_expression.c +81 -81
- data/ext/libxml/ruby_xml_xpath_expression.h +10 -10
- data/ext/libxml/ruby_xml_xpath_object.c +338 -335
- data/ext/libxml/ruby_xml_xpath_object.h +17 -17
- data/ext/libxml/ruby_xml_xpointer.c +99 -99
- data/ext/libxml/ruby_xml_xpointer.h +11 -11
- data/ext/vc/libxml_ruby.sln +17 -15
- data/lib/libxml-ruby.rb +30 -0
- data/lib/libxml.rb +3 -33
- data/lib/libxml/node.rb +2 -78
- data/lib/libxml/parser.rb +0 -266
- data/lib/libxml/sax_parser.rb +0 -17
- data/lib/libxml/schema.rb +47 -66
- data/lib/libxml/schema/attribute.rb +19 -19
- data/lib/libxml/schema/element.rb +19 -27
- data/lib/libxml/schema/type.rb +21 -29
- data/libxml-ruby.gemspec +48 -44
- data/script/benchmark/depixelate +634 -634
- data/script/benchmark/hamlet.xml +9054 -9054
- data/script/benchmark/parsecount +170 -170
- data/script/benchmark/throughput +41 -41
- data/script/test +6 -6
- data/setup.rb +0 -1
- data/test/c14n/given/example-1.xml +14 -14
- data/test/c14n/given/example-2.xml +11 -11
- data/test/c14n/given/example-3.xml +18 -18
- data/test/c14n/given/example-4.xml +9 -9
- data/test/c14n/given/example-5.xml +12 -12
- data/test/c14n/given/example-6.xml +2 -2
- data/test/c14n/given/example-7.xml +11 -11
- data/test/c14n/given/example-8.xml +11 -11
- data/test/c14n/given/example-8.xpath +9 -9
- 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/model/atom.xml +12 -12
- data/test/model/bands.iso-8859-1.xml +4 -4
- data/test/model/bands.utf-8.xml +4 -4
- data/test/model/bands.xml +4 -4
- data/test/model/books.xml +153 -153
- data/test/model/cwm_1_0.xml +11336 -0
- data/test/model/merge_bug_data.xml +58 -58
- data/test/model/ruby-lang.html +238 -238
- data/test/model/rubynet.xml +79 -79
- data/test/model/shiporder.rnc +28 -28
- data/test/model/shiporder.rng +86 -86
- data/test/model/shiporder.xml +22 -22
- data/test/model/shiporder.xsd +39 -39
- data/test/model/soap.xml +27 -27
- data/test/model/xinclude.xml +4 -4
- data/test/test.xml +2 -0
- data/test/{tc_attr.rb → test_attr.rb} +23 -25
- data/test/{tc_attr_decl.rb → test_attr_decl.rb} +13 -14
- data/test/{tc_attributes.rb → test_attributes.rb} +11 -18
- data/test/{tc_canonicalize.rb → test_canonicalize.rb} +36 -41
- data/test/test_deprecated_require.rb +12 -0
- data/test/{tc_document.rb → test_document.rb} +32 -27
- data/test/test_document_write.rb +146 -0
- data/test/{tc_dtd.rb → test_dtd.rb} +28 -29
- data/test/{tc_encoding.rb → test_encoding.rb} +129 -126
- data/test/{tc_encoding_sax.rb → test_encoding_sax.rb} +7 -6
- data/test/test_error.rb +178 -0
- data/test/test_helper.rb +3 -10
- data/test/test_html_parser.rb +162 -0
- data/test/test_html_parser_context.rb +23 -0
- data/test/test_namespace.rb +60 -0
- data/test/{tc_namespaces.rb → test_namespaces.rb} +34 -44
- data/test/{tc_node.rb → test_node.rb} +68 -47
- data/test/{tc_node_cdata.rb → test_node_cdata.rb} +12 -13
- data/test/{tc_node_comment.rb → test_node_comment.rb} +7 -8
- data/test/{tc_node_copy.rb → test_node_copy.rb} +4 -6
- data/test/{tc_node_edit.rb → test_node_edit.rb} +23 -41
- data/test/{tc_node_pi.rb → test_node_pi.rb} +37 -40
- data/test/{tc_node_text.rb → test_node_text.rb} +10 -12
- data/test/{tc_node_write.rb → test_node_write.rb} +18 -29
- data/test/test_node_xlink.rb +28 -0
- data/test/test_parser.rb +324 -0
- data/test/{tc_parser_context.rb → test_parser_context.rb} +41 -42
- data/test/{tc_properties.rb → test_properties.rb} +6 -7
- data/test/test_reader.rb +363 -0
- data/test/test_relaxng.rb +53 -0
- data/test/{tc_sax_parser.rb → test_sax_parser.rb} +36 -37
- data/test/{tc_schema.rb → test_schema.rb} +43 -37
- data/test/test_suite.rb +38 -40
- data/test/{tc_traversal.rb → test_traversal.rb} +5 -6
- data/test/{tc_writer.rb → test_writer.rb} +468 -448
- data/test/{tc_xinclude.rb → test_xinclude.rb} +4 -5
- data/test/test_xml.rb +262 -0
- data/test/{tc_xpath.rb → test_xpath.rb} +31 -32
- data/test/{tc_xpath_context.rb → test_xpath_context.rb} +8 -9
- data/test/test_xpath_expression.rb +37 -0
- data/test/{tc_xpointer.rb → test_xpointer.rb} +16 -18
- metadata +117 -95
- data/lib/libxml/ns.rb +0 -22
- data/lib/libxml/properties.rb +0 -23
- data/lib/libxml/reader.rb +0 -29
- data/lib/libxml/xpath_object.rb +0 -16
- 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/tc_deprecated_require.rb +0 -13
- data/test/tc_document_write.rb +0 -196
- data/test/tc_error.rb +0 -180
- data/test/tc_html_parser.rb +0 -153
- data/test/tc_html_parser_context.rb +0 -24
- data/test/tc_namespace.rb +0 -62
- data/test/tc_node_xlink.rb +0 -29
- data/test/tc_parser.rb +0 -381
- data/test/tc_reader.rb +0 -400
- data/test/tc_relaxng.rb +0 -54
- data/test/tc_xml.rb +0 -226
- data/test/tc_xpath_expression.rb +0 -38
@@ -1,9 +1,9 @@
|
|
1
|
-
/* Please see the LICENSE file for copyright and distribution information */
|
2
|
-
|
3
|
-
#ifndef __RXML_NAMESPACES__
|
4
|
-
#define __RXML_NAMESPACES__
|
5
|
-
|
6
|
-
extern VALUE cXMLNamespaces;
|
7
|
-
|
8
|
-
void rxml_init_namespaces(void);
|
9
|
-
#endif
|
1
|
+
/* Please see the LICENSE file for copyright and distribution information */
|
2
|
+
|
3
|
+
#ifndef __RXML_NAMESPACES__
|
4
|
+
#define __RXML_NAMESPACES__
|
5
|
+
|
6
|
+
extern VALUE cXMLNamespaces;
|
7
|
+
|
8
|
+
void rxml_init_namespaces(void);
|
9
|
+
#endif
|
data/ext/libxml/ruby_xml_node.c
CHANGED
@@ -1,1452 +1,1402 @@
|
|
1
|
-
#include "ruby_libxml.h"
|
2
|
-
#include "ruby_xml_node.h"
|
3
|
-
#include <assert.h>
|
4
|
-
|
5
|
-
VALUE cXMLNode;
|
6
|
-
|
7
|
-
/* Document-class: LibXML::XML::Node
|
8
|
-
*
|
9
|
-
* Nodes are the primary objects that make up an XML document.
|
10
|
-
* The node class represents most node types that are found in
|
11
|
-
* an XML document (but not LibXML::XML::Attributes, see LibXML::XML::Attr).
|
12
|
-
* It exposes libxml's full API for creating, querying
|
13
|
-
* moving and deleting node objects. Many of these methods are
|
14
|
-
* documented in the DOM Level 3 specification found at:
|
15
|
-
* http://www.w3.org/TR/DOM-Level-3-Core/. */
|
16
|
-
|
17
|
-
|
18
|
-
/* Memory management:
|
19
|
-
*
|
20
|
-
* The bindings create a one-to-one mapping between
|
21
|
-
*
|
22
|
-
*
|
23
|
-
*
|
24
|
-
*
|
25
|
-
*
|
26
|
-
*
|
27
|
-
*
|
28
|
-
*
|
29
|
-
*
|
30
|
-
*
|
31
|
-
*
|
32
|
-
*
|
33
|
-
*
|
34
|
-
*
|
35
|
-
*
|
36
|
-
*
|
37
|
-
*
|
38
|
-
*
|
39
|
-
* is
|
40
|
-
*
|
41
|
-
|
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
|
-
xnode->_private = NULL;
|
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
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
*
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
xmlChar
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
{
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
*
|
554
|
-
*
|
555
|
-
*
|
556
|
-
*
|
557
|
-
*
|
558
|
-
*
|
559
|
-
*
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
/*
|
672
|
-
* call-seq:
|
673
|
-
* node.
|
674
|
-
*
|
675
|
-
*
|
676
|
-
|
677
|
-
static VALUE
|
678
|
-
{
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
}
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
*
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
xnode
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
|
750
|
-
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
*
|
765
|
-
|
766
|
-
|
767
|
-
|
768
|
-
|
769
|
-
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
|
776
|
-
|
777
|
-
|
778
|
-
return (Qnil);
|
779
|
-
|
780
|
-
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
*
|
785
|
-
*
|
786
|
-
*
|
787
|
-
*
|
788
|
-
*/
|
789
|
-
static VALUE
|
790
|
-
{
|
791
|
-
xmlNodePtr xnode;
|
792
|
-
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
|
805
|
-
|
806
|
-
|
807
|
-
*
|
808
|
-
*
|
809
|
-
*
|
810
|
-
|
811
|
-
|
812
|
-
|
813
|
-
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
|
819
|
-
|
820
|
-
|
821
|
-
|
822
|
-
|
823
|
-
|
824
|
-
|
825
|
-
|
826
|
-
|
827
|
-
*
|
828
|
-
*
|
829
|
-
*
|
830
|
-
*
|
831
|
-
*
|
832
|
-
|
833
|
-
|
834
|
-
|
835
|
-
|
836
|
-
|
837
|
-
|
838
|
-
|
839
|
-
|
840
|
-
|
841
|
-
|
842
|
-
|
843
|
-
|
844
|
-
|
845
|
-
|
846
|
-
|
847
|
-
|
848
|
-
|
849
|
-
|
850
|
-
|
851
|
-
|
852
|
-
|
853
|
-
|
854
|
-
|
855
|
-
|
856
|
-
|
857
|
-
|
858
|
-
|
859
|
-
|
860
|
-
|
861
|
-
|
862
|
-
|
863
|
-
|
864
|
-
|
865
|
-
|
866
|
-
|
867
|
-
|
868
|
-
|
869
|
-
|
870
|
-
|
871
|
-
|
872
|
-
|
873
|
-
|
874
|
-
|
875
|
-
|
876
|
-
|
877
|
-
|
878
|
-
|
879
|
-
|
880
|
-
|
881
|
-
|
882
|
-
|
883
|
-
|
884
|
-
|
885
|
-
|
886
|
-
|
887
|
-
|
888
|
-
|
889
|
-
|
890
|
-
|
891
|
-
|
892
|
-
|
893
|
-
|
894
|
-
|
895
|
-
|
896
|
-
|
897
|
-
|
898
|
-
|
899
|
-
|
900
|
-
|
901
|
-
name
|
902
|
-
|
903
|
-
|
904
|
-
|
905
|
-
|
906
|
-
|
907
|
-
|
908
|
-
|
909
|
-
|
910
|
-
|
911
|
-
|
912
|
-
|
913
|
-
|
914
|
-
|
915
|
-
|
916
|
-
|
917
|
-
|
918
|
-
|
919
|
-
|
920
|
-
|
921
|
-
|
922
|
-
|
923
|
-
|
924
|
-
|
925
|
-
|
926
|
-
|
927
|
-
|
928
|
-
*
|
929
|
-
*
|
930
|
-
|
931
|
-
|
932
|
-
|
933
|
-
|
934
|
-
|
935
|
-
|
936
|
-
|
937
|
-
|
938
|
-
|
939
|
-
|
940
|
-
|
941
|
-
|
942
|
-
|
943
|
-
|
944
|
-
|
945
|
-
|
946
|
-
|
947
|
-
|
948
|
-
|
949
|
-
*
|
950
|
-
*
|
951
|
-
*
|
952
|
-
|
953
|
-
|
954
|
-
|
955
|
-
|
956
|
-
|
957
|
-
|
958
|
-
|
959
|
-
|
960
|
-
|
961
|
-
|
962
|
-
|
963
|
-
|
964
|
-
|
965
|
-
|
966
|
-
|
967
|
-
|
968
|
-
|
969
|
-
|
970
|
-
|
971
|
-
|
972
|
-
|
973
|
-
|
974
|
-
|
975
|
-
|
976
|
-
|
977
|
-
|
978
|
-
|
979
|
-
|
980
|
-
|
981
|
-
|
982
|
-
|
983
|
-
|
984
|
-
|
985
|
-
*
|
986
|
-
|
987
|
-
|
988
|
-
|
989
|
-
|
990
|
-
|
991
|
-
|
992
|
-
|
993
|
-
|
994
|
-
|
995
|
-
|
996
|
-
|
997
|
-
|
998
|
-
|
999
|
-
|
1000
|
-
*
|
1001
|
-
|
1002
|
-
|
1003
|
-
|
1004
|
-
|
1005
|
-
|
1006
|
-
|
1007
|
-
|
1008
|
-
|
1009
|
-
|
1010
|
-
|
1011
|
-
|
1012
|
-
|
1013
|
-
|
1014
|
-
|
1015
|
-
|
1016
|
-
|
1017
|
-
|
1018
|
-
|
1019
|
-
|
1020
|
-
|
1021
|
-
|
1022
|
-
|
1023
|
-
|
1024
|
-
|
1025
|
-
|
1026
|
-
|
1027
|
-
|
1028
|
-
|
1029
|
-
|
1030
|
-
|
1031
|
-
|
1032
|
-
|
1033
|
-
|
1034
|
-
|
1035
|
-
|
1036
|
-
|
1037
|
-
|
1038
|
-
|
1039
|
-
|
1040
|
-
|
1041
|
-
|
1042
|
-
|
1043
|
-
|
1044
|
-
|
1045
|
-
|
1046
|
-
|
1047
|
-
|
1048
|
-
|
1049
|
-
|
1050
|
-
|
1051
|
-
|
1052
|
-
|
1053
|
-
|
1054
|
-
|
1055
|
-
|
1056
|
-
|
1057
|
-
|
1058
|
-
|
1059
|
-
|
1060
|
-
|
1061
|
-
|
1062
|
-
|
1063
|
-
|
1064
|
-
|
1065
|
-
|
1066
|
-
|
1067
|
-
|
1068
|
-
|
1069
|
-
|
1070
|
-
|
1071
|
-
|
1072
|
-
|
1073
|
-
|
1074
|
-
|
1075
|
-
|
1076
|
-
*
|
1077
|
-
*
|
1078
|
-
|
1079
|
-
|
1080
|
-
|
1081
|
-
|
1082
|
-
|
1083
|
-
|
1084
|
-
|
1085
|
-
|
1086
|
-
|
1087
|
-
|
1088
|
-
|
1089
|
-
|
1090
|
-
|
1091
|
-
|
1092
|
-
|
1093
|
-
|
1094
|
-
|
1095
|
-
|
1096
|
-
|
1097
|
-
|
1098
|
-
|
1099
|
-
|
1100
|
-
|
1101
|
-
*
|
1102
|
-
*
|
1103
|
-
*
|
1104
|
-
|
1105
|
-
|
1106
|
-
|
1107
|
-
|
1108
|
-
|
1109
|
-
|
1110
|
-
|
1111
|
-
|
1112
|
-
|
1113
|
-
|
1114
|
-
|
1115
|
-
|
1116
|
-
|
1117
|
-
|
1118
|
-
|
1119
|
-
|
1120
|
-
return
|
1121
|
-
}
|
1122
|
-
|
1123
|
-
/*
|
1124
|
-
* call-seq:
|
1125
|
-
*
|
1126
|
-
*
|
1127
|
-
*
|
1128
|
-
*
|
1129
|
-
*
|
1130
|
-
|
1131
|
-
|
1132
|
-
|
1133
|
-
|
1134
|
-
|
1135
|
-
|
1136
|
-
|
1137
|
-
|
1138
|
-
|
1139
|
-
|
1140
|
-
|
1141
|
-
|
1142
|
-
|
1143
|
-
|
1144
|
-
|
1145
|
-
|
1146
|
-
|
1147
|
-
|
1148
|
-
|
1149
|
-
|
1150
|
-
|
1151
|
-
|
1152
|
-
|
1153
|
-
|
1154
|
-
|
1155
|
-
|
1156
|
-
|
1157
|
-
|
1158
|
-
|
1159
|
-
|
1160
|
-
|
1161
|
-
|
1162
|
-
|
1163
|
-
|
1164
|
-
|
1165
|
-
|
1166
|
-
|
1167
|
-
*
|
1168
|
-
|
1169
|
-
|
1170
|
-
|
1171
|
-
|
1172
|
-
|
1173
|
-
|
1174
|
-
|
1175
|
-
|
1176
|
-
|
1177
|
-
|
1178
|
-
|
1179
|
-
|
1180
|
-
|
1181
|
-
|
1182
|
-
|
1183
|
-
|
1184
|
-
|
1185
|
-
|
1186
|
-
|
1187
|
-
|
1188
|
-
|
1189
|
-
|
1190
|
-
*
|
1191
|
-
*
|
1192
|
-
*
|
1193
|
-
*
|
1194
|
-
*
|
1195
|
-
*
|
1196
|
-
*
|
1197
|
-
|
1198
|
-
|
1199
|
-
|
1200
|
-
|
1201
|
-
|
1202
|
-
|
1203
|
-
|
1204
|
-
|
1205
|
-
|
1206
|
-
|
1207
|
-
|
1208
|
-
|
1209
|
-
|
1210
|
-
|
1211
|
-
|
1212
|
-
|
1213
|
-
|
1214
|
-
|
1215
|
-
|
1216
|
-
|
1217
|
-
|
1218
|
-
|
1219
|
-
|
1220
|
-
|
1221
|
-
|
1222
|
-
|
1223
|
-
|
1224
|
-
|
1225
|
-
|
1226
|
-
|
1227
|
-
|
1228
|
-
|
1229
|
-
|
1230
|
-
|
1231
|
-
|
1232
|
-
|
1233
|
-
|
1234
|
-
|
1235
|
-
|
1236
|
-
|
1237
|
-
|
1238
|
-
|
1239
|
-
|
1240
|
-
|
1241
|
-
|
1242
|
-
|
1243
|
-
*
|
1244
|
-
|
1245
|
-
|
1246
|
-
|
1247
|
-
|
1248
|
-
|
1249
|
-
|
1250
|
-
|
1251
|
-
|
1252
|
-
|
1253
|
-
|
1254
|
-
|
1255
|
-
|
1256
|
-
|
1257
|
-
|
1258
|
-
|
1259
|
-
|
1260
|
-
|
1261
|
-
|
1262
|
-
|
1263
|
-
|
1264
|
-
|
1265
|
-
|
1266
|
-
|
1267
|
-
|
1268
|
-
|
1269
|
-
|
1270
|
-
|
1271
|
-
|
1272
|
-
|
1273
|
-
|
1274
|
-
|
1275
|
-
*
|
1276
|
-
|
1277
|
-
|
1278
|
-
|
1279
|
-
|
1280
|
-
|
1281
|
-
|
1282
|
-
|
1283
|
-
|
1284
|
-
|
1285
|
-
|
1286
|
-
|
1287
|
-
|
1288
|
-
|
1289
|
-
|
1290
|
-
|
1291
|
-
|
1292
|
-
|
1293
|
-
|
1294
|
-
|
1295
|
-
|
1296
|
-
|
1297
|
-
|
1298
|
-
|
1299
|
-
|
1300
|
-
|
1301
|
-
|
1302
|
-
|
1303
|
-
|
1304
|
-
|
1305
|
-
|
1306
|
-
|
1307
|
-
|
1308
|
-
|
1309
|
-
|
1310
|
-
|
1311
|
-
|
1312
|
-
|
1313
|
-
|
1314
|
-
|
1315
|
-
|
1316
|
-
|
1317
|
-
|
1318
|
-
|
1319
|
-
|
1320
|
-
|
1321
|
-
|
1322
|
-
|
1323
|
-
|
1324
|
-
|
1325
|
-
|
1326
|
-
|
1327
|
-
|
1328
|
-
|
1329
|
-
|
1330
|
-
|
1331
|
-
|
1332
|
-
|
1333
|
-
|
1334
|
-
|
1335
|
-
|
1336
|
-
|
1337
|
-
|
1338
|
-
|
1339
|
-
|
1340
|
-
|
1341
|
-
|
1342
|
-
|
1343
|
-
|
1344
|
-
|
1345
|
-
|
1346
|
-
|
1347
|
-
|
1348
|
-
|
1349
|
-
|
1350
|
-
|
1351
|
-
|
1352
|
-
|
1353
|
-
|
1354
|
-
|
1355
|
-
|
1356
|
-
|
1357
|
-
|
1358
|
-
|
1359
|
-
|
1360
|
-
|
1361
|
-
|
1362
|
-
|
1363
|
-
|
1364
|
-
|
1365
|
-
|
1366
|
-
|
1367
|
-
|
1368
|
-
|
1369
|
-
|
1370
|
-
|
1371
|
-
|
1372
|
-
|
1373
|
-
|
1374
|
-
|
1375
|
-
|
1376
|
-
|
1377
|
-
|
1378
|
-
|
1379
|
-
|
1380
|
-
|
1381
|
-
|
1382
|
-
|
1383
|
-
|
1384
|
-
|
1385
|
-
|
1386
|
-
|
1387
|
-
|
1388
|
-
|
1389
|
-
|
1390
|
-
|
1391
|
-
|
1392
|
-
|
1393
|
-
|
1394
|
-
|
1395
|
-
|
1396
|
-
|
1397
|
-
|
1398
|
-
|
1399
|
-
|
1400
|
-
|
1401
|
-
|
1402
|
-
|
1403
|
-
/* Traversal */
|
1404
|
-
rb_include_module(cXMLNode, rb_mEnumerable);
|
1405
|
-
rb_define_method(cXMLNode, "[]", rxml_node_attribute_get, 1);
|
1406
|
-
rb_define_method(cXMLNode, "each", rxml_node_each, 0);
|
1407
|
-
rb_define_method(cXMLNode, "first", rxml_node_first_get, 0);
|
1408
|
-
rb_define_method(cXMLNode, "last", rxml_node_last_get, 0);
|
1409
|
-
rb_define_method(cXMLNode, "next", rxml_node_next_get, 0);
|
1410
|
-
rb_define_method(cXMLNode, "parent", rxml_node_parent_get, 0);
|
1411
|
-
rb_define_method(cXMLNode, "prev", rxml_node_prev_get, 0);
|
1412
|
-
|
1413
|
-
/* Modification */
|
1414
|
-
rb_define_method(cXMLNode, "[]=", rxml_node_property_set, 2);
|
1415
|
-
rb_define_method(cXMLNode, "<<", rxml_node_content_add, 1);
|
1416
|
-
rb_define_method(cXMLNode, "sibling=", rxml_node_sibling_set, 1);
|
1417
|
-
rb_define_method(cXMLNode, "next=", rxml_node_next_set, 1);
|
1418
|
-
rb_define_method(cXMLNode, "prev=", rxml_node_prev_set, 1);
|
1419
|
-
|
1420
|
-
/* Rest of the node api */
|
1421
|
-
rb_define_method(cXMLNode, "attributes", rxml_node_attributes_get, 0);
|
1422
|
-
rb_define_method(cXMLNode, "base_uri", rxml_node_base_uri_get, 0);
|
1423
|
-
rb_define_method(cXMLNode, "base_uri=", rxml_node_base_uri_set, 1);
|
1424
|
-
rb_define_method(cXMLNode, "blank?", rxml_node_empty_q, 0);
|
1425
|
-
rb_define_method(cXMLNode, "copy", rxml_node_copy, 1);
|
1426
|
-
rb_define_method(cXMLNode, "content", rxml_node_content_get, 0);
|
1427
|
-
rb_define_method(cXMLNode, "content=", rxml_node_content_set, 1);
|
1428
|
-
rb_define_method(cXMLNode, "content_stripped", rxml_node_content_stripped_get, 0);
|
1429
|
-
rb_define_method(cXMLNode, "debug", rxml_node_debug, 0);
|
1430
|
-
rb_define_method(cXMLNode, "doc", rxml_node_doc, 0);
|
1431
|
-
rb_define_method(cXMLNode, "empty?", rxml_node_empty_q, 0);
|
1432
|
-
rb_define_method(cXMLNode, "eql?", rxml_node_eql_q, 1);
|
1433
|
-
rb_define_method(cXMLNode, "lang", rxml_node_lang_get, 0);
|
1434
|
-
rb_define_method(cXMLNode, "lang=", rxml_node_lang_set, 1);
|
1435
|
-
rb_define_method(cXMLNode, "line_num", rxml_node_line_num, 0);
|
1436
|
-
rb_define_method(cXMLNode, "name", rxml_node_name_get, 0);
|
1437
|
-
rb_define_method(cXMLNode, "name=", rxml_node_name_set, 1);
|
1438
|
-
rb_define_method(cXMLNode, "node_type", rxml_node_type, 0);
|
1439
|
-
rb_define_method(cXMLNode, "output_escaping?", rxml_node_output_escaping_q, 0);
|
1440
|
-
rb_define_method(cXMLNode, "output_escaping=", rxml_node_output_escaping_set, 1);
|
1441
|
-
rb_define_method(cXMLNode, "path", rxml_node_path, 0);
|
1442
|
-
rb_define_method(cXMLNode, "pointer", rxml_node_pointer, 1);
|
1443
|
-
rb_define_method(cXMLNode, "remove!", rxml_node_remove_ex, 0);
|
1444
|
-
rb_define_method(cXMLNode, "space_preserve", rxml_node_space_preserve_get, 0);
|
1445
|
-
rb_define_method(cXMLNode, "space_preserve=", rxml_node_space_preserve_set, 1);
|
1446
|
-
rb_define_method(cXMLNode, "to_s", rxml_node_to_s, -1);
|
1447
|
-
rb_define_method(cXMLNode, "xlink?", rxml_node_xlink_q, 0);
|
1448
|
-
rb_define_method(cXMLNode, "xlink_type", rxml_node_xlink_type, 0);
|
1449
|
-
rb_define_method(cXMLNode, "xlink_type_name", rxml_node_xlink_type_name, 0);
|
1450
|
-
|
1451
|
-
rb_define_alias(cXMLNode, "==", "eql?");
|
1452
|
-
}
|
1
|
+
#include "ruby_libxml.h"
|
2
|
+
#include "ruby_xml_node.h"
|
3
|
+
#include <assert.h>
|
4
|
+
|
5
|
+
VALUE cXMLNode;
|
6
|
+
|
7
|
+
/* Document-class: LibXML::XML::Node
|
8
|
+
*
|
9
|
+
* Nodes are the primary objects that make up an XML document.
|
10
|
+
* The node class represents most node types that are found in
|
11
|
+
* an XML document (but not LibXML::XML::Attributes, see LibXML::XML::Attr).
|
12
|
+
* It exposes libxml's full API for creating, querying
|
13
|
+
* moving and deleting node objects. Many of these methods are
|
14
|
+
* documented in the DOM Level 3 specification found at:
|
15
|
+
* http://www.w3.org/TR/DOM-Level-3-Core/. */
|
16
|
+
|
17
|
+
|
18
|
+
/* Memory management:
|
19
|
+
*
|
20
|
+
* The bindings create a one-to-one mapping between ruby objects and
|
21
|
+
* libxml documents and libxml parent nodes (ie, nodes that do not
|
22
|
+
* have a parent and do not belong to a document). In these cases,
|
23
|
+
* the bindings manage the memory. They do this by installing a free
|
24
|
+
* function and storing a back pointer to the Ruby object from the xmlnode
|
25
|
+
* using the _private member on libxml structures. When the Ruby object
|
26
|
+
* goes out of scope, the underlying libxml structure is freed. Libxml
|
27
|
+
* itself then frees all child node (recursively).
|
28
|
+
*
|
29
|
+
* For all other nodes (the vast majority), the bindings create temporary
|
30
|
+
* Ruby objects that get freed once they go out of scope. Thus there can be
|
31
|
+
* more than one ruby object pointing to the same xml node. To mostly hide
|
32
|
+
* this from programmers on the ruby side, the #eql? and #== methods are
|
33
|
+
* overriden to check if two ruby objects wrap the same xmlnode. If they do,
|
34
|
+
* then the methods return true. During the mark phase, each of these temporary
|
35
|
+
* objects marks its owning document, thereby keeping the Ruby document object
|
36
|
+
* alive and thus the xmldoc tree.
|
37
|
+
*
|
38
|
+
* In the sweep phase of the garbage collector, or when a program ends,
|
39
|
+
* there is no order to how Ruby objects are freed. In fact, the ruby document
|
40
|
+
* object is almost always freed before any ruby objects that wrap child nodes.
|
41
|
+
* However, this is ok because those ruby objects do not have a free function
|
42
|
+
* and are no longer in scope (since if they were the document would not be freed).
|
43
|
+
*/
|
44
|
+
|
45
|
+
static void rxml_node_free(xmlNodePtr xnode)
|
46
|
+
{
|
47
|
+
/* The ruby object wrapping the xml object no longer exists and this
|
48
|
+
is a standalone node without a document or parent so ruby is
|
49
|
+
responsible for freeing the underlying node.*/
|
50
|
+
if (xnode->doc == NULL && xnode->parent == NULL)
|
51
|
+
{
|
52
|
+
// Remove the back linkage from libxml to Ruby
|
53
|
+
xnode->_private = NULL;
|
54
|
+
xmlFreeNode(xnode);
|
55
|
+
}
|
56
|
+
}
|
57
|
+
|
58
|
+
void rxml_node_manage(xmlNodePtr xnode, VALUE node)
|
59
|
+
{
|
60
|
+
RDATA(node)->dfree = (RUBY_DATA_FUNC)rxml_node_free;
|
61
|
+
xnode->_private = (void*)node;
|
62
|
+
}
|
63
|
+
|
64
|
+
void rxml_node_unmanage(xmlNodePtr xnode, VALUE node)
|
65
|
+
{
|
66
|
+
RDATA(node)->dfree = NULL;
|
67
|
+
xnode->_private = NULL;
|
68
|
+
}
|
69
|
+
|
70
|
+
xmlNodePtr rxml_node_root(xmlNodePtr xnode)
|
71
|
+
{
|
72
|
+
xmlNodePtr current = xnode;
|
73
|
+
|
74
|
+
while (current->parent)
|
75
|
+
{
|
76
|
+
current = current->parent;
|
77
|
+
}
|
78
|
+
|
79
|
+
return current;
|
80
|
+
}
|
81
|
+
|
82
|
+
void rxml_node_mark(xmlNodePtr xnode)
|
83
|
+
{
|
84
|
+
if (xnode->doc)
|
85
|
+
{
|
86
|
+
if (xnode->doc->_private)
|
87
|
+
{
|
88
|
+
VALUE doc = (VALUE)xnode->doc->_private;
|
89
|
+
rb_gc_mark(doc);
|
90
|
+
}
|
91
|
+
}
|
92
|
+
else if (xnode->parent)
|
93
|
+
{
|
94
|
+
xmlNodePtr root = rxml_node_root(xnode);
|
95
|
+
if (root->_private)
|
96
|
+
{
|
97
|
+
VALUE node = (VALUE)root->_private;
|
98
|
+
rb_gc_mark(node);
|
99
|
+
}
|
100
|
+
}
|
101
|
+
}
|
102
|
+
|
103
|
+
VALUE rxml_node_wrap(xmlNodePtr xnode)
|
104
|
+
{
|
105
|
+
VALUE result = Qnil;
|
106
|
+
|
107
|
+
// Is this node already wrapped?
|
108
|
+
if (xnode->_private)
|
109
|
+
{
|
110
|
+
result = (VALUE)xnode->_private;
|
111
|
+
}
|
112
|
+
else
|
113
|
+
{
|
114
|
+
result = Data_Wrap_Struct(cXMLNode, rxml_node_mark, NULL, xnode);
|
115
|
+
}
|
116
|
+
|
117
|
+
if (!xnode->doc && !xnode->parent)
|
118
|
+
{
|
119
|
+
rxml_node_manage(xnode, result);
|
120
|
+
}
|
121
|
+
return result;
|
122
|
+
}
|
123
|
+
|
124
|
+
static VALUE rxml_node_alloc(VALUE klass)
|
125
|
+
{
|
126
|
+
// This node was created from Ruby so we are responsible for freeing it not libxml
|
127
|
+
return Data_Wrap_Struct(klass, rxml_node_mark, rxml_node_free, NULL);
|
128
|
+
}
|
129
|
+
|
130
|
+
static xmlNodePtr rxml_get_xnode(VALUE node)
|
131
|
+
{
|
132
|
+
xmlNodePtr result;
|
133
|
+
Data_Get_Struct(node, xmlNode, result);
|
134
|
+
|
135
|
+
if (!result)
|
136
|
+
rb_raise(rb_eRuntimeError, "This node has already been freed.");
|
137
|
+
|
138
|
+
return result;
|
139
|
+
}
|
140
|
+
|
141
|
+
/*
|
142
|
+
* call-seq:
|
143
|
+
* XML::Node.new_cdata(content = nil) -> XML::Node
|
144
|
+
*
|
145
|
+
* Create a new #CDATA node, optionally setting
|
146
|
+
* the node's content.
|
147
|
+
*/
|
148
|
+
static VALUE rxml_node_new_cdata(int argc, VALUE *argv, VALUE klass)
|
149
|
+
{
|
150
|
+
VALUE content = Qnil;
|
151
|
+
xmlNodePtr xnode;
|
152
|
+
|
153
|
+
rb_scan_args(argc, argv, "01", &content);
|
154
|
+
|
155
|
+
if (NIL_P(content))
|
156
|
+
{
|
157
|
+
xnode = xmlNewCDataBlock(NULL, NULL, 0);
|
158
|
+
}
|
159
|
+
else
|
160
|
+
{
|
161
|
+
content = rb_obj_as_string(content);
|
162
|
+
xnode = xmlNewCDataBlock(NULL, (xmlChar*) StringValuePtr(content), (int)RSTRING_LEN(content));
|
163
|
+
}
|
164
|
+
|
165
|
+
if (xnode == NULL)
|
166
|
+
rxml_raise(&xmlLastError);
|
167
|
+
|
168
|
+
return rxml_node_wrap(xnode);
|
169
|
+
}
|
170
|
+
|
171
|
+
/*
|
172
|
+
* call-seq:
|
173
|
+
* XML::Node.new_comment(content = nil) -> XML::Node
|
174
|
+
*
|
175
|
+
* Create a new comment node, optionally setting
|
176
|
+
* the node's content.
|
177
|
+
*
|
178
|
+
*/
|
179
|
+
static VALUE rxml_node_new_comment(int argc, VALUE *argv, VALUE klass)
|
180
|
+
{
|
181
|
+
VALUE content = Qnil;
|
182
|
+
xmlNodePtr xnode;
|
183
|
+
|
184
|
+
rb_scan_args(argc, argv, "01", &content);
|
185
|
+
|
186
|
+
if (NIL_P(content))
|
187
|
+
{
|
188
|
+
xnode = xmlNewComment(NULL);
|
189
|
+
}
|
190
|
+
else
|
191
|
+
{
|
192
|
+
content = rb_obj_as_string(content);
|
193
|
+
xnode = xmlNewComment((xmlChar*) StringValueCStr(content));
|
194
|
+
}
|
195
|
+
|
196
|
+
if (xnode == NULL)
|
197
|
+
rxml_raise(&xmlLastError);
|
198
|
+
|
199
|
+
return rxml_node_wrap(xnode);
|
200
|
+
}
|
201
|
+
|
202
|
+
/*
|
203
|
+
* call-seq:
|
204
|
+
* XML::Node.new_pi(name, content = nil) -> XML::Node
|
205
|
+
*
|
206
|
+
* Create a new pi node, optionally setting
|
207
|
+
* the node's content.
|
208
|
+
*
|
209
|
+
*/
|
210
|
+
static VALUE rxml_node_new_pi(int argc, VALUE *argv, VALUE klass)
|
211
|
+
{
|
212
|
+
VALUE name = Qnil;
|
213
|
+
VALUE content = Qnil;
|
214
|
+
xmlNodePtr xnode;
|
215
|
+
|
216
|
+
rb_scan_args(argc, argv, "11", &name, &content);
|
217
|
+
|
218
|
+
if (NIL_P(name))
|
219
|
+
{
|
220
|
+
rb_raise(rb_eRuntimeError, "You must provide me with a name for a PI.");
|
221
|
+
}
|
222
|
+
name = rb_obj_as_string(name);
|
223
|
+
if (NIL_P(content))
|
224
|
+
{
|
225
|
+
xnode = xmlNewPI((xmlChar*) StringValuePtr(name), NULL);
|
226
|
+
}
|
227
|
+
else
|
228
|
+
{
|
229
|
+
content = rb_obj_as_string(content);
|
230
|
+
xnode = xmlNewPI((xmlChar*) StringValuePtr(name), (xmlChar*) StringValueCStr(content));
|
231
|
+
}
|
232
|
+
|
233
|
+
if (xnode == NULL)
|
234
|
+
rxml_raise(&xmlLastError);
|
235
|
+
|
236
|
+
return rxml_node_wrap(xnode);
|
237
|
+
}
|
238
|
+
|
239
|
+
/*
|
240
|
+
* call-seq:
|
241
|
+
* XML::Node.new_text(content) -> XML::Node
|
242
|
+
*
|
243
|
+
* Create a new text node.
|
244
|
+
*
|
245
|
+
*/
|
246
|
+
static VALUE rxml_node_new_text(VALUE klass, VALUE content)
|
247
|
+
{
|
248
|
+
xmlNodePtr xnode;
|
249
|
+
Check_Type(content, T_STRING);
|
250
|
+
content = rb_obj_as_string(content);
|
251
|
+
|
252
|
+
xnode = xmlNewText((xmlChar*) StringValueCStr(content));
|
253
|
+
|
254
|
+
if (xnode == NULL)
|
255
|
+
rxml_raise(&xmlLastError);
|
256
|
+
|
257
|
+
return rxml_node_wrap(xnode);
|
258
|
+
}
|
259
|
+
|
260
|
+
static VALUE rxml_node_content_set(VALUE self, VALUE content);
|
261
|
+
|
262
|
+
/*
|
263
|
+
* call-seq:
|
264
|
+
* XML::Node.initialize(name, content = nil, namespace = nil) -> XML::Node
|
265
|
+
*
|
266
|
+
* Creates a new element with the specified name, content and
|
267
|
+
* namespace. The content and namespace may be nil.
|
268
|
+
*/
|
269
|
+
static VALUE rxml_node_initialize(int argc, VALUE *argv, VALUE self)
|
270
|
+
{
|
271
|
+
VALUE name;
|
272
|
+
VALUE content;
|
273
|
+
VALUE ns;
|
274
|
+
xmlNodePtr xnode = NULL;
|
275
|
+
xmlNsPtr xns = NULL;
|
276
|
+
|
277
|
+
rb_scan_args(argc, argv, "12", &name, &content, &ns);
|
278
|
+
|
279
|
+
name = rb_obj_as_string(name);
|
280
|
+
|
281
|
+
if (!NIL_P(ns))
|
282
|
+
Data_Get_Struct(ns, xmlNs, xns);
|
283
|
+
|
284
|
+
xnode = xmlNewNode(xns, (xmlChar*) StringValuePtr(name));
|
285
|
+
|
286
|
+
if (xnode == NULL)
|
287
|
+
rxml_raise(&xmlLastError);
|
288
|
+
|
289
|
+
// Link the ruby wrapper to the underlying libxml node
|
290
|
+
RDATA(self)->data = xnode;
|
291
|
+
|
292
|
+
// Ruby is in charge of managing this node's memory
|
293
|
+
rxml_node_manage(xnode, self);
|
294
|
+
|
295
|
+
if (!NIL_P(content))
|
296
|
+
rxml_node_content_set(self, content);
|
297
|
+
|
298
|
+
return self;
|
299
|
+
}
|
300
|
+
|
301
|
+
static VALUE rxml_node_modify_dom(VALUE self, VALUE target,
|
302
|
+
xmlNodePtr (*xmlFunc)(xmlNodePtr, xmlNodePtr))
|
303
|
+
{
|
304
|
+
xmlNodePtr xnode, xtarget, xresult;
|
305
|
+
|
306
|
+
if (rb_obj_is_kind_of(target, cXMLNode) == Qfalse)
|
307
|
+
rb_raise(rb_eTypeError, "Must pass an XML::Node object");
|
308
|
+
|
309
|
+
xnode = rxml_get_xnode(self);
|
310
|
+
xtarget = rxml_get_xnode(target);
|
311
|
+
|
312
|
+
if (xtarget->doc != NULL && xtarget->doc != xnode->doc)
|
313
|
+
rb_raise(eXMLError, "Nodes belong to different documents. You must first import the node by calling LibXML::XML::Document.import");
|
314
|
+
|
315
|
+
xmlUnlinkNode(xtarget);
|
316
|
+
|
317
|
+
// Target is about to have a parent, so stop having ruby manage it.
|
318
|
+
rxml_node_unmanage(xtarget, target);
|
319
|
+
|
320
|
+
// This target node could be freed here and be replaced by a different node
|
321
|
+
xresult = xmlFunc(xnode, xtarget);
|
322
|
+
|
323
|
+
if (!xresult)
|
324
|
+
rxml_raise(&xmlLastError);
|
325
|
+
|
326
|
+
/* Assume the target was freed, we need to fix up the ruby object to point to the
|
327
|
+
newly returned node. */
|
328
|
+
RDATA(target)->data = xresult;
|
329
|
+
|
330
|
+
return target;
|
331
|
+
}
|
332
|
+
|
333
|
+
/*
|
334
|
+
* call-seq:
|
335
|
+
* node.base_uri -> "uri"
|
336
|
+
*
|
337
|
+
* Obtain this node's base URI.
|
338
|
+
*/
|
339
|
+
static VALUE rxml_node_base_uri_get(VALUE self)
|
340
|
+
{
|
341
|
+
xmlNodePtr xnode;
|
342
|
+
xmlChar* base_uri;
|
343
|
+
VALUE result = Qnil;
|
344
|
+
|
345
|
+
xnode = rxml_get_xnode(self);
|
346
|
+
|
347
|
+
if (xnode->doc == NULL)
|
348
|
+
return (result);
|
349
|
+
|
350
|
+
base_uri = xmlNodeGetBase(xnode->doc, xnode);
|
351
|
+
if (base_uri)
|
352
|
+
{
|
353
|
+
result = rxml_new_cstr( base_uri, NULL);
|
354
|
+
xmlFree(base_uri);
|
355
|
+
}
|
356
|
+
|
357
|
+
return (result);
|
358
|
+
}
|
359
|
+
|
360
|
+
// TODO node_base_set should support setting back to nil
|
361
|
+
|
362
|
+
/*
|
363
|
+
* call-seq:
|
364
|
+
* node.base_uri = "uri"
|
365
|
+
*
|
366
|
+
* Set this node's base URI.
|
367
|
+
*/
|
368
|
+
static VALUE rxml_node_base_uri_set(VALUE self, VALUE uri)
|
369
|
+
{
|
370
|
+
xmlNodePtr xnode;
|
371
|
+
|
372
|
+
Check_Type(uri, T_STRING);
|
373
|
+
xnode = rxml_get_xnode(self);
|
374
|
+
if (xnode->doc == NULL)
|
375
|
+
return (Qnil);
|
376
|
+
|
377
|
+
xmlNodeSetBase(xnode, (xmlChar*) StringValuePtr(uri));
|
378
|
+
return (Qtrue);
|
379
|
+
}
|
380
|
+
|
381
|
+
/*
|
382
|
+
* call-seq:
|
383
|
+
* node.content -> "string"
|
384
|
+
*
|
385
|
+
* Obtain this node's content as a string.
|
386
|
+
*/
|
387
|
+
static VALUE rxml_node_content_get(VALUE self)
|
388
|
+
{
|
389
|
+
xmlNodePtr xnode;
|
390
|
+
xmlChar *content;
|
391
|
+
VALUE result = Qnil;
|
392
|
+
|
393
|
+
xnode = rxml_get_xnode(self);
|
394
|
+
content = xmlNodeGetContent(xnode);
|
395
|
+
if (content)
|
396
|
+
{
|
397
|
+
result = rxml_new_cstr(content, NULL);
|
398
|
+
xmlFree(content);
|
399
|
+
}
|
400
|
+
|
401
|
+
return result;
|
402
|
+
}
|
403
|
+
|
404
|
+
/*
|
405
|
+
* call-seq:
|
406
|
+
* node.content = "string"
|
407
|
+
*
|
408
|
+
* Set this node's content to the specified string.
|
409
|
+
*/
|
410
|
+
static VALUE rxml_node_content_set(VALUE self, VALUE content)
|
411
|
+
{
|
412
|
+
xmlNodePtr xnode;
|
413
|
+
xmlChar* encoded_content;
|
414
|
+
|
415
|
+
Check_Type(content, T_STRING);
|
416
|
+
xnode = rxml_get_xnode(self);
|
417
|
+
encoded_content = xmlEncodeSpecialChars(xnode->doc, (xmlChar*) StringValuePtr(content));
|
418
|
+
xmlNodeSetContent(xnode, encoded_content);
|
419
|
+
xmlFree(encoded_content);
|
420
|
+
return (Qtrue);
|
421
|
+
}
|
422
|
+
|
423
|
+
/*
|
424
|
+
* call-seq:
|
425
|
+
* node.debug -> true|false
|
426
|
+
*
|
427
|
+
* Print libxml debugging information to stdout.
|
428
|
+
* Requires that libxml was compiled with debugging enabled.
|
429
|
+
*/
|
430
|
+
static VALUE rxml_node_debug(VALUE self)
|
431
|
+
{
|
432
|
+
#ifdef LIBXML_DEBUG_ENABLED
|
433
|
+
xmlNodePtr xnode;
|
434
|
+
xnode = rxml_get_xnode(self);
|
435
|
+
xmlDebugDumpNode(NULL, xnode, 2);
|
436
|
+
return Qtrue;
|
437
|
+
#else
|
438
|
+
rb_warn("libxml was compiled without debugging support.");
|
439
|
+
return Qfalse;
|
440
|
+
#endif
|
441
|
+
}
|
442
|
+
|
443
|
+
/*
|
444
|
+
* call-seq:
|
445
|
+
* node.first -> XML::Node
|
446
|
+
*
|
447
|
+
* Returns this node's first child node if any.
|
448
|
+
*/
|
449
|
+
static VALUE rxml_node_first_get(VALUE self)
|
450
|
+
{
|
451
|
+
xmlNodePtr xnode;
|
452
|
+
|
453
|
+
xnode = rxml_get_xnode(self);
|
454
|
+
|
455
|
+
if (xnode->children)
|
456
|
+
return (rxml_node_wrap(xnode->children));
|
457
|
+
else
|
458
|
+
return (Qnil);
|
459
|
+
}
|
460
|
+
|
461
|
+
|
462
|
+
/*
|
463
|
+
* call-seq:
|
464
|
+
* curr_node << "Some text"
|
465
|
+
* curr_node << node
|
466
|
+
*
|
467
|
+
* Add the specified text or XML::Node as a new child node to the
|
468
|
+
* current node.
|
469
|
+
*
|
470
|
+
* If the specified argument is a string, it should be a raw string
|
471
|
+
* that contains unescaped XML special characters. Entity references
|
472
|
+
* are not supported.
|
473
|
+
*
|
474
|
+
* The method will return the current node.
|
475
|
+
*/
|
476
|
+
static VALUE rxml_node_content_add(VALUE self, VALUE obj)
|
477
|
+
{
|
478
|
+
xmlNodePtr xnode;
|
479
|
+
VALUE str;
|
480
|
+
|
481
|
+
xnode = rxml_get_xnode(self);
|
482
|
+
|
483
|
+
/* XXX This should only be legal for a CDATA type node, I think,
|
484
|
+
* resulting in a merge of content, as if a string were passed
|
485
|
+
* danj 070827
|
486
|
+
*/
|
487
|
+
if (rb_obj_is_kind_of(obj, cXMLNode))
|
488
|
+
{
|
489
|
+
rxml_node_modify_dom(self, obj, xmlAddChild);
|
490
|
+
}
|
491
|
+
else
|
492
|
+
{
|
493
|
+
str = rb_obj_as_string(obj);
|
494
|
+
if (NIL_P(str) || TYPE(str) != T_STRING)
|
495
|
+
rb_raise(rb_eTypeError, "invalid argument: must be string or XML::Node");
|
496
|
+
|
497
|
+
xmlNodeAddContent(xnode, (xmlChar*) StringValuePtr(str));
|
498
|
+
}
|
499
|
+
return self;
|
500
|
+
}
|
501
|
+
|
502
|
+
/*
|
503
|
+
* call-seq:
|
504
|
+
* node.doc -> document
|
505
|
+
*
|
506
|
+
* Obtain the XML::Document this node belongs to.
|
507
|
+
*/
|
508
|
+
static VALUE rxml_node_doc(VALUE self)
|
509
|
+
{
|
510
|
+
xmlDocPtr xdoc = NULL;
|
511
|
+
xmlNodePtr xnode = rxml_get_xnode(self);
|
512
|
+
|
513
|
+
switch (xnode->type)
|
514
|
+
{
|
515
|
+
case XML_DOCUMENT_NODE:
|
516
|
+
#ifdef LIBXML_DOCB_ENABLED
|
517
|
+
case XML_DOCB_DOCUMENT_NODE:
|
518
|
+
#endif
|
519
|
+
case XML_HTML_DOCUMENT_NODE:
|
520
|
+
case XML_NAMESPACE_DECL:
|
521
|
+
break;
|
522
|
+
case XML_ATTRIBUTE_NODE:
|
523
|
+
xdoc = (xmlDocPtr)((xmlAttrPtr) xnode->doc);
|
524
|
+
break;
|
525
|
+
default:
|
526
|
+
xdoc = xnode->doc;
|
527
|
+
}
|
528
|
+
|
529
|
+
if (xdoc == NULL)
|
530
|
+
return (Qnil);
|
531
|
+
|
532
|
+
return (VALUE)xdoc->_private;
|
533
|
+
}
|
534
|
+
|
535
|
+
/*
|
536
|
+
* call-seq:
|
537
|
+
* node.to_s -> "string"
|
538
|
+
* node.to_s(:indent => true, :encoding => 'UTF-8', :level => 0) -> "string"
|
539
|
+
*
|
540
|
+
* Converts a node, and all of its children, to a string representation.
|
541
|
+
* To include only the node's children, use the the XML::Node#inner_xml
|
542
|
+
* method.
|
543
|
+
*
|
544
|
+
* You may provide an optional hash table to control how the string is
|
545
|
+
* generated. Valid options are:
|
546
|
+
*
|
547
|
+
* :indent - Specifies if the string should be indented. The default value
|
548
|
+
* is true. Note that indentation is only added if both :indent is
|
549
|
+
* true and XML.indent_tree_output is true. If :indent is set to false,
|
550
|
+
* then both indentation and line feeds are removed from the result.
|
551
|
+
*
|
552
|
+
* :level - Specifies the indentation level. The amount of indentation
|
553
|
+
* is equal to the (level * number_spaces) + number_spaces, where libxml
|
554
|
+
* defaults the number of spaces to 2. Thus a level of 0 results in
|
555
|
+
* 2 spaces, level 1 results in 4 spaces, level 2 results in 6 spaces, etc.
|
556
|
+
*
|
557
|
+
* :encoding - Specifies the output encoding of the string. It
|
558
|
+
* defaults to XML::Encoding::UTF8. To change it, use one of the
|
559
|
+
* XML::Encoding encoding constants. */
|
560
|
+
|
561
|
+
static VALUE rxml_node_to_s(int argc, VALUE *argv, VALUE self)
|
562
|
+
{
|
563
|
+
VALUE result = Qnil;
|
564
|
+
VALUE options = Qnil;
|
565
|
+
xmlNodePtr xnode;
|
566
|
+
xmlCharEncodingHandlerPtr encodingHandler;
|
567
|
+
xmlOutputBufferPtr output;
|
568
|
+
|
569
|
+
int level = 0;
|
570
|
+
int indent = 1;
|
571
|
+
const xmlChar *xencoding = (const xmlChar*)"UTF-8";
|
572
|
+
|
573
|
+
rb_scan_args(argc, argv, "01", &options);
|
574
|
+
|
575
|
+
if (!NIL_P(options))
|
576
|
+
{
|
577
|
+
VALUE rencoding, rindent, rlevel;
|
578
|
+
Check_Type(options, T_HASH);
|
579
|
+
rencoding = rb_hash_aref(options, ID2SYM(rb_intern("encoding")));
|
580
|
+
rindent = rb_hash_aref(options, ID2SYM(rb_intern("indent")));
|
581
|
+
rlevel = rb_hash_aref(options, ID2SYM(rb_intern("level")));
|
582
|
+
|
583
|
+
if (rindent == Qfalse)
|
584
|
+
indent = 0;
|
585
|
+
|
586
|
+
if (rlevel != Qnil)
|
587
|
+
level = NUM2INT(rlevel);
|
588
|
+
|
589
|
+
if (rencoding != Qnil)
|
590
|
+
{
|
591
|
+
xencoding = (const xmlChar*)xmlGetCharEncodingName((xmlCharEncoding)NUM2INT(rencoding));
|
592
|
+
if (!xencoding)
|
593
|
+
rb_raise(rb_eArgError, "Unknown encoding value: %d", NUM2INT(rencoding));
|
594
|
+
}
|
595
|
+
}
|
596
|
+
|
597
|
+
encodingHandler = xmlFindCharEncodingHandler((const char*)xencoding);
|
598
|
+
output = xmlAllocOutputBuffer(encodingHandler);
|
599
|
+
|
600
|
+
xnode = rxml_get_xnode(self);
|
601
|
+
|
602
|
+
xmlNodeDumpOutput(output, xnode->doc, xnode, level, indent, (const char*)xencoding);
|
603
|
+
xmlOutputBufferFlush(output);
|
604
|
+
|
605
|
+
#ifdef LIBXML2_NEW_BUFFER
|
606
|
+
if (output->conv)
|
607
|
+
result = rxml_new_cstr(xmlBufContent(output->conv), xencoding);
|
608
|
+
else
|
609
|
+
result = rxml_new_cstr(xmlBufContent(output->buffer), xencoding);
|
610
|
+
#else
|
611
|
+
if (output->conv)
|
612
|
+
result = rxml_new_cstr(xmlBufferContent(output->conv), xencoding);
|
613
|
+
else
|
614
|
+
result = rxml_new_cstr(xmlBufferContent(output->buffer), xencoding);
|
615
|
+
#endif
|
616
|
+
|
617
|
+
xmlOutputBufferClose(output);
|
618
|
+
|
619
|
+
return result;
|
620
|
+
}
|
621
|
+
|
622
|
+
|
623
|
+
/*
|
624
|
+
* call-seq:
|
625
|
+
* node.each -> XML::Node
|
626
|
+
*
|
627
|
+
* Iterates over this node's children, including text
|
628
|
+
* nodes, element nodes, etc. If you wish to iterate
|
629
|
+
* only over child elements, use XML::Node#each_element.
|
630
|
+
*
|
631
|
+
* doc = XML::Document.new('model/books.xml')
|
632
|
+
* doc.root.each {|node| puts node}
|
633
|
+
*/
|
634
|
+
static VALUE rxml_node_each(VALUE self)
|
635
|
+
{
|
636
|
+
xmlNodePtr xnode;
|
637
|
+
xmlNodePtr xcurrent;
|
638
|
+
xnode = rxml_get_xnode(self);
|
639
|
+
|
640
|
+
xcurrent = xnode->children;
|
641
|
+
|
642
|
+
while (xcurrent)
|
643
|
+
{
|
644
|
+
/* The user could remove this node, so first stache
|
645
|
+
away the next node. */
|
646
|
+
xmlNodePtr xnext = xcurrent->next;
|
647
|
+
|
648
|
+
rb_yield(rxml_node_wrap(xcurrent));
|
649
|
+
xcurrent = xnext;
|
650
|
+
}
|
651
|
+
return Qnil;
|
652
|
+
}
|
653
|
+
|
654
|
+
/*
|
655
|
+
* call-seq:
|
656
|
+
* node.empty? -> (true|false)
|
657
|
+
*
|
658
|
+
* Determine whether this node is an empty or whitespace only text-node.
|
659
|
+
*/
|
660
|
+
static VALUE rxml_node_empty_q(VALUE self)
|
661
|
+
{
|
662
|
+
xmlNodePtr xnode;
|
663
|
+
xnode = rxml_get_xnode(self);
|
664
|
+
if (xnode == NULL)
|
665
|
+
return (Qnil);
|
666
|
+
|
667
|
+
return ((xmlIsBlankNode(xnode) == 1) ? Qtrue : Qfalse);
|
668
|
+
}
|
669
|
+
|
670
|
+
|
671
|
+
/*
|
672
|
+
* call-seq:
|
673
|
+
* node.eql?(other_node) => (true|false)
|
674
|
+
*
|
675
|
+
* Test equality between the two nodes. Two nodes are equal
|
676
|
+
* if they are the same node.*/
|
677
|
+
static VALUE rxml_node_eql_q(VALUE self, VALUE other)
|
678
|
+
{
|
679
|
+
if (self == other)
|
680
|
+
{
|
681
|
+
return Qtrue;
|
682
|
+
}
|
683
|
+
else if (NIL_P(other))
|
684
|
+
{
|
685
|
+
return Qfalse;
|
686
|
+
}
|
687
|
+
else
|
688
|
+
{
|
689
|
+
xmlNodePtr xnode = rxml_get_xnode(self);
|
690
|
+
xmlNodePtr xnode_other = rxml_get_xnode(other);
|
691
|
+
return xnode == xnode_other ? Qtrue : Qfalse;
|
692
|
+
}
|
693
|
+
}
|
694
|
+
|
695
|
+
/*
|
696
|
+
* call-seq:
|
697
|
+
* node.lang -> "string"
|
698
|
+
*
|
699
|
+
* Obtain the language set for this node, if any.
|
700
|
+
* This is set in XML via the xml:lang attribute.
|
701
|
+
*/
|
702
|
+
static VALUE rxml_node_lang_get(VALUE self)
|
703
|
+
{
|
704
|
+
xmlNodePtr xnode;
|
705
|
+
xmlChar *lang;
|
706
|
+
VALUE result = Qnil;
|
707
|
+
|
708
|
+
xnode = rxml_get_xnode(self);
|
709
|
+
lang = xmlNodeGetLang(xnode);
|
710
|
+
|
711
|
+
if (lang)
|
712
|
+
{
|
713
|
+
result = rxml_new_cstr( lang, NULL);
|
714
|
+
xmlFree(lang);
|
715
|
+
}
|
716
|
+
|
717
|
+
return (result);
|
718
|
+
}
|
719
|
+
|
720
|
+
// TODO node_lang_set should support setting back to nil
|
721
|
+
|
722
|
+
/*
|
723
|
+
* call-seq:
|
724
|
+
* node.lang = "string"
|
725
|
+
*
|
726
|
+
* Set the language for this node. This affects the value
|
727
|
+
* of the xml:lang attribute.
|
728
|
+
*/
|
729
|
+
static VALUE rxml_node_lang_set(VALUE self, VALUE lang)
|
730
|
+
{
|
731
|
+
xmlNodePtr xnode;
|
732
|
+
|
733
|
+
Check_Type(lang, T_STRING);
|
734
|
+
xnode = rxml_get_xnode(self);
|
735
|
+
xmlNodeSetLang(xnode, (xmlChar*) StringValuePtr(lang));
|
736
|
+
|
737
|
+
return (Qtrue);
|
738
|
+
}
|
739
|
+
|
740
|
+
/*
|
741
|
+
* call-seq:
|
742
|
+
* node.last -> XML::Node
|
743
|
+
*
|
744
|
+
* Obtain the last child node of this node, if any.
|
745
|
+
*/
|
746
|
+
static VALUE rxml_node_last_get(VALUE self)
|
747
|
+
{
|
748
|
+
xmlNodePtr xnode;
|
749
|
+
|
750
|
+
xnode = rxml_get_xnode(self);
|
751
|
+
|
752
|
+
if (xnode->last)
|
753
|
+
return (rxml_node_wrap(xnode->last));
|
754
|
+
else
|
755
|
+
return (Qnil);
|
756
|
+
}
|
757
|
+
|
758
|
+
/*
|
759
|
+
* call-seq:
|
760
|
+
* node.line_num -> num
|
761
|
+
*
|
762
|
+
* Obtain the line number (in the XML document) that this
|
763
|
+
* node was read from. If +default_line_numbers+ is set
|
764
|
+
* false (the default), this method returns zero.
|
765
|
+
*/
|
766
|
+
static VALUE rxml_node_line_num(VALUE self)
|
767
|
+
{
|
768
|
+
xmlNodePtr xnode;
|
769
|
+
long line_num;
|
770
|
+
xnode = rxml_get_xnode(self);
|
771
|
+
|
772
|
+
if (!xmlLineNumbersDefaultValue)
|
773
|
+
rb_warn(
|
774
|
+
"Line numbers were not retained: use XML::Parser::default_line_numbers=true");
|
775
|
+
|
776
|
+
line_num = xmlGetLineNo(xnode);
|
777
|
+
if (line_num == -1)
|
778
|
+
return (Qnil);
|
779
|
+
else
|
780
|
+
return (INT2NUM((long) line_num));
|
781
|
+
}
|
782
|
+
|
783
|
+
/*
|
784
|
+
* call-seq:
|
785
|
+
* node.xlink? -> (true|false)
|
786
|
+
*
|
787
|
+
* Determine whether this node is an xlink node.
|
788
|
+
*/
|
789
|
+
static VALUE rxml_node_xlink_q(VALUE self)
|
790
|
+
{
|
791
|
+
xmlNodePtr xnode;
|
792
|
+
xlinkType xlt;
|
793
|
+
|
794
|
+
xnode = rxml_get_xnode(self);
|
795
|
+
xlt = xlinkIsLink(xnode->doc, xnode);
|
796
|
+
|
797
|
+
if (xlt == XLINK_TYPE_NONE)
|
798
|
+
return (Qfalse);
|
799
|
+
else
|
800
|
+
return (Qtrue);
|
801
|
+
}
|
802
|
+
|
803
|
+
/*
|
804
|
+
* call-seq:
|
805
|
+
* node.xlink_type -> num
|
806
|
+
*
|
807
|
+
* Obtain the type identifier for this xlink, if applicable.
|
808
|
+
* If this is not an xlink node (see +xlink?+), will return
|
809
|
+
* nil.
|
810
|
+
*/
|
811
|
+
static VALUE rxml_node_xlink_type(VALUE self)
|
812
|
+
{
|
813
|
+
xmlNodePtr xnode;
|
814
|
+
xlinkType xlt;
|
815
|
+
|
816
|
+
xnode = rxml_get_xnode(self);
|
817
|
+
xlt = xlinkIsLink(xnode->doc, xnode);
|
818
|
+
|
819
|
+
if (xlt == XLINK_TYPE_NONE)
|
820
|
+
return (Qnil);
|
821
|
+
else
|
822
|
+
return (INT2NUM(xlt));
|
823
|
+
}
|
824
|
+
|
825
|
+
/*
|
826
|
+
* call-seq:
|
827
|
+
* node.xlink_type_name -> "string"
|
828
|
+
*
|
829
|
+
* Obtain the type name for this xlink, if applicable.
|
830
|
+
* If this is not an xlink node (see +xlink?+), will return
|
831
|
+
* nil.
|
832
|
+
*/
|
833
|
+
static VALUE rxml_node_xlink_type_name(VALUE self)
|
834
|
+
{
|
835
|
+
xmlNodePtr xnode;
|
836
|
+
xlinkType xlt;
|
837
|
+
|
838
|
+
xnode = rxml_get_xnode(self);
|
839
|
+
xlt = xlinkIsLink(xnode->doc, xnode);
|
840
|
+
|
841
|
+
switch (xlt)
|
842
|
+
{
|
843
|
+
case XLINK_TYPE_NONE:
|
844
|
+
return (Qnil);
|
845
|
+
case XLINK_TYPE_SIMPLE:
|
846
|
+
return (rxml_new_cstr((const xmlChar*)"simple", NULL));
|
847
|
+
case XLINK_TYPE_EXTENDED:
|
848
|
+
return (rxml_new_cstr((const xmlChar*)"extended", NULL));
|
849
|
+
case XLINK_TYPE_EXTENDED_SET:
|
850
|
+
return (rxml_new_cstr((const xmlChar*)"extended_set", NULL));
|
851
|
+
default:
|
852
|
+
rb_fatal("Unknowng xlink type, %d", xlt);
|
853
|
+
}
|
854
|
+
}
|
855
|
+
|
856
|
+
/*
|
857
|
+
* call-seq:
|
858
|
+
* node.name -> "string"
|
859
|
+
*
|
860
|
+
* Obtain this node's name.
|
861
|
+
*/
|
862
|
+
static VALUE rxml_node_name_get(VALUE self)
|
863
|
+
{
|
864
|
+
xmlNodePtr xnode;
|
865
|
+
const xmlChar *name;
|
866
|
+
|
867
|
+
xnode = rxml_get_xnode(self);
|
868
|
+
|
869
|
+
switch (xnode->type)
|
870
|
+
{
|
871
|
+
case XML_DOCUMENT_NODE:
|
872
|
+
#ifdef LIBXML_DOCB_ENABLED
|
873
|
+
case XML_DOCB_DOCUMENT_NODE:
|
874
|
+
#endif
|
875
|
+
case XML_HTML_DOCUMENT_NODE:
|
876
|
+
{
|
877
|
+
xmlDocPtr doc = (xmlDocPtr) xnode;
|
878
|
+
name = doc->URL;
|
879
|
+
break;
|
880
|
+
}
|
881
|
+
case XML_ATTRIBUTE_NODE:
|
882
|
+
{
|
883
|
+
xmlAttrPtr attr = (xmlAttrPtr) xnode;
|
884
|
+
name = attr->name;
|
885
|
+
break;
|
886
|
+
}
|
887
|
+
case XML_NAMESPACE_DECL:
|
888
|
+
{
|
889
|
+
xmlNsPtr ns = (xmlNsPtr) xnode;
|
890
|
+
name = ns->prefix;
|
891
|
+
break;
|
892
|
+
}
|
893
|
+
default:
|
894
|
+
name = xnode->name;
|
895
|
+
break;
|
896
|
+
}
|
897
|
+
|
898
|
+
if (xnode->name == NULL)
|
899
|
+
return (Qnil);
|
900
|
+
else
|
901
|
+
return (rxml_new_cstr( name, NULL));
|
902
|
+
}
|
903
|
+
|
904
|
+
/*
|
905
|
+
* call-seq:
|
906
|
+
* node.name = "string"
|
907
|
+
*
|
908
|
+
* Set this node's name.
|
909
|
+
*/
|
910
|
+
static VALUE rxml_node_name_set(VALUE self, VALUE name)
|
911
|
+
{
|
912
|
+
xmlNodePtr xnode;
|
913
|
+
const xmlChar *xname;
|
914
|
+
|
915
|
+
Check_Type(name, T_STRING);
|
916
|
+
xnode = rxml_get_xnode(self);
|
917
|
+
xname = (const xmlChar*)StringValuePtr(name);
|
918
|
+
|
919
|
+
/* Note: calling xmlNodeSetName() for a text node is ignored by libXML. */
|
920
|
+
xmlNodeSetName(xnode, xname);
|
921
|
+
|
922
|
+
return (Qtrue);
|
923
|
+
}
|
924
|
+
|
925
|
+
/*
|
926
|
+
* call-seq:
|
927
|
+
* node.next -> XML::Node
|
928
|
+
*
|
929
|
+
* Returns the next sibling node if one exists.
|
930
|
+
*/
|
931
|
+
static VALUE rxml_node_next_get(VALUE self)
|
932
|
+
{
|
933
|
+
xmlNodePtr xnode;
|
934
|
+
|
935
|
+
xnode = rxml_get_xnode(self);
|
936
|
+
|
937
|
+
if (xnode->next)
|
938
|
+
return (rxml_node_wrap(xnode->next));
|
939
|
+
else
|
940
|
+
return (Qnil);
|
941
|
+
}
|
942
|
+
|
943
|
+
/*
|
944
|
+
* call-seq:
|
945
|
+
* curr_node.next = node
|
946
|
+
*
|
947
|
+
* Adds the specified node as the next sibling of the current node.
|
948
|
+
* If the node already exists in the document, it is first removed
|
949
|
+
* from its existing context. Any adjacent text nodes will be
|
950
|
+
* merged together, meaning the returned node may be different
|
951
|
+
* than the original node.
|
952
|
+
*/
|
953
|
+
static VALUE rxml_node_next_set(VALUE self, VALUE next)
|
954
|
+
{
|
955
|
+
return rxml_node_modify_dom(self, next, xmlAddNextSibling);
|
956
|
+
}
|
957
|
+
|
958
|
+
/*
|
959
|
+
* call-seq:
|
960
|
+
* node.parent -> XML::Node
|
961
|
+
*
|
962
|
+
* Obtain this node's parent node, if any.
|
963
|
+
*/
|
964
|
+
static VALUE rxml_node_parent_get(VALUE self)
|
965
|
+
{
|
966
|
+
xmlNodePtr xnode;
|
967
|
+
|
968
|
+
xnode = rxml_get_xnode(self);
|
969
|
+
|
970
|
+
if (xnode->parent)
|
971
|
+
return (rxml_node_wrap(xnode->parent));
|
972
|
+
else
|
973
|
+
return (Qnil);
|
974
|
+
}
|
975
|
+
|
976
|
+
/*
|
977
|
+
* call-seq:
|
978
|
+
* node.path -> path
|
979
|
+
*
|
980
|
+
* Obtain this node's path.
|
981
|
+
*/
|
982
|
+
static VALUE rxml_node_path(VALUE self)
|
983
|
+
{
|
984
|
+
xmlNodePtr xnode;
|
985
|
+
xmlChar *path;
|
986
|
+
|
987
|
+
xnode = rxml_get_xnode(self);
|
988
|
+
path = xmlGetNodePath(xnode);
|
989
|
+
|
990
|
+
if (path == NULL)
|
991
|
+
return (Qnil);
|
992
|
+
else
|
993
|
+
return (rxml_new_cstr( path, NULL));
|
994
|
+
}
|
995
|
+
|
996
|
+
/*
|
997
|
+
* call-seq:
|
998
|
+
* node.pointer -> XML::NodeSet
|
999
|
+
*
|
1000
|
+
* Evaluates an XPointer expression relative to this node.
|
1001
|
+
*/
|
1002
|
+
static VALUE rxml_node_pointer(VALUE self, VALUE xptr_str)
|
1003
|
+
{
|
1004
|
+
return (rxml_xpointer_point2(self, xptr_str));
|
1005
|
+
}
|
1006
|
+
|
1007
|
+
/*
|
1008
|
+
* call-seq:
|
1009
|
+
* node.prev -> XML::Node
|
1010
|
+
*
|
1011
|
+
* Obtain the previous sibling, if any.
|
1012
|
+
*/
|
1013
|
+
static VALUE rxml_node_prev_get(VALUE self)
|
1014
|
+
{
|
1015
|
+
xmlNodePtr xnode;
|
1016
|
+
xmlNodePtr node;
|
1017
|
+
xnode = rxml_get_xnode(self);
|
1018
|
+
|
1019
|
+
switch (xnode->type)
|
1020
|
+
{
|
1021
|
+
case XML_DOCUMENT_NODE:
|
1022
|
+
#ifdef LIBXML_DOCB_ENABLED
|
1023
|
+
case XML_DOCB_DOCUMENT_NODE:
|
1024
|
+
#endif
|
1025
|
+
case XML_HTML_DOCUMENT_NODE:
|
1026
|
+
case XML_NAMESPACE_DECL:
|
1027
|
+
node = NULL;
|
1028
|
+
break;
|
1029
|
+
case XML_ATTRIBUTE_NODE:
|
1030
|
+
{
|
1031
|
+
xmlAttrPtr attr = (xmlAttrPtr) xnode;
|
1032
|
+
node = (xmlNodePtr) attr->prev;
|
1033
|
+
}
|
1034
|
+
break;
|
1035
|
+
default:
|
1036
|
+
node = xnode->prev;
|
1037
|
+
break;
|
1038
|
+
}
|
1039
|
+
|
1040
|
+
if (node == NULL)
|
1041
|
+
return (Qnil);
|
1042
|
+
else
|
1043
|
+
return (rxml_node_wrap(node));
|
1044
|
+
}
|
1045
|
+
|
1046
|
+
/*
|
1047
|
+
* call-seq:
|
1048
|
+
* curr_node.prev = node
|
1049
|
+
*
|
1050
|
+
* Adds the specified node as the previous sibling of the current node.
|
1051
|
+
* If the node already exists in the document, it is first removed
|
1052
|
+
* from its existing context. Any adjacent text nodes will be
|
1053
|
+
* merged together, meaning the returned node may be different
|
1054
|
+
* than the original node.
|
1055
|
+
*/
|
1056
|
+
static VALUE rxml_node_prev_set(VALUE self, VALUE prev)
|
1057
|
+
{
|
1058
|
+
return rxml_node_modify_dom(self, prev, xmlAddPrevSibling);
|
1059
|
+
}
|
1060
|
+
|
1061
|
+
/*
|
1062
|
+
* call-seq:
|
1063
|
+
* node.attributes -> attributes
|
1064
|
+
*
|
1065
|
+
* Returns the XML::Attributes for this node.
|
1066
|
+
*/
|
1067
|
+
static VALUE rxml_node_attributes_get(VALUE self)
|
1068
|
+
{
|
1069
|
+
xmlNodePtr xnode;
|
1070
|
+
|
1071
|
+
xnode = rxml_get_xnode(self);
|
1072
|
+
return rxml_attributes_new(xnode);
|
1073
|
+
}
|
1074
|
+
|
1075
|
+
/*
|
1076
|
+
* call-seq:
|
1077
|
+
* node.property("name") -> "string"
|
1078
|
+
* node["name"] -> "string"
|
1079
|
+
*
|
1080
|
+
* Obtain the named property.
|
1081
|
+
*/
|
1082
|
+
static VALUE rxml_node_attribute_get(VALUE self, VALUE name)
|
1083
|
+
{
|
1084
|
+
VALUE attributes = rxml_node_attributes_get(self);
|
1085
|
+
return rxml_attributes_attribute_get(attributes, name);
|
1086
|
+
}
|
1087
|
+
|
1088
|
+
/*
|
1089
|
+
* call-seq:
|
1090
|
+
* node["name"] = "string"
|
1091
|
+
*
|
1092
|
+
* Set the named property.
|
1093
|
+
*/
|
1094
|
+
static VALUE rxml_node_property_set(VALUE self, VALUE name, VALUE value)
|
1095
|
+
{
|
1096
|
+
VALUE attributes = rxml_node_attributes_get(self);
|
1097
|
+
return rxml_attributes_attribute_set(attributes, name, value);
|
1098
|
+
}
|
1099
|
+
|
1100
|
+
/*
|
1101
|
+
* call-seq:
|
1102
|
+
* node.remove! -> node
|
1103
|
+
*
|
1104
|
+
* Removes this node and its children from the document tree by setting its document,
|
1105
|
+
* parent and siblings to nil. You can add the returned node back into a document.
|
1106
|
+
* Otherwise, the node will be freed once any references to it go out of scope.
|
1107
|
+
*/
|
1108
|
+
|
1109
|
+
static VALUE rxml_node_remove_ex(VALUE self)
|
1110
|
+
{
|
1111
|
+
xmlNodePtr xnode = rxml_get_xnode(self);
|
1112
|
+
|
1113
|
+
// Now unlink the node from its parent
|
1114
|
+
xmlUnlinkNode(xnode);
|
1115
|
+
|
1116
|
+
// Ruby now manages this node
|
1117
|
+
rxml_node_manage(xnode, self);
|
1118
|
+
|
1119
|
+
// Now return the removed node so the user can do something with it
|
1120
|
+
return self;
|
1121
|
+
}
|
1122
|
+
|
1123
|
+
/*
|
1124
|
+
* call-seq:
|
1125
|
+
* curr_node.sibling = node
|
1126
|
+
*
|
1127
|
+
* Adds the specified node as the end of the current node's list
|
1128
|
+
* of siblings. If the node already exists in the document, it
|
1129
|
+
* is first removed from its existing context. Any adjacent text
|
1130
|
+
* nodes will be merged together, meaning the returned node may
|
1131
|
+
* be different than the original node.
|
1132
|
+
*/
|
1133
|
+
static VALUE rxml_node_sibling_set(VALUE self, VALUE sibling)
|
1134
|
+
{
|
1135
|
+
return rxml_node_modify_dom(self, sibling, xmlAddSibling);
|
1136
|
+
}
|
1137
|
+
|
1138
|
+
/*
|
1139
|
+
* call-seq:
|
1140
|
+
* text_node.output_escaping? -> (true|false)
|
1141
|
+
* element_node.output_escaping? -> (true|false|nil)
|
1142
|
+
* attribute_node.output_escaping? -> (true|false|nil)
|
1143
|
+
* other_node.output_escaping? -> (nil)
|
1144
|
+
*
|
1145
|
+
* Determine whether this node escapes it's output or not.
|
1146
|
+
*
|
1147
|
+
* Text nodes return only +true+ or +false+. Element and attribute nodes
|
1148
|
+
* examine their immediate text node children to determine the value.
|
1149
|
+
* Any other type of node always returns +nil+.
|
1150
|
+
*
|
1151
|
+
* If an element or attribute node has at least one immediate child text node
|
1152
|
+
* and all the immediate text node children have the same +output_escaping?+
|
1153
|
+
* value, that value is returned. Otherwise, +nil+ is returned.
|
1154
|
+
*/
|
1155
|
+
static VALUE rxml_node_output_escaping_q(VALUE self)
|
1156
|
+
{
|
1157
|
+
xmlNodePtr xnode;
|
1158
|
+
xnode = rxml_get_xnode(self);
|
1159
|
+
|
1160
|
+
switch (xnode->type) {
|
1161
|
+
case XML_TEXT_NODE:
|
1162
|
+
return xnode->name==xmlStringTextNoenc ? Qfalse : Qtrue;
|
1163
|
+
case XML_ELEMENT_NODE:
|
1164
|
+
case XML_ATTRIBUTE_NODE:
|
1165
|
+
{
|
1166
|
+
xmlNodePtr tmp = xnode->children;
|
1167
|
+
const xmlChar *match = NULL;
|
1168
|
+
|
1169
|
+
/* Find the first text node and use it as the reference. */
|
1170
|
+
while (tmp && tmp->type != XML_TEXT_NODE)
|
1171
|
+
tmp = tmp->next;
|
1172
|
+
if (! tmp)
|
1173
|
+
return Qnil;
|
1174
|
+
match = tmp->name;
|
1175
|
+
|
1176
|
+
/* Walk the remaining text nodes until we run out or one doesn't match. */
|
1177
|
+
while (tmp && (tmp->type != XML_TEXT_NODE || match == tmp->name))
|
1178
|
+
tmp = tmp->next;
|
1179
|
+
|
1180
|
+
/* We're left with either the mismatched node or the aggregate result. */
|
1181
|
+
return tmp ? Qnil : (match==xmlStringTextNoenc ? Qfalse : Qtrue);
|
1182
|
+
}
|
1183
|
+
break;
|
1184
|
+
default:
|
1185
|
+
return Qnil;
|
1186
|
+
}
|
1187
|
+
}
|
1188
|
+
|
1189
|
+
/*
|
1190
|
+
* call-seq:
|
1191
|
+
* text_node.output_escaping = true|false
|
1192
|
+
* element_node.output_escaping = true|false
|
1193
|
+
* attribute_node.output_escaping = true|false
|
1194
|
+
*
|
1195
|
+
* Controls whether this text node or the immediate text node children of an
|
1196
|
+
* element or attribute node escapes their output. Any other type of node
|
1197
|
+
* will simply ignore this operation.
|
1198
|
+
*
|
1199
|
+
* Text nodes which are added to an element or attribute node will be affected
|
1200
|
+
* by any previous setting of this property.
|
1201
|
+
*/
|
1202
|
+
static VALUE rxml_node_output_escaping_set(VALUE self, VALUE value)
|
1203
|
+
{
|
1204
|
+
xmlNodePtr xnode;
|
1205
|
+
xnode = rxml_get_xnode(self);
|
1206
|
+
|
1207
|
+
switch (xnode->type) {
|
1208
|
+
case XML_TEXT_NODE:
|
1209
|
+
xnode->name = (value != Qfalse && value != Qnil) ? xmlStringText : xmlStringTextNoenc;
|
1210
|
+
break;
|
1211
|
+
case XML_ELEMENT_NODE:
|
1212
|
+
case XML_ATTRIBUTE_NODE:
|
1213
|
+
{
|
1214
|
+
const xmlChar *name = (value != Qfalse && value != Qnil) ? xmlStringText : xmlStringTextNoenc;
|
1215
|
+
xmlNodePtr tmp;
|
1216
|
+
for (tmp = xnode->children; tmp; tmp = tmp->next)
|
1217
|
+
if (tmp->type == XML_TEXT_NODE)
|
1218
|
+
tmp->name = name;
|
1219
|
+
}
|
1220
|
+
break;
|
1221
|
+
default:
|
1222
|
+
return Qnil;
|
1223
|
+
}
|
1224
|
+
|
1225
|
+
return (value!=Qfalse && value!=Qnil) ? Qtrue : Qfalse;
|
1226
|
+
}
|
1227
|
+
|
1228
|
+
/*
|
1229
|
+
* call-seq:
|
1230
|
+
* node.space_preserve -> (true|false)
|
1231
|
+
*
|
1232
|
+
* Determine whether this node preserves whitespace.
|
1233
|
+
*/
|
1234
|
+
static VALUE rxml_node_space_preserve_get(VALUE self)
|
1235
|
+
{
|
1236
|
+
xmlNodePtr xnode;
|
1237
|
+
|
1238
|
+
xnode = rxml_get_xnode(self);
|
1239
|
+
return (INT2NUM(xmlNodeGetSpacePreserve(xnode)));
|
1240
|
+
}
|
1241
|
+
|
1242
|
+
/*
|
1243
|
+
* call-seq:
|
1244
|
+
* node.space_preserve = true|false
|
1245
|
+
*
|
1246
|
+
* Control whether this node preserves whitespace.
|
1247
|
+
*/
|
1248
|
+
static VALUE rxml_node_space_preserve_set(VALUE self, VALUE value)
|
1249
|
+
{
|
1250
|
+
xmlNodePtr xnode;
|
1251
|
+
xnode = rxml_get_xnode(self);
|
1252
|
+
|
1253
|
+
if (value == Qfalse)
|
1254
|
+
xmlNodeSetSpacePreserve(xnode, 0);
|
1255
|
+
else
|
1256
|
+
xmlNodeSetSpacePreserve(xnode, 1);
|
1257
|
+
|
1258
|
+
return (Qnil);
|
1259
|
+
}
|
1260
|
+
|
1261
|
+
/*
|
1262
|
+
* call-seq:
|
1263
|
+
* node.type -> num
|
1264
|
+
*
|
1265
|
+
* Obtain this node's type identifier.
|
1266
|
+
*/
|
1267
|
+
static VALUE rxml_node_type(VALUE self)
|
1268
|
+
{
|
1269
|
+
xmlNodePtr xnode;
|
1270
|
+
xnode = rxml_get_xnode(self);
|
1271
|
+
return (INT2NUM(xnode->type));
|
1272
|
+
}
|
1273
|
+
|
1274
|
+
/*
|
1275
|
+
* call-seq:
|
1276
|
+
* node.copy -> XML::Node
|
1277
|
+
*
|
1278
|
+
* Creates a copy of this node. To create a
|
1279
|
+
* shallow copy set the deep parameter to false.
|
1280
|
+
* To create a deep copy set the deep parameter
|
1281
|
+
* to true.
|
1282
|
+
*
|
1283
|
+
*/
|
1284
|
+
static VALUE rxml_node_copy(VALUE self, VALUE deep)
|
1285
|
+
{
|
1286
|
+
xmlNodePtr xnode;
|
1287
|
+
xmlNodePtr xcopy;
|
1288
|
+
int recursive = (deep == Qnil || deep == Qfalse) ? 0 : 1;
|
1289
|
+
xnode = rxml_get_xnode(self);
|
1290
|
+
|
1291
|
+
xcopy = xmlCopyNode(xnode, recursive);
|
1292
|
+
|
1293
|
+
if (xcopy)
|
1294
|
+
return rxml_node_wrap(xcopy);
|
1295
|
+
else
|
1296
|
+
return Qnil;
|
1297
|
+
}
|
1298
|
+
|
1299
|
+
void rxml_init_node(void)
|
1300
|
+
{
|
1301
|
+
cXMLNode = rb_define_class_under(mXML, "Node", rb_cObject);
|
1302
|
+
|
1303
|
+
rb_define_const(cXMLNode, "SPACE_DEFAULT", INT2NUM(0));
|
1304
|
+
rb_define_const(cXMLNode, "SPACE_PRESERVE", INT2NUM(1));
|
1305
|
+
rb_define_const(cXMLNode, "SPACE_NOT_INHERIT", INT2NUM(-1));
|
1306
|
+
rb_define_const(cXMLNode, "XLINK_ACTUATE_AUTO", INT2NUM(1));
|
1307
|
+
rb_define_const(cXMLNode, "XLINK_ACTUATE_NONE", INT2NUM(0));
|
1308
|
+
rb_define_const(cXMLNode, "XLINK_ACTUATE_ONREQUEST", INT2NUM(2));
|
1309
|
+
rb_define_const(cXMLNode, "XLINK_SHOW_EMBED", INT2NUM(2));
|
1310
|
+
rb_define_const(cXMLNode, "XLINK_SHOW_NEW", INT2NUM(1));
|
1311
|
+
rb_define_const(cXMLNode, "XLINK_SHOW_NONE", INT2NUM(0));
|
1312
|
+
rb_define_const(cXMLNode, "XLINK_SHOW_REPLACE", INT2NUM(3));
|
1313
|
+
rb_define_const(cXMLNode, "XLINK_TYPE_EXTENDED", INT2NUM(2));
|
1314
|
+
rb_define_const(cXMLNode, "XLINK_TYPE_EXTENDED_SET", INT2NUM(3));
|
1315
|
+
rb_define_const(cXMLNode, "XLINK_TYPE_NONE", INT2NUM(0));
|
1316
|
+
rb_define_const(cXMLNode, "XLINK_TYPE_SIMPLE", INT2NUM(1));
|
1317
|
+
|
1318
|
+
rb_define_const(cXMLNode, "ELEMENT_NODE", INT2FIX(XML_ELEMENT_NODE));
|
1319
|
+
rb_define_const(cXMLNode, "ATTRIBUTE_NODE", INT2FIX(XML_ATTRIBUTE_NODE));
|
1320
|
+
rb_define_const(cXMLNode, "TEXT_NODE", INT2FIX(XML_TEXT_NODE));
|
1321
|
+
rb_define_const(cXMLNode, "CDATA_SECTION_NODE", INT2FIX(XML_CDATA_SECTION_NODE));
|
1322
|
+
rb_define_const(cXMLNode, "ENTITY_REF_NODE", INT2FIX(XML_ENTITY_REF_NODE));
|
1323
|
+
rb_define_const(cXMLNode, "ENTITY_NODE", INT2FIX(XML_ENTITY_NODE));
|
1324
|
+
rb_define_const(cXMLNode, "PI_NODE", INT2FIX(XML_PI_NODE));
|
1325
|
+
rb_define_const(cXMLNode, "COMMENT_NODE", INT2FIX(XML_COMMENT_NODE));
|
1326
|
+
rb_define_const(cXMLNode, "DOCUMENT_NODE", INT2FIX(XML_DOCUMENT_NODE));
|
1327
|
+
rb_define_const(cXMLNode, "DOCUMENT_TYPE_NODE", INT2FIX(XML_DOCUMENT_TYPE_NODE));
|
1328
|
+
rb_define_const(cXMLNode, "DOCUMENT_FRAG_NODE", INT2FIX(XML_DOCUMENT_FRAG_NODE));
|
1329
|
+
rb_define_const(cXMLNode, "NOTATION_NODE", INT2FIX(XML_NOTATION_NODE));
|
1330
|
+
rb_define_const(cXMLNode, "HTML_DOCUMENT_NODE", INT2FIX(XML_HTML_DOCUMENT_NODE));
|
1331
|
+
rb_define_const(cXMLNode, "DTD_NODE", INT2FIX(XML_DTD_NODE));
|
1332
|
+
rb_define_const(cXMLNode, "ELEMENT_DECL", INT2FIX(XML_ELEMENT_DECL));
|
1333
|
+
rb_define_const(cXMLNode, "ATTRIBUTE_DECL", INT2FIX(XML_ATTRIBUTE_DECL));
|
1334
|
+
rb_define_const(cXMLNode, "ENTITY_DECL", INT2FIX(XML_ENTITY_DECL));
|
1335
|
+
rb_define_const(cXMLNode, "NAMESPACE_DECL", INT2FIX(XML_NAMESPACE_DECL));
|
1336
|
+
rb_define_const(cXMLNode, "XINCLUDE_START", INT2FIX(XML_XINCLUDE_START));
|
1337
|
+
rb_define_const(cXMLNode, "XINCLUDE_END", INT2FIX(XML_XINCLUDE_END));
|
1338
|
+
|
1339
|
+
#ifdef LIBXML_DOCB_ENABLED
|
1340
|
+
rb_define_const(cXMLNode, "DOCB_DOCUMENT_NODE", INT2FIX(XML_DOCB_DOCUMENT_NODE));
|
1341
|
+
#else
|
1342
|
+
rb_define_const(cXMLNode, "DOCB_DOCUMENT_NODE", Qnil);
|
1343
|
+
#endif
|
1344
|
+
|
1345
|
+
rb_define_singleton_method(cXMLNode, "new_cdata", rxml_node_new_cdata, -1);
|
1346
|
+
rb_define_singleton_method(cXMLNode, "new_comment", rxml_node_new_comment, -1);
|
1347
|
+
rb_define_singleton_method(cXMLNode, "new_pi", rxml_node_new_pi, -1);
|
1348
|
+
rb_define_singleton_method(cXMLNode, "new_text", rxml_node_new_text, 1);
|
1349
|
+
|
1350
|
+
/* Initialization */
|
1351
|
+
rb_define_alloc_func(cXMLNode, rxml_node_alloc);
|
1352
|
+
rb_define_method(cXMLNode, "initialize", rxml_node_initialize, -1);
|
1353
|
+
|
1354
|
+
/* Traversal */
|
1355
|
+
rb_include_module(cXMLNode, rb_mEnumerable);
|
1356
|
+
rb_define_method(cXMLNode, "[]", rxml_node_attribute_get, 1);
|
1357
|
+
rb_define_method(cXMLNode, "each", rxml_node_each, 0);
|
1358
|
+
rb_define_method(cXMLNode, "first", rxml_node_first_get, 0);
|
1359
|
+
rb_define_method(cXMLNode, "last", rxml_node_last_get, 0);
|
1360
|
+
rb_define_method(cXMLNode, "next", rxml_node_next_get, 0);
|
1361
|
+
rb_define_method(cXMLNode, "parent", rxml_node_parent_get, 0);
|
1362
|
+
rb_define_method(cXMLNode, "prev", rxml_node_prev_get, 0);
|
1363
|
+
|
1364
|
+
/* Modification */
|
1365
|
+
rb_define_method(cXMLNode, "[]=", rxml_node_property_set, 2);
|
1366
|
+
rb_define_method(cXMLNode, "<<", rxml_node_content_add, 1);
|
1367
|
+
rb_define_method(cXMLNode, "sibling=", rxml_node_sibling_set, 1);
|
1368
|
+
rb_define_method(cXMLNode, "next=", rxml_node_next_set, 1);
|
1369
|
+
rb_define_method(cXMLNode, "prev=", rxml_node_prev_set, 1);
|
1370
|
+
|
1371
|
+
/* Rest of the node api */
|
1372
|
+
rb_define_method(cXMLNode, "attributes", rxml_node_attributes_get, 0);
|
1373
|
+
rb_define_method(cXMLNode, "base_uri", rxml_node_base_uri_get, 0);
|
1374
|
+
rb_define_method(cXMLNode, "base_uri=", rxml_node_base_uri_set, 1);
|
1375
|
+
rb_define_method(cXMLNode, "blank?", rxml_node_empty_q, 0);
|
1376
|
+
rb_define_method(cXMLNode, "copy", rxml_node_copy, 1);
|
1377
|
+
rb_define_method(cXMLNode, "content", rxml_node_content_get, 0);
|
1378
|
+
rb_define_method(cXMLNode, "content=", rxml_node_content_set, 1);
|
1379
|
+
rb_define_method(cXMLNode, "debug", rxml_node_debug, 0);
|
1380
|
+
rb_define_method(cXMLNode, "doc", rxml_node_doc, 0);
|
1381
|
+
rb_define_method(cXMLNode, "empty?", rxml_node_empty_q, 0);
|
1382
|
+
rb_define_method(cXMLNode, "eql?", rxml_node_eql_q, 1);
|
1383
|
+
rb_define_method(cXMLNode, "lang", rxml_node_lang_get, 0);
|
1384
|
+
rb_define_method(cXMLNode, "lang=", rxml_node_lang_set, 1);
|
1385
|
+
rb_define_method(cXMLNode, "line_num", rxml_node_line_num, 0);
|
1386
|
+
rb_define_method(cXMLNode, "name", rxml_node_name_get, 0);
|
1387
|
+
rb_define_method(cXMLNode, "name=", rxml_node_name_set, 1);
|
1388
|
+
rb_define_method(cXMLNode, "node_type", rxml_node_type, 0);
|
1389
|
+
rb_define_method(cXMLNode, "output_escaping?", rxml_node_output_escaping_q, 0);
|
1390
|
+
rb_define_method(cXMLNode, "output_escaping=", rxml_node_output_escaping_set, 1);
|
1391
|
+
rb_define_method(cXMLNode, "path", rxml_node_path, 0);
|
1392
|
+
rb_define_method(cXMLNode, "pointer", rxml_node_pointer, 1);
|
1393
|
+
rb_define_method(cXMLNode, "remove!", rxml_node_remove_ex, 0);
|
1394
|
+
rb_define_method(cXMLNode, "space_preserve", rxml_node_space_preserve_get, 0);
|
1395
|
+
rb_define_method(cXMLNode, "space_preserve=", rxml_node_space_preserve_set, 1);
|
1396
|
+
rb_define_method(cXMLNode, "to_s", rxml_node_to_s, -1);
|
1397
|
+
rb_define_method(cXMLNode, "xlink?", rxml_node_xlink_q, 0);
|
1398
|
+
rb_define_method(cXMLNode, "xlink_type", rxml_node_xlink_type, 0);
|
1399
|
+
rb_define_method(cXMLNode, "xlink_type_name", rxml_node_xlink_type_name, 0);
|
1400
|
+
|
1401
|
+
rb_define_alias(cXMLNode, "==", "eql?");
|
1402
|
+
}
|