libxml-ruby 0.9.4-x86-mswin32-60 → 0.9.5-x86-mswin32-60
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +22 -0
- data/README +3 -1
- data/ext/libxml/cbg.c +86 -76
- data/ext/libxml/extconf.rb +2 -1
- data/ext/libxml/libxml.c +899 -885
- data/ext/libxml/ruby_libxml.h +65 -70
- data/ext/libxml/ruby_xml_attr.c +485 -500
- data/ext/libxml/ruby_xml_attributes.c +107 -106
- data/ext/libxml/ruby_xml_document.c +355 -356
- data/ext/libxml/ruby_xml_dtd.c +119 -117
- data/ext/libxml/ruby_xml_error.c +1112 -581
- data/ext/libxml/ruby_xml_html_parser.c +35 -34
- data/ext/libxml/ruby_xml_input.c +182 -187
- data/ext/libxml/ruby_xml_input_cbg.c +197 -179
- data/ext/libxml/ruby_xml_node.c +1529 -1566
- data/ext/libxml/ruby_xml_node.h +2 -2
- data/ext/libxml/ruby_xml_ns.c +150 -156
- data/ext/libxml/ruby_xml_parser.c +37 -36
- data/ext/libxml/ruby_xml_parser_context.c +657 -659
- data/ext/libxml/ruby_xml_reader.c +203 -209
- data/ext/libxml/ruby_xml_relaxng.c +29 -25
- data/ext/libxml/ruby_xml_sax_parser.c +33 -32
- data/ext/libxml/ruby_xml_schema.c +165 -161
- data/ext/libxml/ruby_xml_state.c +19 -21
- data/ext/libxml/ruby_xml_xinclude.c +24 -25
- data/ext/libxml/ruby_xml_xpath.c +108 -108
- data/ext/libxml/ruby_xml_xpath_context.c +305 -293
- data/ext/libxml/ruby_xml_xpath_expression.c +24 -24
- data/ext/libxml/ruby_xml_xpath_object.c +89 -96
- data/ext/libxml/ruby_xml_xpointer.c +107 -109
- data/ext/libxml/ruby_xml_xpointer.h +13 -13
- data/ext/libxml/version.h +2 -2
- data/ext/mingw/Rakefile +1 -1
- data/ext/mingw/libxml_ruby.dll.a +0 -0
- data/ext/mingw/libxml_ruby.so +0 -0
- data/ext/vc/libxml_ruby.vcproj +1 -1
- data/lib/libxml/error.rb +4 -4
- data/test/tc_node_edit.rb +14 -2
- data/test/tc_node_text.rb +9 -9
- metadata +2 -2
data/ext/libxml/ruby_libxml.h
CHANGED
@@ -1,70 +1,65 @@
|
|
1
|
-
/* Please see the LICENSE file for copyright and distribution information */
|
2
|
-
|
3
|
-
#ifndef __RUBY_LIBXML_H__
|
4
|
-
#define __RUBY_LIBXML_H__
|
5
|
-
|
6
|
-
#include "version.h"
|
7
|
-
|
8
|
-
#include <ruby.h>
|
9
|
-
#include <rubyio.h>
|
10
|
-
#include <util.h>
|
11
|
-
#include <libxml/parser.h>
|
12
|
-
#include <libxml/parserInternals.h>
|
13
|
-
#include <libxml/debugXML.h>
|
14
|
-
#include <libxml/xmlversion.h>
|
15
|
-
#include <libxml/xmlmemory.h>
|
16
|
-
#include <libxml/xpath.h>
|
17
|
-
#include <libxml/valid.h>
|
18
|
-
#include <libxml/catalog.h>
|
19
|
-
#include <libxml/HTMLparser.h>
|
20
|
-
#include <libxml/xmlreader.h>
|
21
|
-
|
22
|
-
//
|
23
|
-
#ifndef
|
24
|
-
#define
|
25
|
-
#
|
26
|
-
|
27
|
-
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
31
|
-
#
|
32
|
-
|
33
|
-
#
|
34
|
-
#
|
35
|
-
#
|
36
|
-
#
|
37
|
-
|
38
|
-
#
|
39
|
-
#
|
40
|
-
#include
|
41
|
-
#
|
42
|
-
|
43
|
-
#include "
|
44
|
-
#include "
|
45
|
-
#include "
|
46
|
-
#include "
|
47
|
-
#include "
|
48
|
-
#include "
|
49
|
-
#include "
|
50
|
-
#include "
|
51
|
-
#include "
|
52
|
-
#include "
|
53
|
-
#include "
|
54
|
-
#include "
|
55
|
-
#include "
|
56
|
-
#include "
|
57
|
-
#include "
|
58
|
-
#include "
|
59
|
-
#include "
|
60
|
-
#include "
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
#
|
66
|
-
|
67
|
-
extern VALUE mLibXML;
|
68
|
-
extern VALUE mXML;
|
69
|
-
|
70
|
-
#endif
|
1
|
+
/* Please see the LICENSE file for copyright and distribution information */
|
2
|
+
|
3
|
+
#ifndef __RUBY_LIBXML_H__
|
4
|
+
#define __RUBY_LIBXML_H__
|
5
|
+
|
6
|
+
#include "version.h"
|
7
|
+
|
8
|
+
#include <ruby.h>
|
9
|
+
#include <rubyio.h>
|
10
|
+
#include <util.h>
|
11
|
+
#include <libxml/parser.h>
|
12
|
+
#include <libxml/parserInternals.h>
|
13
|
+
#include <libxml/debugXML.h>
|
14
|
+
#include <libxml/xmlversion.h>
|
15
|
+
#include <libxml/xmlmemory.h>
|
16
|
+
#include <libxml/xpath.h>
|
17
|
+
#include <libxml/valid.h>
|
18
|
+
#include <libxml/catalog.h>
|
19
|
+
#include <libxml/HTMLparser.h>
|
20
|
+
#include <libxml/xmlreader.h>
|
21
|
+
|
22
|
+
// not in Ruby 1.9
|
23
|
+
#ifndef GetWriteFile
|
24
|
+
#define GetWriteFile(fp) rb_io_stdio_file(fp)
|
25
|
+
#define OpenFile rb_io_t
|
26
|
+
#endif
|
27
|
+
|
28
|
+
#ifdef LIBXML_DEBUG_ENABLED
|
29
|
+
#include <libxml/xpathInternals.h>
|
30
|
+
#endif
|
31
|
+
#ifdef LIBXML_XINCLUDE_ENABLED
|
32
|
+
#include <libxml/xinclude.h>
|
33
|
+
#endif
|
34
|
+
#ifdef LIBXML_XPTR_ENABLED
|
35
|
+
#include <libxml/xpointer.h>
|
36
|
+
#endif
|
37
|
+
|
38
|
+
#include "ruby_xml_error.h"
|
39
|
+
#include "ruby_xml_input.h"
|
40
|
+
#include "ruby_xml_state.h"
|
41
|
+
#include "ruby_xml_attributes.h"
|
42
|
+
#include "ruby_xml_attr.h"
|
43
|
+
#include "ruby_xml_document.h"
|
44
|
+
#include "ruby_xml_node.h"
|
45
|
+
#include "ruby_xml_ns.h"
|
46
|
+
#include "ruby_xml_parser.h"
|
47
|
+
#include "ruby_xml_parser_context.h"
|
48
|
+
#include "ruby_xml_sax_parser.h"
|
49
|
+
#include "ruby_xml_xinclude.h"
|
50
|
+
#include "ruby_xml_xpath.h"
|
51
|
+
#include "ruby_xml_xpath_expression.h"
|
52
|
+
#include "ruby_xml_xpath_context.h"
|
53
|
+
#include "ruby_xml_xpath_object.h"
|
54
|
+
#include "ruby_xml_xpointer.h"
|
55
|
+
#include "ruby_xml_input_cbg.h"
|
56
|
+
#include "ruby_xml_dtd.h"
|
57
|
+
#include "ruby_xml_schema.h"
|
58
|
+
#include "ruby_xml_relaxng.h"
|
59
|
+
#include "ruby_xml_html_parser.h"
|
60
|
+
#include "ruby_xml_reader.h"
|
61
|
+
|
62
|
+
extern VALUE mLibXML;
|
63
|
+
extern VALUE mXML;
|
64
|
+
|
65
|
+
#endif
|
data/ext/libxml/ruby_xml_attr.c
CHANGED
@@ -1,500 +1,485 @@
|
|
1
|
-
/* $Id: ruby_xml_attr.c
|
2
|
-
|
3
|
-
/* Please see the LICENSE file for copyright and distribution information */
|
4
|
-
|
5
|
-
/*
|
6
|
-
* Document-class: LibXML::XML::Attr
|
7
|
-
*
|
8
|
-
* Provides access to an single element attribute.
|
9
|
-
*
|
10
|
-
* Basic Usage:
|
11
|
-
*
|
12
|
-
* require 'xml'
|
13
|
-
*
|
14
|
-
* doc = XML::Document.new(<some_file>)
|
15
|
-
* attribute = doc.root.attributes.get_attribute_ns('http://www.w3.org/1999/xlink', 'href')
|
16
|
-
* attribute.name == 'href'
|
17
|
-
* attribute.value == 'http://www.mydocument.com'
|
18
|
-
* attribute.remove!
|
19
|
-
*/
|
20
|
-
|
21
|
-
#include "ruby_libxml.h"
|
22
|
-
#include "ruby_xml_attr.h"
|
23
|
-
|
24
|
-
VALUE cXMLAttr;
|
25
|
-
|
26
|
-
void rxml_attr_free(xmlAttrPtr xattr)
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
}
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
return;
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
#
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
rxml_attr_alloc(VALUE klass)
|
77
|
-
{
|
78
|
-
return Data_Wrap_Struct(
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
*
|
85
|
-
*
|
86
|
-
*
|
87
|
-
*
|
88
|
-
*
|
89
|
-
*
|
90
|
-
*
|
91
|
-
*
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
VALUE
|
98
|
-
VALUE
|
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
|
-
return(
|
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
|
-
|
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
|
-
cXMLAttr
|
479
|
-
|
480
|
-
rb_define_method(cXMLAttr, "
|
481
|
-
rb_define_method(cXMLAttr, "
|
482
|
-
rb_define_method(cXMLAttr, "
|
483
|
-
rb_define_method(cXMLAttr, "
|
484
|
-
rb_define_method(cXMLAttr, "
|
485
|
-
|
486
|
-
rb_define_method(cXMLAttr, "last?", rxml_attr_last_q, 0);
|
487
|
-
rb_define_method(cXMLAttr, "name", rxml_attr_name_get, 0);
|
488
|
-
rb_define_method(cXMLAttr, "next", rxml_attr_next_get, 0);
|
489
|
-
rb_define_method(cXMLAttr, "next?", rxml_attr_next_q, 0);
|
490
|
-
rb_define_method(cXMLAttr, "node_type_name", rxml_attr_node_type_name, 0);
|
491
|
-
rb_define_method(cXMLAttr, "ns", rxml_attr_ns_get, 0);
|
492
|
-
rb_define_method(cXMLAttr, "ns?", rxml_attr_ns_q, 0);
|
493
|
-
rb_define_method(cXMLAttr, "parent", rxml_attr_parent_get, 0);
|
494
|
-
rb_define_method(cXMLAttr, "parent?", rxml_attr_parent_q, 0);
|
495
|
-
rb_define_method(cXMLAttr, "prev", rxml_attr_prev_get, 0);
|
496
|
-
rb_define_method(cXMLAttr, "prev?", rxml_attr_prev_q, 0);
|
497
|
-
rb_define_method(cXMLAttr, "remove!", rxml_attr_remove_ex, 0);
|
498
|
-
rb_define_method(cXMLAttr, "value", rxml_attr_value_get, 0);
|
499
|
-
rb_define_method(cXMLAttr, "value=", rxml_attr_value_set, 1);
|
500
|
-
}
|
1
|
+
/* $Id: ruby_xml_attr.c 650 2008-11-30 03:40:22Z cfis $ */
|
2
|
+
|
3
|
+
/* Please see the LICENSE file for copyright and distribution information */
|
4
|
+
|
5
|
+
/*
|
6
|
+
* Document-class: LibXML::XML::Attr
|
7
|
+
*
|
8
|
+
* Provides access to an single element attribute.
|
9
|
+
*
|
10
|
+
* Basic Usage:
|
11
|
+
*
|
12
|
+
* require 'xml'
|
13
|
+
*
|
14
|
+
* doc = XML::Document.new(<some_file>)
|
15
|
+
* attribute = doc.root.attributes.get_attribute_ns('http://www.w3.org/1999/xlink', 'href')
|
16
|
+
* attribute.name == 'href'
|
17
|
+
* attribute.value == 'http://www.mydocument.com'
|
18
|
+
* attribute.remove!
|
19
|
+
*/
|
20
|
+
|
21
|
+
#include "ruby_libxml.h"
|
22
|
+
#include "ruby_xml_attr.h"
|
23
|
+
|
24
|
+
VALUE cXMLAttr;
|
25
|
+
|
26
|
+
void rxml_attr_free(xmlAttrPtr xattr)
|
27
|
+
{
|
28
|
+
if (!xattr)
|
29
|
+
return;
|
30
|
+
|
31
|
+
if (xattr != NULL)
|
32
|
+
{
|
33
|
+
xattr->_private = NULL;
|
34
|
+
if (xattr->parent == NULL && xattr->doc == NULL)
|
35
|
+
{
|
36
|
+
#ifdef NODE_DEBUG
|
37
|
+
fprintf(stderr,"ruby_xfree rxn=0x%x xn=0x%x o=0x%x\n",(long)rxn,(long)rxn->node,(long)rxn->node->_private);
|
38
|
+
#endif
|
39
|
+
xmlFreeProp(xattr);
|
40
|
+
}
|
41
|
+
|
42
|
+
xattr = NULL;
|
43
|
+
}
|
44
|
+
}
|
45
|
+
|
46
|
+
void rxml_attr_mark(xmlAttrPtr xattr)
|
47
|
+
{
|
48
|
+
if (xattr == NULL)
|
49
|
+
return;
|
50
|
+
|
51
|
+
if (xattr->_private == NULL)
|
52
|
+
{
|
53
|
+
rb_warning("XmlAttr is not bound! (%s:%d)", __FILE__, __LINE__);
|
54
|
+
return;
|
55
|
+
}
|
56
|
+
|
57
|
+
rxml_node_mark_common((xmlNodePtr) xattr);
|
58
|
+
}
|
59
|
+
|
60
|
+
VALUE rxml_attr_wrap(xmlAttrPtr xattr)
|
61
|
+
{
|
62
|
+
VALUE result;
|
63
|
+
// This node is already wrapped
|
64
|
+
if (xattr->_private != NULL)
|
65
|
+
return (VALUE) xattr->_private;
|
66
|
+
|
67
|
+
result = Data_Wrap_Struct(cXMLAttr, rxml_attr_mark, rxml_attr_free, xattr);
|
68
|
+
|
69
|
+
xattr->_private = (void*) result;
|
70
|
+
#ifdef NODE_DEBUG
|
71
|
+
fprintf(stderr,"wrap rxn=0x%x xn=0x%x o=0x%x\n",(long)rxn,(long)xnode,(long)obj);
|
72
|
+
#endif
|
73
|
+
return result;
|
74
|
+
}
|
75
|
+
|
76
|
+
static VALUE rxml_attr_alloc(VALUE klass)
|
77
|
+
{
|
78
|
+
return Data_Wrap_Struct(klass, rxml_attr_mark, rxml_attr_free, NULL);
|
79
|
+
}
|
80
|
+
|
81
|
+
/*
|
82
|
+
* call-seq:
|
83
|
+
* attr.initialize(node, "name", "value")
|
84
|
+
*
|
85
|
+
* Creates a new attribute for the node.
|
86
|
+
*
|
87
|
+
* node: The XML::Node that will contain the attribute
|
88
|
+
* name: The name of the attribute
|
89
|
+
* value: The value of the attribute
|
90
|
+
*
|
91
|
+
* attr = XML::Attr.new(doc.root, 'name', 'libxml')
|
92
|
+
*/
|
93
|
+
static VALUE rxml_attr_initialize(int argc, VALUE *argv, VALUE self)
|
94
|
+
{
|
95
|
+
VALUE node = argv[0];
|
96
|
+
VALUE name = argv[1];
|
97
|
+
VALUE value = argv[2];
|
98
|
+
VALUE ns = (argc == 4 ? argv[3] : Qnil);
|
99
|
+
|
100
|
+
xmlNodePtr xnode;
|
101
|
+
xmlAttrPtr xattr;
|
102
|
+
|
103
|
+
if (argc < 3 || argc > 4)
|
104
|
+
rb_raise(rb_eArgError, "Wrong number of arguments (3 or 4)");
|
105
|
+
|
106
|
+
Check_Type(name, T_STRING);
|
107
|
+
Check_Type(value, T_STRING);
|
108
|
+
|
109
|
+
Data_Get_Struct(node, xmlNode, xnode);
|
110
|
+
|
111
|
+
if (xnode->type != XML_ELEMENT_NODE)
|
112
|
+
rb_raise(rb_eArgError, "Attributes can only be created on element nodes.");
|
113
|
+
|
114
|
+
if NIL_P(ns)
|
115
|
+
{
|
116
|
+
xattr = xmlNewProp(xnode, (xmlChar*)StringValuePtr(name), (xmlChar*)StringValuePtr(value));
|
117
|
+
}
|
118
|
+
else
|
119
|
+
{
|
120
|
+
xmlNsPtr xns;
|
121
|
+
Data_Get_Struct(ns, xmlNs, xns);
|
122
|
+
xattr = xmlNewNsProp(xnode, xns, (xmlChar*)StringValuePtr(name), (xmlChar*)StringValuePtr(value));
|
123
|
+
}
|
124
|
+
|
125
|
+
if (!xattr)
|
126
|
+
rb_raise(rb_eRuntimeError, "Could not create attribute.");
|
127
|
+
|
128
|
+
xattr->_private = (void *) self;
|
129
|
+
DATA_PTR( self) = xattr;
|
130
|
+
return self;
|
131
|
+
}
|
132
|
+
|
133
|
+
/*
|
134
|
+
* call-seq:
|
135
|
+
* attr.child -> node
|
136
|
+
*
|
137
|
+
* Obtain this attribute's child attribute(s).
|
138
|
+
*/
|
139
|
+
static VALUE rxml_attr_child_get(VALUE self)
|
140
|
+
{
|
141
|
+
xmlAttrPtr xattr;
|
142
|
+
Data_Get_Struct(self, xmlAttr, xattr);
|
143
|
+
if (xattr->children == NULL)
|
144
|
+
return (Qnil);
|
145
|
+
else
|
146
|
+
return (rxml_node_wrap(cXMLNode, (xmlNodePtr) xattr->children));
|
147
|
+
}
|
148
|
+
|
149
|
+
/*
|
150
|
+
* call-seq:
|
151
|
+
* attr.child? -> (true|false)
|
152
|
+
*
|
153
|
+
* Returns whether this attribute has child attributes.
|
154
|
+
*/
|
155
|
+
static VALUE rxml_attr_child_q(VALUE self)
|
156
|
+
{
|
157
|
+
xmlAttrPtr xattr;
|
158
|
+
Data_Get_Struct(self, xmlAttr, xattr);
|
159
|
+
if (xattr->children == NULL)
|
160
|
+
return (Qfalse);
|
161
|
+
else
|
162
|
+
return (Qtrue);
|
163
|
+
}
|
164
|
+
|
165
|
+
/*
|
166
|
+
* call-seq:
|
167
|
+
* attr.doc -> XML::Document
|
168
|
+
*
|
169
|
+
* Returns this attribute's document.
|
170
|
+
*
|
171
|
+
* doc.root.attributes.get_attribute('name').doc == doc
|
172
|
+
*/
|
173
|
+
static VALUE rxml_attr_doc_get(VALUE self)
|
174
|
+
{
|
175
|
+
xmlAttrPtr xattr;
|
176
|
+
Data_Get_Struct(self, xmlAttr, xattr);
|
177
|
+
if (xattr->doc == NULL)
|
178
|
+
return (Qnil);
|
179
|
+
else
|
180
|
+
return (rxml_document_wrap(xattr->doc));
|
181
|
+
}
|
182
|
+
|
183
|
+
/*
|
184
|
+
* call-seq:
|
185
|
+
* attr.doc? -> (true|false)
|
186
|
+
*
|
187
|
+
* Determine whether this attribute is associated with an
|
188
|
+
* XML::Document.
|
189
|
+
*/
|
190
|
+
static VALUE rxml_attr_doc_q(VALUE self)
|
191
|
+
{
|
192
|
+
xmlAttrPtr xattr;
|
193
|
+
Data_Get_Struct(self, xmlAttr, xattr);
|
194
|
+
if (xattr->doc == NULL)
|
195
|
+
return (Qfalse);
|
196
|
+
else
|
197
|
+
return (Qtrue);
|
198
|
+
}
|
199
|
+
|
200
|
+
/*
|
201
|
+
* call-seq:
|
202
|
+
* attr.last -> node
|
203
|
+
*
|
204
|
+
* Obtain the last attribute.
|
205
|
+
*/
|
206
|
+
static VALUE rxml_attr_last_get(VALUE self)
|
207
|
+
{
|
208
|
+
xmlAttrPtr xattr;
|
209
|
+
Data_Get_Struct(self, xmlAttr, xattr);
|
210
|
+
if (xattr->last == NULL)
|
211
|
+
return (Qnil);
|
212
|
+
else
|
213
|
+
return (rxml_node_wrap(cXMLNode, xattr->last));
|
214
|
+
}
|
215
|
+
|
216
|
+
/*
|
217
|
+
* call-seq:
|
218
|
+
* attr.last? -> (true|false)
|
219
|
+
*
|
220
|
+
* Determine whether this is the last attribute.
|
221
|
+
*/
|
222
|
+
static VALUE rxml_attr_last_q(VALUE self)
|
223
|
+
{
|
224
|
+
xmlAttrPtr xattr;
|
225
|
+
Data_Get_Struct(self, xmlAttr, xattr);
|
226
|
+
if (xattr->last == NULL)
|
227
|
+
return (Qfalse);
|
228
|
+
else
|
229
|
+
return (Qtrue);
|
230
|
+
}
|
231
|
+
|
232
|
+
/*
|
233
|
+
* call-seq:
|
234
|
+
* attr.name -> "name"
|
235
|
+
*
|
236
|
+
* Obtain this attribute's name.
|
237
|
+
*/
|
238
|
+
static VALUE rxml_attr_name_get(VALUE self)
|
239
|
+
{
|
240
|
+
xmlAttrPtr xattr;
|
241
|
+
Data_Get_Struct(self, xmlAttr, xattr);
|
242
|
+
|
243
|
+
if (xattr->name == NULL)
|
244
|
+
return (Qnil);
|
245
|
+
else
|
246
|
+
return (rb_str_new2((const char*) xattr->name));
|
247
|
+
}
|
248
|
+
|
249
|
+
/*
|
250
|
+
* call-seq:
|
251
|
+
* attr.next -> node
|
252
|
+
*
|
253
|
+
* Obtain the next attribute.
|
254
|
+
*/
|
255
|
+
static VALUE rxml_attr_next_get(VALUE self)
|
256
|
+
{
|
257
|
+
xmlAttrPtr xattr;
|
258
|
+
Data_Get_Struct(self, xmlAttr, xattr);
|
259
|
+
if (xattr->next == NULL)
|
260
|
+
return (Qnil);
|
261
|
+
else
|
262
|
+
return (rxml_attr_wrap(xattr->next));
|
263
|
+
}
|
264
|
+
|
265
|
+
/*
|
266
|
+
* call-seq:
|
267
|
+
* attr.next? -> (true|false)
|
268
|
+
*
|
269
|
+
* Determine whether there is a next attribute.
|
270
|
+
*/
|
271
|
+
static VALUE rxml_attr_next_q(VALUE self)
|
272
|
+
{
|
273
|
+
xmlAttrPtr xattr;
|
274
|
+
Data_Get_Struct(self, xmlAttr, xattr);
|
275
|
+
if (xattr->next == NULL)
|
276
|
+
return (Qfalse);
|
277
|
+
else
|
278
|
+
return (Qtrue);
|
279
|
+
}
|
280
|
+
|
281
|
+
/*
|
282
|
+
* call-seq:
|
283
|
+
* attr.type_name -> "attribute"
|
284
|
+
*
|
285
|
+
* Obtain this attribute node's type name.
|
286
|
+
*/
|
287
|
+
static VALUE rxml_attr_node_type_name(VALUE self)
|
288
|
+
{
|
289
|
+
return (rb_str_new2("attribute"));
|
290
|
+
}
|
291
|
+
|
292
|
+
/*
|
293
|
+
* call-seq:
|
294
|
+
* attr.ns -> namespace
|
295
|
+
*
|
296
|
+
* Obtain this attribute's associated XML::NS, if any.
|
297
|
+
*/
|
298
|
+
static VALUE rxml_attr_ns_get(VALUE self)
|
299
|
+
{
|
300
|
+
xmlAttrPtr xattr;
|
301
|
+
Data_Get_Struct(self, xmlAttr, xattr);
|
302
|
+
if (xattr->ns == NULL)
|
303
|
+
return (Qnil);
|
304
|
+
else
|
305
|
+
return (rxml_ns_wrap(xattr->ns));
|
306
|
+
}
|
307
|
+
|
308
|
+
/*
|
309
|
+
* call-seq:
|
310
|
+
* attr.ns? -> (true|false)
|
311
|
+
*
|
312
|
+
* Determine whether this attribute has an associated
|
313
|
+
* namespace.
|
314
|
+
*/
|
315
|
+
static VALUE rxml_attr_ns_q(VALUE self)
|
316
|
+
{
|
317
|
+
xmlAttrPtr xattr;
|
318
|
+
Data_Get_Struct(self, xmlAttr, xattr);
|
319
|
+
if (xattr->ns == NULL)
|
320
|
+
return (Qfalse);
|
321
|
+
else
|
322
|
+
return (Qtrue);
|
323
|
+
}
|
324
|
+
|
325
|
+
/*
|
326
|
+
* call-seq:
|
327
|
+
* attr.parent -> node
|
328
|
+
*
|
329
|
+
* Obtain this attribute node's parent.
|
330
|
+
*/
|
331
|
+
static VALUE rxml_attr_parent_get(VALUE self)
|
332
|
+
{
|
333
|
+
xmlAttrPtr xattr;
|
334
|
+
Data_Get_Struct(self, xmlAttr, xattr);
|
335
|
+
if (xattr->parent == NULL)
|
336
|
+
return (Qnil);
|
337
|
+
else
|
338
|
+
return (rxml_node_wrap(cXMLNode, xattr->parent));
|
339
|
+
}
|
340
|
+
|
341
|
+
/*
|
342
|
+
* call-seq:
|
343
|
+
* attr.parent? -> (true|false)
|
344
|
+
*
|
345
|
+
* Determine whether this attribute has a parent.
|
346
|
+
*/
|
347
|
+
static VALUE rxml_attr_parent_q(VALUE self)
|
348
|
+
{
|
349
|
+
xmlAttrPtr xattr;
|
350
|
+
Data_Get_Struct(self, xmlAttr, xattr);
|
351
|
+
if (xattr->parent == NULL)
|
352
|
+
return (Qfalse);
|
353
|
+
else
|
354
|
+
return (Qtrue);
|
355
|
+
}
|
356
|
+
|
357
|
+
/*
|
358
|
+
* call-seq:
|
359
|
+
* attr.prev -> node
|
360
|
+
*
|
361
|
+
* Obtain the previous attribute.
|
362
|
+
*/
|
363
|
+
static VALUE rxml_attr_prev_get(VALUE self)
|
364
|
+
{
|
365
|
+
xmlAttrPtr xattr;
|
366
|
+
Data_Get_Struct(self, xmlAttr, xattr);
|
367
|
+
if (xattr->prev == NULL)
|
368
|
+
return (Qnil);
|
369
|
+
else
|
370
|
+
return (rxml_attr_wrap(xattr->prev));
|
371
|
+
}
|
372
|
+
|
373
|
+
/*
|
374
|
+
* call-seq:
|
375
|
+
* attr.prev? -> (true|false)
|
376
|
+
*
|
377
|
+
* Determine whether there is a previous attribute.
|
378
|
+
*/
|
379
|
+
static VALUE rxml_attr_prev_q(VALUE self)
|
380
|
+
{
|
381
|
+
xmlAttrPtr xattr;
|
382
|
+
Data_Get_Struct(self, xmlAttr, xattr);
|
383
|
+
if (xattr->prev == NULL)
|
384
|
+
return (Qfalse);
|
385
|
+
else
|
386
|
+
return (Qtrue);
|
387
|
+
}
|
388
|
+
|
389
|
+
/*
|
390
|
+
* call-seq:
|
391
|
+
* node.remove! -> nil
|
392
|
+
*
|
393
|
+
* Removes this attribute from it's parent.
|
394
|
+
*/
|
395
|
+
static VALUE rxml_attr_remove_ex(VALUE self)
|
396
|
+
{
|
397
|
+
xmlAttrPtr xattr;
|
398
|
+
Data_Get_Struct(self, xmlAttr, xattr);
|
399
|
+
|
400
|
+
if (xattr->_private == NULL)
|
401
|
+
xmlRemoveProp(xattr);
|
402
|
+
else
|
403
|
+
xmlUnlinkNode((xmlNodePtr) xattr);
|
404
|
+
|
405
|
+
return (Qnil);
|
406
|
+
}
|
407
|
+
|
408
|
+
/*
|
409
|
+
* call-seq:
|
410
|
+
* attr.value -> "value"
|
411
|
+
*
|
412
|
+
* Obtain the value of this attribute.
|
413
|
+
*/
|
414
|
+
VALUE rxml_attr_value_get(VALUE self)
|
415
|
+
{
|
416
|
+
xmlAttrPtr xattr;
|
417
|
+
xmlChar *value;
|
418
|
+
VALUE result = Qnil;
|
419
|
+
|
420
|
+
Data_Get_Struct(self, xmlAttr, xattr);
|
421
|
+
if (rxml_attr_parent_q(self) == Qtrue)
|
422
|
+
{
|
423
|
+
value = xmlGetProp(xattr->parent, xattr->name);
|
424
|
+
if (value != NULL)
|
425
|
+
{
|
426
|
+
result = rb_str_new2((const char*) value);
|
427
|
+
xmlFree(value);
|
428
|
+
}
|
429
|
+
}
|
430
|
+
return (result);
|
431
|
+
}
|
432
|
+
|
433
|
+
/*
|
434
|
+
* call-seq:
|
435
|
+
* attr.value = "value"
|
436
|
+
*
|
437
|
+
* Sets the value of this attribute.
|
438
|
+
*/
|
439
|
+
VALUE rxml_attr_value_set(VALUE self, VALUE val)
|
440
|
+
{
|
441
|
+
xmlAttrPtr xattr;
|
442
|
+
|
443
|
+
Check_Type(val, T_STRING);
|
444
|
+
Data_Get_Struct(self, xmlAttr, xattr);
|
445
|
+
|
446
|
+
if (xattr->ns)
|
447
|
+
xmlSetNsProp(xattr->parent, xattr->ns, xattr->name,
|
448
|
+
(xmlChar*) StringValuePtr(val));
|
449
|
+
else
|
450
|
+
xmlSetProp(xattr->parent, xattr->name, (xmlChar*) StringValuePtr(val));
|
451
|
+
|
452
|
+
return (self);
|
453
|
+
}
|
454
|
+
|
455
|
+
// Rdoc needs to know
|
456
|
+
#ifdef RDOC_NEVER_DEFINED
|
457
|
+
mLibXML = rb_define_module("LibXML");
|
458
|
+
mXML = rb_define_module_under(mLibXML, "XML");
|
459
|
+
#endif
|
460
|
+
|
461
|
+
void ruby_init_xml_attr(void)
|
462
|
+
{
|
463
|
+
cXMLAttr = rb_define_class_under(mXML, "Attr", rb_cObject);
|
464
|
+
rb_define_alloc_func(cXMLAttr, rxml_attr_alloc);
|
465
|
+
rb_define_method(cXMLAttr, "initialize", rxml_attr_initialize, -1);
|
466
|
+
rb_define_method(cXMLAttr, "child", rxml_attr_child_get, 0);
|
467
|
+
rb_define_method(cXMLAttr, "child?", rxml_attr_child_q, 0);
|
468
|
+
rb_define_method(cXMLAttr, "doc", rxml_attr_doc_get, 0);
|
469
|
+
rb_define_method(cXMLAttr, "doc?", rxml_attr_doc_q, 0);
|
470
|
+
rb_define_method(cXMLAttr, "last", rxml_attr_last_get, 0);
|
471
|
+
rb_define_method(cXMLAttr, "last?", rxml_attr_last_q, 0);
|
472
|
+
rb_define_method(cXMLAttr, "name", rxml_attr_name_get, 0);
|
473
|
+
rb_define_method(cXMLAttr, "next", rxml_attr_next_get, 0);
|
474
|
+
rb_define_method(cXMLAttr, "next?", rxml_attr_next_q, 0);
|
475
|
+
rb_define_method(cXMLAttr, "node_type_name", rxml_attr_node_type_name, 0);
|
476
|
+
rb_define_method(cXMLAttr, "ns", rxml_attr_ns_get, 0);
|
477
|
+
rb_define_method(cXMLAttr, "ns?", rxml_attr_ns_q, 0);
|
478
|
+
rb_define_method(cXMLAttr, "parent", rxml_attr_parent_get, 0);
|
479
|
+
rb_define_method(cXMLAttr, "parent?", rxml_attr_parent_q, 0);
|
480
|
+
rb_define_method(cXMLAttr, "prev", rxml_attr_prev_get, 0);
|
481
|
+
rb_define_method(cXMLAttr, "prev?", rxml_attr_prev_q, 0);
|
482
|
+
rb_define_method(cXMLAttr, "remove!", rxml_attr_remove_ex, 0);
|
483
|
+
rb_define_method(cXMLAttr, "value", rxml_attr_value_get, 0);
|
484
|
+
rb_define_method(cXMLAttr, "value=", rxml_attr_value_set, 1);
|
485
|
+
}
|