libxml-ruby 0.9.5-x86-mswin32-60 → 0.9.6-x86-mswin32-60
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGES +28 -0
- data/README +8 -12
- data/ext/libxml/cbg.c +86 -86
- data/ext/libxml/libxml.c +875 -899
- data/ext/libxml/ruby_libxml.h +91 -65
- data/ext/libxml/ruby_xml_attr.c +485 -485
- data/ext/libxml/ruby_xml_attr.h +3 -3
- data/ext/libxml/ruby_xml_attributes.h +2 -2
- data/ext/libxml/ruby_xml_document.c +124 -307
- data/ext/libxml/ruby_xml_document.h +3 -3
- data/ext/libxml/ruby_xml_dtd.c +119 -119
- data/ext/libxml/ruby_xml_dtd.h +2 -2
- data/ext/libxml/ruby_xml_error.c +1 -1
- data/ext/libxml/ruby_xml_error.h +2 -2
- data/ext/libxml/ruby_xml_html_parser.c +119 -119
- data/ext/libxml/ruby_xml_html_parser.h +3 -3
- data/ext/libxml/ruby_xml_input.c +13 -11
- data/ext/libxml/ruby_xml_input.h +3 -3
- data/ext/libxml/ruby_xml_input_cbg.c +197 -197
- data/ext/libxml/ruby_xml_namespace.c +158 -0
- data/ext/libxml/ruby_xml_namespace.h +12 -0
- data/ext/libxml/ruby_xml_namespaces.c +303 -0
- data/ext/libxml/{ruby_xml_ns.h → ruby_xml_namespaces.h} +4 -5
- data/ext/libxml/ruby_xml_node.c +88 -293
- data/ext/libxml/ruby_xml_node.h +4 -4
- data/ext/libxml/ruby_xml_parser.c +152 -152
- data/ext/libxml/ruby_xml_parser.h +3 -3
- data/ext/libxml/ruby_xml_parser_context.c +630 -657
- data/ext/libxml/ruby_xml_parser_context.h +3 -3
- data/ext/libxml/ruby_xml_reader.c +899 -904
- data/ext/libxml/ruby_xml_reader.h +2 -2
- data/ext/libxml/ruby_xml_relaxng.h +2 -2
- data/ext/libxml/ruby_xml_sax_parser.c +175 -175
- data/ext/libxml/ruby_xml_sax_parser.h +3 -3
- data/ext/libxml/ruby_xml_schema.c +165 -165
- data/ext/libxml/ruby_xml_schema.h +2 -2
- data/ext/libxml/ruby_xml_state.h +2 -2
- data/ext/libxml/ruby_xml_xinclude.c +24 -24
- data/ext/libxml/ruby_xml_xinclude.h +3 -3
- data/ext/libxml/ruby_xml_xpath.c +108 -108
- data/ext/libxml/ruby_xml_xpath.h +3 -3
- data/ext/libxml/ruby_xml_xpath_context.c +84 -35
- data/ext/libxml/ruby_xml_xpath_context.h +3 -3
- data/ext/libxml/ruby_xml_xpath_expression.c +5 -7
- data/ext/libxml/ruby_xml_xpath_expression.h +2 -2
- data/ext/libxml/ruby_xml_xpath_object.c +7 -7
- data/ext/libxml/ruby_xml_xpath_object.h +2 -2
- data/ext/libxml/ruby_xml_xpointer.c +107 -107
- data/ext/libxml/ruby_xml_xpointer.h +3 -3
- data/ext/libxml/version.h +2 -2
- data/ext/mingw/libxml_ruby.dll.a +0 -0
- data/ext/mingw/libxml_ruby.so +0 -0
- data/ext/vc/libxml_ruby.vcproj +13 -5
- data/lib/libxml.rb +4 -1
- data/lib/libxml/document.rb +40 -6
- data/lib/libxml/hpricot.rb +76 -76
- data/lib/libxml/namespace.rb +60 -0
- data/lib/libxml/namespaces.rb +36 -0
- data/lib/libxml/node.rb +90 -26
- data/lib/libxml/ns.rb +20 -0
- data/test/model/bands.xml +5 -0
- data/test/tc_attributes.rb +1 -1
- data/test/tc_document.rb +24 -41
- data/test/tc_document_write.rb +87 -115
- data/test/tc_namespace.rb +59 -0
- data/test/tc_namespaces.rb +174 -0
- data/test/tc_node.rb +41 -33
- data/test/tc_node_copy.rb +1 -1
- data/test/tc_node_edit.rb +6 -0
- data/test/tc_node_write.rb +76 -0
- data/test/tc_xinclude.rb +2 -9
- data/test/tc_xpath.rb +38 -11
- data/test/test_suite.rb +3 -1
- metadata +16 -9
- data/ext/libxml/ruby_xml_ns.c +0 -150
- data/test/ets_copy_bug.rb +0 -21
- data/test/ets_copy_bug3.rb +0 -38
- data/test/model/default_validation_bug.rb +0 -0
- data/test/tc_ns.rb +0 -18
data/ext/libxml/ruby_libxml.h
CHANGED
@@ -1,65 +1,91 @@
|
|
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
|
-
#endif
|
31
|
-
|
32
|
-
|
33
|
-
#
|
34
|
-
#
|
35
|
-
#
|
36
|
-
|
37
|
-
|
38
|
-
#
|
39
|
-
#
|
40
|
-
#
|
41
|
-
|
42
|
-
|
43
|
-
#
|
44
|
-
#
|
45
|
-
#
|
46
|
-
|
47
|
-
|
48
|
-
#
|
49
|
-
#
|
50
|
-
#
|
51
|
-
#
|
52
|
-
|
53
|
-
#
|
54
|
-
#include
|
55
|
-
#
|
56
|
-
#
|
57
|
-
#include
|
58
|
-
#
|
59
|
-
#
|
60
|
-
#include
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
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
|
+
/* Needed for Ruby 1.8.5 */
|
23
|
+
#ifndef RARRAY_LEN
|
24
|
+
#define RARRAY_LEN(s) (RARRAY(s)->len)
|
25
|
+
#endif
|
26
|
+
|
27
|
+
/* Needed for Ruby 1.8.5 */
|
28
|
+
#ifndef RARRAY_PTR
|
29
|
+
#define RARRAY_PTR(s) (RARRAY(s)->ptr)
|
30
|
+
#endif
|
31
|
+
|
32
|
+
/* Needed for Ruby 1.8.5 */
|
33
|
+
#ifndef RSTRING_LEN
|
34
|
+
#define RSTRING_LEN(s) (RSTRING(s)->len)
|
35
|
+
#endif
|
36
|
+
|
37
|
+
/* Needed for Ruby 1.8.5 */
|
38
|
+
#ifndef RSTRING_PTR
|
39
|
+
#define RSTRING_PTR(s) (RSTRING(s)->ptr)
|
40
|
+
#endif
|
41
|
+
|
42
|
+
/* Needed prior to Ruby 1.9.1 */
|
43
|
+
#ifndef RHASH_TBL
|
44
|
+
#define RHASH_TBL(s) (RHASH(s)->tbl)
|
45
|
+
#endif
|
46
|
+
|
47
|
+
// not in Ruby 1.9
|
48
|
+
#ifndef GetWriteFile
|
49
|
+
#define GetWriteFile(fp) rb_io_stdio_file(fp)
|
50
|
+
#define OpenFile rb_io_t
|
51
|
+
#endif
|
52
|
+
|
53
|
+
#ifdef LIBXML_DEBUG_ENABLED
|
54
|
+
#include <libxml/xpathInternals.h>
|
55
|
+
#endif
|
56
|
+
#ifdef LIBXML_XINCLUDE_ENABLED
|
57
|
+
#include <libxml/xinclude.h>
|
58
|
+
#endif
|
59
|
+
#ifdef LIBXML_XPTR_ENABLED
|
60
|
+
#include <libxml/xpointer.h>
|
61
|
+
#endif
|
62
|
+
|
63
|
+
#include "ruby_xml_error.h"
|
64
|
+
#include "ruby_xml_input.h"
|
65
|
+
#include "ruby_xml_state.h"
|
66
|
+
#include "ruby_xml_attributes.h"
|
67
|
+
#include "ruby_xml_attr.h"
|
68
|
+
#include "ruby_xml_document.h"
|
69
|
+
#include "ruby_xml_node.h"
|
70
|
+
#include "ruby_xml_namespace.h"
|
71
|
+
#include "ruby_xml_namespaces.h"
|
72
|
+
#include "ruby_xml_parser.h"
|
73
|
+
#include "ruby_xml_parser_context.h"
|
74
|
+
#include "ruby_xml_sax_parser.h"
|
75
|
+
#include "ruby_xml_xinclude.h"
|
76
|
+
#include "ruby_xml_xpath.h"
|
77
|
+
#include "ruby_xml_xpath_expression.h"
|
78
|
+
#include "ruby_xml_xpath_context.h"
|
79
|
+
#include "ruby_xml_xpath_object.h"
|
80
|
+
#include "ruby_xml_xpointer.h"
|
81
|
+
#include "ruby_xml_input_cbg.h"
|
82
|
+
#include "ruby_xml_dtd.h"
|
83
|
+
#include "ruby_xml_schema.h"
|
84
|
+
#include "ruby_xml_relaxng.h"
|
85
|
+
#include "ruby_xml_html_parser.h"
|
86
|
+
#include "ruby_xml_reader.h"
|
87
|
+
|
88
|
+
extern VALUE mLibXML;
|
89
|
+
extern VALUE mXML;
|
90
|
+
|
91
|
+
#endif
|
data/ext/libxml/ruby_xml_attr.c
CHANGED
@@ -1,485 +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
|
-
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 (
|
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
|
-
}
|
1
|
+
/* $Id: ruby_xml_attr.c 666 2008-12-07 00:16:50Z 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_namespace_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
|
+
}
|