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