libxml-ruby 1.1.2-x86-mswin32-60 → 1.1.3-x86-mswin32-60
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +20 -0
- data/ext/libxml/build.log +4 -4
- data/ext/libxml/extconf.rb +278 -278
- data/ext/libxml/libxml.c +77 -77
- data/ext/libxml/ruby_xml.c +80 -42
- data/ext/libxml/ruby_xml.h +1 -0
- data/ext/libxml/ruby_xml_attr.c +352 -352
- data/ext/libxml/ruby_xml_attr_decl.c +1 -1
- data/ext/libxml/ruby_xml_attributes.c +3 -3
- data/ext/libxml/ruby_xml_cbg.c +86 -86
- data/ext/libxml/ruby_xml_document.c +936 -915
- data/ext/libxml/ruby_xml_dtd.c +1 -1
- data/ext/libxml/ruby_xml_error.c +5 -4
- data/ext/libxml/ruby_xml_html_parser_context.c +18 -0
- data/ext/libxml/ruby_xml_node.c +131 -177
- data/ext/libxml/ruby_xml_node.h +2 -3
- data/ext/libxml/ruby_xml_parser_context.c +32 -2
- 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 +11 -0
- data/test/tc_document.rb +13 -2
- data/test/tc_dtd.rb +5 -4
- data/test/tc_node.rb +1 -1
- data/test/tc_node_edit.rb +28 -4
- data/test/tc_xml.rb +12 -0
- data/test/tc_xpath.rb +0 -10
- metadata +2 -3
- data/test/cro_events.html +0 -740
data/ext/libxml/ruby_xml.h
CHANGED
data/ext/libxml/ruby_xml_attr.c
CHANGED
@@ -1,352 +1,352 @@
|
|
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 attribute defined on an element.
|
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
|
-
xattr->_private = NULL;
|
32
|
-
|
33
|
-
if (xattr->parent == NULL && xattr->doc == NULL)
|
34
|
-
{
|
35
|
-
xmlFreeProp(xattr);
|
36
|
-
}
|
37
|
-
}
|
38
|
-
|
39
|
-
void rxml_attr_mark(xmlAttrPtr xattr)
|
40
|
-
{
|
41
|
-
/* This can happen if Ruby does a GC run after creating the
|
42
|
-
new attribute but before initializing it. */
|
43
|
-
if (xattr == NULL)
|
44
|
-
return;
|
45
|
-
|
46
|
-
if (xattr->_private == NULL)
|
47
|
-
{
|
48
|
-
rb_warning("XmlAttr is not bound! (%s:%d)", __FILE__, __LINE__);
|
49
|
-
return;
|
50
|
-
}
|
51
|
-
|
52
|
-
|
53
|
-
}
|
54
|
-
|
55
|
-
VALUE rxml_attr_wrap(xmlAttrPtr xattr)
|
56
|
-
{
|
57
|
-
VALUE result;
|
58
|
-
|
59
|
-
/* Check if the node is already wrapped. */
|
60
|
-
if (xattr->_private != NULL)
|
61
|
-
return (VALUE) xattr->_private;
|
62
|
-
|
63
|
-
result = Data_Wrap_Struct(cXMLAttr, rxml_attr_mark, rxml_attr_free, xattr);
|
64
|
-
xattr->_private = (void*) result;
|
65
|
-
|
66
|
-
return result;
|
67
|
-
}
|
68
|
-
|
69
|
-
static VALUE rxml_attr_alloc(VALUE klass)
|
70
|
-
{
|
71
|
-
return Data_Wrap_Struct(klass, rxml_attr_mark, rxml_attr_free, NULL);
|
72
|
-
}
|
73
|
-
|
74
|
-
/*
|
75
|
-
* call-seq:
|
76
|
-
* attr.initialize(node, "name", "value")
|
77
|
-
*
|
78
|
-
* Creates a new attribute for the node.
|
79
|
-
*
|
80
|
-
* node: The XML::Node that will contain the attribute
|
81
|
-
* name: The name of the attribute
|
82
|
-
* value: The value of the attribute
|
83
|
-
*
|
84
|
-
* attr = XML::Attr.new(doc.root, 'name', 'libxml')
|
85
|
-
*/
|
86
|
-
static VALUE rxml_attr_initialize(int argc, VALUE *argv, VALUE self)
|
87
|
-
{
|
88
|
-
VALUE node = argv[0];
|
89
|
-
VALUE name = argv[1];
|
90
|
-
VALUE value = argv[2];
|
91
|
-
VALUE ns = (argc == 4 ? argv[3] : Qnil);
|
92
|
-
|
93
|
-
xmlNodePtr xnode;
|
94
|
-
xmlAttrPtr xattr;
|
95
|
-
|
96
|
-
if (argc < 3 || argc > 4)
|
97
|
-
rb_raise(rb_eArgError, "Wrong number of arguments (3 or 4)");
|
98
|
-
|
99
|
-
Check_Type(name, T_STRING);
|
100
|
-
Check_Type(value, T_STRING);
|
101
|
-
|
102
|
-
Data_Get_Struct(node, xmlNode, xnode);
|
103
|
-
|
104
|
-
if (xnode->type != XML_ELEMENT_NODE)
|
105
|
-
rb_raise(rb_eArgError, "Attributes can only be created on element nodes.");
|
106
|
-
|
107
|
-
if (NIL_P(ns))
|
108
|
-
{
|
109
|
-
xattr = xmlNewProp(xnode, (xmlChar*)StringValuePtr(name), (xmlChar*)StringValuePtr(value));
|
110
|
-
}
|
111
|
-
else
|
112
|
-
{
|
113
|
-
xmlNsPtr xns;
|
114
|
-
Data_Get_Struct(ns, xmlNs, xns);
|
115
|
-
xattr = xmlNewNsProp(xnode, xns, (xmlChar*)StringValuePtr(name), (xmlChar*)StringValuePtr(value));
|
116
|
-
}
|
117
|
-
|
118
|
-
if (!xattr)
|
119
|
-
rb_raise(rb_eRuntimeError, "Could not create attribute.");
|
120
|
-
|
121
|
-
xattr->_private = (void *) self;
|
122
|
-
DATA_PTR( self) = xattr;
|
123
|
-
return self;
|
124
|
-
}
|
125
|
-
|
126
|
-
/*
|
127
|
-
* call-seq:
|
128
|
-
* attr.child -> node
|
129
|
-
*
|
130
|
-
* Obtain this attribute's child attribute(s).
|
131
|
-
*/
|
132
|
-
static VALUE rxml_attr_child_get(VALUE self)
|
133
|
-
{
|
134
|
-
xmlAttrPtr xattr;
|
135
|
-
Data_Get_Struct(self, xmlAttr, xattr);
|
136
|
-
if (xattr->children == NULL)
|
137
|
-
return Qnil;
|
138
|
-
else
|
139
|
-
return rxml_node_wrap((xmlNodePtr) xattr->children);
|
140
|
-
}
|
141
|
-
|
142
|
-
|
143
|
-
/*
|
144
|
-
* call-seq:
|
145
|
-
* attr.doc -> XML::Document
|
146
|
-
*
|
147
|
-
* Returns this attribute's document.
|
148
|
-
*
|
149
|
-
* doc.root.attributes.get_attribute('name').doc == doc
|
150
|
-
*/
|
151
|
-
static VALUE rxml_attr_doc_get(VALUE self)
|
152
|
-
{
|
153
|
-
xmlAttrPtr xattr;
|
154
|
-
Data_Get_Struct(self, xmlAttr, xattr);
|
155
|
-
if (xattr->doc == NULL)
|
156
|
-
return Qnil;
|
157
|
-
else
|
158
|
-
return rxml_document_wrap(xattr->doc);
|
159
|
-
}
|
160
|
-
|
161
|
-
/*
|
162
|
-
* call-seq:
|
163
|
-
* attr.last -> node
|
164
|
-
*
|
165
|
-
* Obtain the last attribute.
|
166
|
-
*/
|
167
|
-
static VALUE rxml_attr_last_get(VALUE self)
|
168
|
-
{
|
169
|
-
xmlAttrPtr xattr;
|
170
|
-
Data_Get_Struct(self, xmlAttr, xattr);
|
171
|
-
if (xattr->last == NULL)
|
172
|
-
return Qnil;
|
173
|
-
else
|
174
|
-
return rxml_node_wrap(xattr->last);
|
175
|
-
}
|
176
|
-
|
177
|
-
/*
|
178
|
-
* call-seq:
|
179
|
-
* attr.name -> "name"
|
180
|
-
*
|
181
|
-
* Obtain this attribute's name.
|
182
|
-
*/
|
183
|
-
static VALUE rxml_attr_name_get(VALUE self)
|
184
|
-
{
|
185
|
-
xmlAttrPtr xattr;
|
186
|
-
Data_Get_Struct(self, xmlAttr, xattr);
|
187
|
-
|
188
|
-
if (xattr->name == NULL)
|
189
|
-
return Qnil;
|
190
|
-
else
|
191
|
-
return rb_str_new2((const char*) xattr->name);
|
192
|
-
}
|
193
|
-
|
194
|
-
/*
|
195
|
-
* call-seq:
|
196
|
-
* attr.next -> node
|
197
|
-
*
|
198
|
-
* Obtain the next attribute.
|
199
|
-
*/
|
200
|
-
static VALUE rxml_attr_next_get(VALUE self)
|
201
|
-
{
|
202
|
-
xmlAttrPtr xattr;
|
203
|
-
Data_Get_Struct(self, xmlAttr, xattr);
|
204
|
-
if (xattr->next == NULL)
|
205
|
-
return Qnil;
|
206
|
-
else
|
207
|
-
return rxml_attr_wrap(xattr->next);
|
208
|
-
}
|
209
|
-
|
210
|
-
/*
|
211
|
-
* call-seq:
|
212
|
-
* attr.node_type -> num
|
213
|
-
*
|
214
|
-
* Obtain this node's type identifier.
|
215
|
-
*/
|
216
|
-
static VALUE rxml_attr_node_type(VALUE self)
|
217
|
-
{
|
218
|
-
xmlAttrPtr xattr;
|
219
|
-
Data_Get_Struct(self, xmlAttr, xattr);
|
220
|
-
return INT2NUM(xattr->type);
|
221
|
-
}
|
222
|
-
|
223
|
-
/*
|
224
|
-
* call-seq:
|
225
|
-
* attr.ns -> namespace
|
226
|
-
*
|
227
|
-
* Obtain this attribute's associated XML::NS, if any.
|
228
|
-
*/
|
229
|
-
static VALUE rxml_attr_ns_get(VALUE self)
|
230
|
-
{
|
231
|
-
xmlAttrPtr xattr;
|
232
|
-
Data_Get_Struct(self, xmlAttr, xattr);
|
233
|
-
if (xattr->ns == NULL)
|
234
|
-
return Qnil;
|
235
|
-
else
|
236
|
-
return rxml_namespace_wrap(xattr->ns, NULL);
|
237
|
-
}
|
238
|
-
|
239
|
-
/*
|
240
|
-
* call-seq:
|
241
|
-
* attr.parent -> node
|
242
|
-
*
|
243
|
-
* Obtain this attribute node's parent.
|
244
|
-
*/
|
245
|
-
static VALUE rxml_attr_parent_get(VALUE self)
|
246
|
-
{
|
247
|
-
xmlAttrPtr xattr;
|
248
|
-
Data_Get_Struct(self, xmlAttr, xattr);
|
249
|
-
if (xattr->parent == NULL)
|
250
|
-
return Qnil;
|
251
|
-
else
|
252
|
-
return rxml_node_wrap(xattr->parent);
|
253
|
-
}
|
254
|
-
|
255
|
-
/*
|
256
|
-
* call-seq:
|
257
|
-
* attr.prev -> node
|
258
|
-
*
|
259
|
-
* Obtain the previous attribute.
|
260
|
-
*/
|
261
|
-
static VALUE rxml_attr_prev_get(VALUE self)
|
262
|
-
{
|
263
|
-
xmlAttrPtr xattr;
|
264
|
-
Data_Get_Struct(self, xmlAttr, xattr);
|
265
|
-
if (xattr->prev == NULL)
|
266
|
-
return Qnil;
|
267
|
-
else
|
268
|
-
return rxml_attr_wrap(xattr->prev);
|
269
|
-
}
|
270
|
-
|
271
|
-
/*
|
272
|
-
* call-seq:
|
273
|
-
* node.remove! -> nil
|
274
|
-
*
|
275
|
-
* Removes this attribute from it's parent.
|
276
|
-
*/
|
277
|
-
static VALUE rxml_attr_remove_ex(VALUE self)
|
278
|
-
{
|
279
|
-
xmlAttrPtr xattr;
|
280
|
-
Data_Get_Struct(self, xmlAttr, xattr);
|
281
|
-
|
282
|
-
if (xattr->_private == NULL)
|
283
|
-
xmlRemoveProp(xattr);
|
284
|
-
else
|
285
|
-
xmlUnlinkNode((xmlNodePtr) xattr);
|
286
|
-
|
287
|
-
return Qnil;;
|
288
|
-
}
|
289
|
-
|
290
|
-
/*
|
291
|
-
* call-seq:
|
292
|
-
* attr.value -> "value"
|
293
|
-
*
|
294
|
-
* Obtain the value of this attribute.
|
295
|
-
*/
|
296
|
-
VALUE rxml_attr_value_get(VALUE self)
|
297
|
-
{
|
298
|
-
xmlAttrPtr xattr;
|
299
|
-
xmlChar *value;
|
300
|
-
VALUE result = Qnil;
|
301
|
-
|
302
|
-
Data_Get_Struct(self, xmlAttr, xattr);
|
303
|
-
value = xmlNodeGetContent((xmlNodePtr)xattr);
|
304
|
-
|
305
|
-
if (value != NULL)
|
306
|
-
{
|
307
|
-
result = rb_str_new2((const char*) value);
|
308
|
-
xmlFree(value);
|
309
|
-
}
|
310
|
-
return result;
|
311
|
-
}
|
312
|
-
|
313
|
-
/*
|
314
|
-
* call-seq:
|
315
|
-
* attr.value = "value"
|
316
|
-
*
|
317
|
-
* Sets the value of this attribute.
|
318
|
-
*/
|
319
|
-
VALUE rxml_attr_value_set(VALUE self, VALUE val)
|
320
|
-
{
|
321
|
-
xmlAttrPtr xattr;
|
322
|
-
|
323
|
-
Check_Type(val, T_STRING);
|
324
|
-
Data_Get_Struct(self, xmlAttr, xattr);
|
325
|
-
|
326
|
-
if (xattr->ns)
|
327
|
-
xmlSetNsProp(xattr->parent, xattr->ns, xattr->name,
|
328
|
-
(xmlChar*) StringValuePtr(val));
|
329
|
-
else
|
330
|
-
xmlSetProp(xattr->parent, xattr->name, (xmlChar*) StringValuePtr(val));
|
331
|
-
|
332
|
-
return (self);
|
333
|
-
}
|
334
|
-
|
335
|
-
void rxml_init_attr(void)
|
336
|
-
{
|
337
|
-
cXMLAttr = rb_define_class_under(mXML, "Attr", rb_cObject);
|
338
|
-
rb_define_alloc_func(cXMLAttr, rxml_attr_alloc);
|
339
|
-
rb_define_method(cXMLAttr, "initialize", rxml_attr_initialize, -1);
|
340
|
-
rb_define_method(cXMLAttr, "child", rxml_attr_child_get, 0);
|
341
|
-
rb_define_method(cXMLAttr, "doc", rxml_attr_doc_get, 0);
|
342
|
-
rb_define_method(cXMLAttr, "last", rxml_attr_last_get, 0);
|
343
|
-
rb_define_method(cXMLAttr, "name", rxml_attr_name_get, 0);
|
344
|
-
rb_define_method(cXMLAttr, "next", rxml_attr_next_get, 0);
|
345
|
-
rb_define_method(cXMLAttr, "node_type", rxml_attr_node_type, 0);
|
346
|
-
rb_define_method(cXMLAttr, "ns", rxml_attr_ns_get, 0);
|
347
|
-
rb_define_method(cXMLAttr, "parent", rxml_attr_parent_get, 0);
|
348
|
-
rb_define_method(cXMLAttr, "prev", rxml_attr_prev_get, 0);
|
349
|
-
rb_define_method(cXMLAttr, "remove!", rxml_attr_remove_ex, 0);
|
350
|
-
rb_define_method(cXMLAttr, "value", rxml_attr_value_get, 0);
|
351
|
-
rb_define_method(cXMLAttr, "value=", rxml_attr_value_set, 1);
|
352
|
-
}
|
1
|
+
/* $Id: ruby_xml_attr.c 847 2009-03-21 22:19:43Z 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 attribute defined on an element.
|
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
|
+
xattr->_private = NULL;
|
32
|
+
|
33
|
+
if (xattr->parent == NULL && xattr->doc == NULL)
|
34
|
+
{
|
35
|
+
xmlFreeProp(xattr);
|
36
|
+
}
|
37
|
+
}
|
38
|
+
|
39
|
+
void rxml_attr_mark(xmlAttrPtr xattr)
|
40
|
+
{
|
41
|
+
/* This can happen if Ruby does a GC run after creating the
|
42
|
+
new attribute but before initializing it. */
|
43
|
+
if (xattr == NULL)
|
44
|
+
return;
|
45
|
+
|
46
|
+
if (xattr->_private == NULL)
|
47
|
+
{
|
48
|
+
rb_warning("XmlAttr is not bound! (%s:%d)", __FILE__, __LINE__);
|
49
|
+
return;
|
50
|
+
}
|
51
|
+
|
52
|
+
rxml_node_mark((xmlNodePtr) xattr);
|
53
|
+
}
|
54
|
+
|
55
|
+
VALUE rxml_attr_wrap(xmlAttrPtr xattr)
|
56
|
+
{
|
57
|
+
VALUE result;
|
58
|
+
|
59
|
+
/* Check if the node is already wrapped. */
|
60
|
+
if (xattr->_private != NULL)
|
61
|
+
return (VALUE) xattr->_private;
|
62
|
+
|
63
|
+
result = Data_Wrap_Struct(cXMLAttr, rxml_attr_mark, rxml_attr_free, xattr);
|
64
|
+
xattr->_private = (void*) result;
|
65
|
+
|
66
|
+
return result;
|
67
|
+
}
|
68
|
+
|
69
|
+
static VALUE rxml_attr_alloc(VALUE klass)
|
70
|
+
{
|
71
|
+
return Data_Wrap_Struct(klass, rxml_attr_mark, rxml_attr_free, NULL);
|
72
|
+
}
|
73
|
+
|
74
|
+
/*
|
75
|
+
* call-seq:
|
76
|
+
* attr.initialize(node, "name", "value")
|
77
|
+
*
|
78
|
+
* Creates a new attribute for the node.
|
79
|
+
*
|
80
|
+
* node: The XML::Node that will contain the attribute
|
81
|
+
* name: The name of the attribute
|
82
|
+
* value: The value of the attribute
|
83
|
+
*
|
84
|
+
* attr = XML::Attr.new(doc.root, 'name', 'libxml')
|
85
|
+
*/
|
86
|
+
static VALUE rxml_attr_initialize(int argc, VALUE *argv, VALUE self)
|
87
|
+
{
|
88
|
+
VALUE node = argv[0];
|
89
|
+
VALUE name = argv[1];
|
90
|
+
VALUE value = argv[2];
|
91
|
+
VALUE ns = (argc == 4 ? argv[3] : Qnil);
|
92
|
+
|
93
|
+
xmlNodePtr xnode;
|
94
|
+
xmlAttrPtr xattr;
|
95
|
+
|
96
|
+
if (argc < 3 || argc > 4)
|
97
|
+
rb_raise(rb_eArgError, "Wrong number of arguments (3 or 4)");
|
98
|
+
|
99
|
+
Check_Type(name, T_STRING);
|
100
|
+
Check_Type(value, T_STRING);
|
101
|
+
|
102
|
+
Data_Get_Struct(node, xmlNode, xnode);
|
103
|
+
|
104
|
+
if (xnode->type != XML_ELEMENT_NODE)
|
105
|
+
rb_raise(rb_eArgError, "Attributes can only be created on element nodes.");
|
106
|
+
|
107
|
+
if (NIL_P(ns))
|
108
|
+
{
|
109
|
+
xattr = xmlNewProp(xnode, (xmlChar*)StringValuePtr(name), (xmlChar*)StringValuePtr(value));
|
110
|
+
}
|
111
|
+
else
|
112
|
+
{
|
113
|
+
xmlNsPtr xns;
|
114
|
+
Data_Get_Struct(ns, xmlNs, xns);
|
115
|
+
xattr = xmlNewNsProp(xnode, xns, (xmlChar*)StringValuePtr(name), (xmlChar*)StringValuePtr(value));
|
116
|
+
}
|
117
|
+
|
118
|
+
if (!xattr)
|
119
|
+
rb_raise(rb_eRuntimeError, "Could not create attribute.");
|
120
|
+
|
121
|
+
xattr->_private = (void *) self;
|
122
|
+
DATA_PTR( self) = xattr;
|
123
|
+
return self;
|
124
|
+
}
|
125
|
+
|
126
|
+
/*
|
127
|
+
* call-seq:
|
128
|
+
* attr.child -> node
|
129
|
+
*
|
130
|
+
* Obtain this attribute's child attribute(s).
|
131
|
+
*/
|
132
|
+
static VALUE rxml_attr_child_get(VALUE self)
|
133
|
+
{
|
134
|
+
xmlAttrPtr xattr;
|
135
|
+
Data_Get_Struct(self, xmlAttr, xattr);
|
136
|
+
if (xattr->children == NULL)
|
137
|
+
return Qnil;
|
138
|
+
else
|
139
|
+
return rxml_node_wrap((xmlNodePtr) xattr->children);
|
140
|
+
}
|
141
|
+
|
142
|
+
|
143
|
+
/*
|
144
|
+
* call-seq:
|
145
|
+
* attr.doc -> XML::Document
|
146
|
+
*
|
147
|
+
* Returns this attribute's document.
|
148
|
+
*
|
149
|
+
* doc.root.attributes.get_attribute('name').doc == doc
|
150
|
+
*/
|
151
|
+
static VALUE rxml_attr_doc_get(VALUE self)
|
152
|
+
{
|
153
|
+
xmlAttrPtr xattr;
|
154
|
+
Data_Get_Struct(self, xmlAttr, xattr);
|
155
|
+
if (xattr->doc == NULL)
|
156
|
+
return Qnil;
|
157
|
+
else
|
158
|
+
return rxml_document_wrap(xattr->doc);
|
159
|
+
}
|
160
|
+
|
161
|
+
/*
|
162
|
+
* call-seq:
|
163
|
+
* attr.last -> node
|
164
|
+
*
|
165
|
+
* Obtain the last attribute.
|
166
|
+
*/
|
167
|
+
static VALUE rxml_attr_last_get(VALUE self)
|
168
|
+
{
|
169
|
+
xmlAttrPtr xattr;
|
170
|
+
Data_Get_Struct(self, xmlAttr, xattr);
|
171
|
+
if (xattr->last == NULL)
|
172
|
+
return Qnil;
|
173
|
+
else
|
174
|
+
return rxml_node_wrap(xattr->last);
|
175
|
+
}
|
176
|
+
|
177
|
+
/*
|
178
|
+
* call-seq:
|
179
|
+
* attr.name -> "name"
|
180
|
+
*
|
181
|
+
* Obtain this attribute's name.
|
182
|
+
*/
|
183
|
+
static VALUE rxml_attr_name_get(VALUE self)
|
184
|
+
{
|
185
|
+
xmlAttrPtr xattr;
|
186
|
+
Data_Get_Struct(self, xmlAttr, xattr);
|
187
|
+
|
188
|
+
if (xattr->name == NULL)
|
189
|
+
return Qnil;
|
190
|
+
else
|
191
|
+
return rb_str_new2((const char*) xattr->name);
|
192
|
+
}
|
193
|
+
|
194
|
+
/*
|
195
|
+
* call-seq:
|
196
|
+
* attr.next -> node
|
197
|
+
*
|
198
|
+
* Obtain the next attribute.
|
199
|
+
*/
|
200
|
+
static VALUE rxml_attr_next_get(VALUE self)
|
201
|
+
{
|
202
|
+
xmlAttrPtr xattr;
|
203
|
+
Data_Get_Struct(self, xmlAttr, xattr);
|
204
|
+
if (xattr->next == NULL)
|
205
|
+
return Qnil;
|
206
|
+
else
|
207
|
+
return rxml_attr_wrap(xattr->next);
|
208
|
+
}
|
209
|
+
|
210
|
+
/*
|
211
|
+
* call-seq:
|
212
|
+
* attr.node_type -> num
|
213
|
+
*
|
214
|
+
* Obtain this node's type identifier.
|
215
|
+
*/
|
216
|
+
static VALUE rxml_attr_node_type(VALUE self)
|
217
|
+
{
|
218
|
+
xmlAttrPtr xattr;
|
219
|
+
Data_Get_Struct(self, xmlAttr, xattr);
|
220
|
+
return INT2NUM(xattr->type);
|
221
|
+
}
|
222
|
+
|
223
|
+
/*
|
224
|
+
* call-seq:
|
225
|
+
* attr.ns -> namespace
|
226
|
+
*
|
227
|
+
* Obtain this attribute's associated XML::NS, if any.
|
228
|
+
*/
|
229
|
+
static VALUE rxml_attr_ns_get(VALUE self)
|
230
|
+
{
|
231
|
+
xmlAttrPtr xattr;
|
232
|
+
Data_Get_Struct(self, xmlAttr, xattr);
|
233
|
+
if (xattr->ns == NULL)
|
234
|
+
return Qnil;
|
235
|
+
else
|
236
|
+
return rxml_namespace_wrap(xattr->ns, NULL);
|
237
|
+
}
|
238
|
+
|
239
|
+
/*
|
240
|
+
* call-seq:
|
241
|
+
* attr.parent -> node
|
242
|
+
*
|
243
|
+
* Obtain this attribute node's parent.
|
244
|
+
*/
|
245
|
+
static VALUE rxml_attr_parent_get(VALUE self)
|
246
|
+
{
|
247
|
+
xmlAttrPtr xattr;
|
248
|
+
Data_Get_Struct(self, xmlAttr, xattr);
|
249
|
+
if (xattr->parent == NULL)
|
250
|
+
return Qnil;
|
251
|
+
else
|
252
|
+
return rxml_node_wrap(xattr->parent);
|
253
|
+
}
|
254
|
+
|
255
|
+
/*
|
256
|
+
* call-seq:
|
257
|
+
* attr.prev -> node
|
258
|
+
*
|
259
|
+
* Obtain the previous attribute.
|
260
|
+
*/
|
261
|
+
static VALUE rxml_attr_prev_get(VALUE self)
|
262
|
+
{
|
263
|
+
xmlAttrPtr xattr;
|
264
|
+
Data_Get_Struct(self, xmlAttr, xattr);
|
265
|
+
if (xattr->prev == NULL)
|
266
|
+
return Qnil;
|
267
|
+
else
|
268
|
+
return rxml_attr_wrap(xattr->prev);
|
269
|
+
}
|
270
|
+
|
271
|
+
/*
|
272
|
+
* call-seq:
|
273
|
+
* node.remove! -> nil
|
274
|
+
*
|
275
|
+
* Removes this attribute from it's parent.
|
276
|
+
*/
|
277
|
+
static VALUE rxml_attr_remove_ex(VALUE self)
|
278
|
+
{
|
279
|
+
xmlAttrPtr xattr;
|
280
|
+
Data_Get_Struct(self, xmlAttr, xattr);
|
281
|
+
|
282
|
+
if (xattr->_private == NULL)
|
283
|
+
xmlRemoveProp(xattr);
|
284
|
+
else
|
285
|
+
xmlUnlinkNode((xmlNodePtr) xattr);
|
286
|
+
|
287
|
+
return Qnil;;
|
288
|
+
}
|
289
|
+
|
290
|
+
/*
|
291
|
+
* call-seq:
|
292
|
+
* attr.value -> "value"
|
293
|
+
*
|
294
|
+
* Obtain the value of this attribute.
|
295
|
+
*/
|
296
|
+
VALUE rxml_attr_value_get(VALUE self)
|
297
|
+
{
|
298
|
+
xmlAttrPtr xattr;
|
299
|
+
xmlChar *value;
|
300
|
+
VALUE result = Qnil;
|
301
|
+
|
302
|
+
Data_Get_Struct(self, xmlAttr, xattr);
|
303
|
+
value = xmlNodeGetContent((xmlNodePtr)xattr);
|
304
|
+
|
305
|
+
if (value != NULL)
|
306
|
+
{
|
307
|
+
result = rb_str_new2((const char*) value);
|
308
|
+
xmlFree(value);
|
309
|
+
}
|
310
|
+
return result;
|
311
|
+
}
|
312
|
+
|
313
|
+
/*
|
314
|
+
* call-seq:
|
315
|
+
* attr.value = "value"
|
316
|
+
*
|
317
|
+
* Sets the value of this attribute.
|
318
|
+
*/
|
319
|
+
VALUE rxml_attr_value_set(VALUE self, VALUE val)
|
320
|
+
{
|
321
|
+
xmlAttrPtr xattr;
|
322
|
+
|
323
|
+
Check_Type(val, T_STRING);
|
324
|
+
Data_Get_Struct(self, xmlAttr, xattr);
|
325
|
+
|
326
|
+
if (xattr->ns)
|
327
|
+
xmlSetNsProp(xattr->parent, xattr->ns, xattr->name,
|
328
|
+
(xmlChar*) StringValuePtr(val));
|
329
|
+
else
|
330
|
+
xmlSetProp(xattr->parent, xattr->name, (xmlChar*) StringValuePtr(val));
|
331
|
+
|
332
|
+
return (self);
|
333
|
+
}
|
334
|
+
|
335
|
+
void rxml_init_attr(void)
|
336
|
+
{
|
337
|
+
cXMLAttr = rb_define_class_under(mXML, "Attr", rb_cObject);
|
338
|
+
rb_define_alloc_func(cXMLAttr, rxml_attr_alloc);
|
339
|
+
rb_define_method(cXMLAttr, "initialize", rxml_attr_initialize, -1);
|
340
|
+
rb_define_method(cXMLAttr, "child", rxml_attr_child_get, 0);
|
341
|
+
rb_define_method(cXMLAttr, "doc", rxml_attr_doc_get, 0);
|
342
|
+
rb_define_method(cXMLAttr, "last", rxml_attr_last_get, 0);
|
343
|
+
rb_define_method(cXMLAttr, "name", rxml_attr_name_get, 0);
|
344
|
+
rb_define_method(cXMLAttr, "next", rxml_attr_next_get, 0);
|
345
|
+
rb_define_method(cXMLAttr, "node_type", rxml_attr_node_type, 0);
|
346
|
+
rb_define_method(cXMLAttr, "ns", rxml_attr_ns_get, 0);
|
347
|
+
rb_define_method(cXMLAttr, "parent", rxml_attr_parent_get, 0);
|
348
|
+
rb_define_method(cXMLAttr, "prev", rxml_attr_prev_get, 0);
|
349
|
+
rb_define_method(cXMLAttr, "remove!", rxml_attr_remove_ex, 0);
|
350
|
+
rb_define_method(cXMLAttr, "value", rxml_attr_value_get, 0);
|
351
|
+
rb_define_method(cXMLAttr, "value=", rxml_attr_value_set, 1);
|
352
|
+
}
|