libxml-ruby 2.0.0-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY +516 -0
- data/LICENSE +23 -0
- data/MANIFEST +165 -0
- data/README.rdoc +161 -0
- data/Rakefile +82 -0
- data/ext/libxml/extconf.rb +122 -0
- data/ext/libxml/libxml.c +93 -0
- data/ext/libxml/ruby_libxml.h +101 -0
- data/ext/libxml/ruby_xml.c +893 -0
- data/ext/libxml/ruby_xml.h +10 -0
- data/ext/libxml/ruby_xml_attr.c +352 -0
- data/ext/libxml/ruby_xml_attr.h +14 -0
- data/ext/libxml/ruby_xml_attr_decl.c +171 -0
- data/ext/libxml/ruby_xml_attr_decl.h +13 -0
- data/ext/libxml/ruby_xml_attributes.c +277 -0
- data/ext/libxml/ruby_xml_attributes.h +17 -0
- data/ext/libxml/ruby_xml_cbg.c +85 -0
- data/ext/libxml/ruby_xml_document.c +958 -0
- data/ext/libxml/ruby_xml_document.h +17 -0
- data/ext/libxml/ruby_xml_dtd.c +257 -0
- data/ext/libxml/ruby_xml_dtd.h +9 -0
- data/ext/libxml/ruby_xml_encoding.c +221 -0
- data/ext/libxml/ruby_xml_encoding.h +16 -0
- data/ext/libxml/ruby_xml_error.c +1004 -0
- data/ext/libxml/ruby_xml_error.h +14 -0
- data/ext/libxml/ruby_xml_html_parser.c +92 -0
- data/ext/libxml/ruby_xml_html_parser.h +12 -0
- data/ext/libxml/ruby_xml_html_parser_context.c +308 -0
- data/ext/libxml/ruby_xml_html_parser_context.h +12 -0
- data/ext/libxml/ruby_xml_html_parser_options.c +40 -0
- data/ext/libxml/ruby_xml_html_parser_options.h +12 -0
- data/ext/libxml/ruby_xml_input_cbg.c +191 -0
- data/ext/libxml/ruby_xml_input_cbg.h +20 -0
- data/ext/libxml/ruby_xml_io.c +30 -0
- data/ext/libxml/ruby_xml_io.h +9 -0
- data/ext/libxml/ruby_xml_namespace.c +170 -0
- data/ext/libxml/ruby_xml_namespace.h +12 -0
- data/ext/libxml/ruby_xml_namespaces.c +295 -0
- data/ext/libxml/ruby_xml_namespaces.h +11 -0
- data/ext/libxml/ruby_xml_node.c +1386 -0
- data/ext/libxml/ruby_xml_node.h +13 -0
- data/ext/libxml/ruby_xml_parser.c +94 -0
- data/ext/libxml/ruby_xml_parser.h +14 -0
- data/ext/libxml/ruby_xml_parser_context.c +982 -0
- data/ext/libxml/ruby_xml_parser_context.h +12 -0
- data/ext/libxml/ruby_xml_parser_options.c +68 -0
- data/ext/libxml/ruby_xml_parser_options.h +14 -0
- data/ext/libxml/ruby_xml_reader.c +1057 -0
- data/ext/libxml/ruby_xml_reader.h +14 -0
- data/ext/libxml/ruby_xml_relaxng.c +111 -0
- data/ext/libxml/ruby_xml_relaxng.h +10 -0
- data/ext/libxml/ruby_xml_sax2_handler.c +334 -0
- data/ext/libxml/ruby_xml_sax2_handler.h +12 -0
- data/ext/libxml/ruby_xml_sax_parser.c +136 -0
- data/ext/libxml/ruby_xml_sax_parser.h +12 -0
- data/ext/libxml/ruby_xml_schema.c +159 -0
- data/ext/libxml/ruby_xml_schema.h +11 -0
- data/ext/libxml/ruby_xml_version.h +9 -0
- data/ext/libxml/ruby_xml_xinclude.c +18 -0
- data/ext/libxml/ruby_xml_xinclude.h +13 -0
- data/ext/libxml/ruby_xml_xpath.c +107 -0
- data/ext/libxml/ruby_xml_xpath.h +12 -0
- data/ext/libxml/ruby_xml_xpath_context.c +390 -0
- data/ext/libxml/ruby_xml_xpath_context.h +11 -0
- data/ext/libxml/ruby_xml_xpath_expression.c +83 -0
- data/ext/libxml/ruby_xml_xpath_expression.h +12 -0
- data/ext/libxml/ruby_xml_xpath_object.c +336 -0
- data/ext/libxml/ruby_xml_xpath_object.h +19 -0
- data/ext/libxml/ruby_xml_xpointer.c +101 -0
- data/ext/libxml/ruby_xml_xpointer.h +13 -0
- data/ext/mingw/Rakefile +34 -0
- data/ext/mingw/build.rake +41 -0
- data/ext/vc/libxml_ruby.sln +26 -0
- data/lib/1.8/libxml_ruby.so +0 -0
- data/lib/1.9/libxml_ruby.so +0 -0
- data/lib/libxml.rb +30 -0
- data/lib/libxml/attr.rb +113 -0
- data/lib/libxml/attr_decl.rb +80 -0
- data/lib/libxml/attributes.rb +14 -0
- data/lib/libxml/document.rb +192 -0
- data/lib/libxml/error.rb +90 -0
- data/lib/libxml/hpricot.rb +78 -0
- data/lib/libxml/html_parser.rb +96 -0
- data/lib/libxml/namespace.rb +62 -0
- data/lib/libxml/namespaces.rb +38 -0
- data/lib/libxml/node.rb +399 -0
- data/lib/libxml/ns.rb +22 -0
- data/lib/libxml/parser.rb +367 -0
- data/lib/libxml/properties.rb +23 -0
- data/lib/libxml/reader.rb +29 -0
- data/lib/libxml/sax_callbacks.rb +180 -0
- data/lib/libxml/sax_parser.rb +58 -0
- data/lib/libxml/tree.rb +29 -0
- data/lib/libxml/xpath_object.rb +16 -0
- data/lib/xml.rb +16 -0
- data/lib/xml/libxml.rb +10 -0
- data/libxml-ruby.gemspec +50 -0
- data/script/benchmark/depixelate +634 -0
- data/script/benchmark/hamlet.xml +9055 -0
- data/script/benchmark/parsecount +170 -0
- data/script/benchmark/sock_entries.xml +507 -0
- data/script/benchmark/throughput +41 -0
- data/script/test +6 -0
- data/setup.rb +1585 -0
- data/test/etc_doc_to_s.rb +21 -0
- data/test/ets_doc_file.rb +17 -0
- data/test/ets_doc_to_s.rb +23 -0
- data/test/ets_gpx.rb +28 -0
- data/test/ets_node_gc.rb +23 -0
- data/test/ets_test.xml +2 -0
- data/test/ets_tsr.rb +11 -0
- data/test/model/atom.xml +13 -0
- data/test/model/bands.iso-8859-1.xml +5 -0
- data/test/model/bands.utf-8.xml +5 -0
- data/test/model/bands.xml +5 -0
- data/test/model/books.xml +146 -0
- data/test/model/merge_bug_data.xml +58 -0
- data/test/model/ruby-lang.html +238 -0
- data/test/model/rubynet.xml +79 -0
- data/test/model/rubynet_project +1 -0
- data/test/model/shiporder.rnc +28 -0
- data/test/model/shiporder.rng +86 -0
- data/test/model/shiporder.xml +23 -0
- data/test/model/shiporder.xsd +31 -0
- data/test/model/soap.xml +27 -0
- data/test/model/xinclude.xml +5 -0
- data/test/rb-magic-comment.rb +33 -0
- data/test/tc_attr.rb +181 -0
- data/test/tc_attr_decl.rb +133 -0
- data/test/tc_attributes.rb +135 -0
- data/test/tc_deprecated_require.rb +13 -0
- data/test/tc_document.rb +119 -0
- data/test/tc_document_write.rb +187 -0
- data/test/tc_dtd.rb +125 -0
- data/test/tc_error.rb +138 -0
- data/test/tc_html_parser.rb +140 -0
- data/test/tc_namespace.rb +62 -0
- data/test/tc_namespaces.rb +177 -0
- data/test/tc_node.rb +258 -0
- data/test/tc_node_cdata.rb +51 -0
- data/test/tc_node_comment.rb +33 -0
- data/test/tc_node_copy.rb +42 -0
- data/test/tc_node_edit.rb +160 -0
- data/test/tc_node_text.rb +71 -0
- data/test/tc_node_write.rb +108 -0
- data/test/tc_node_xlink.rb +29 -0
- data/test/tc_parser.rb +336 -0
- data/test/tc_parser_context.rb +189 -0
- data/test/tc_properties.rb +39 -0
- data/test/tc_reader.rb +298 -0
- data/test/tc_relaxng.rb +54 -0
- data/test/tc_sax_parser.rb +276 -0
- data/test/tc_schema.rb +53 -0
- data/test/tc_traversal.rb +222 -0
- data/test/tc_xinclude.rb +21 -0
- data/test/tc_xml.rb +226 -0
- data/test/tc_xpath.rb +195 -0
- data/test/tc_xpath_context.rb +80 -0
- data/test/tc_xpath_expression.rb +38 -0
- data/test/tc_xpointer.rb +74 -0
- data/test/test_helper.rb +14 -0
- data/test/test_suite.rb +39 -0
- metadata +254 -0
@@ -0,0 +1,352 @@
|
|
1
|
+
/* $Id$ */
|
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 'test_helper'
|
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 rxml_str_new2((const char*) xattr->name, xattr->doc->encoding);
|
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 = rxml_str_new2((const char*) value, xattr->doc->encoding);
|
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
|
+
}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
/* $Id$ */
|
2
|
+
|
3
|
+
/* Please see the LICENSE file for copyright and distribution information */
|
4
|
+
|
5
|
+
#ifndef __RXML_ATTR__
|
6
|
+
#define __RXML_ATTR__
|
7
|
+
|
8
|
+
extern VALUE cXMLAttr;
|
9
|
+
|
10
|
+
void rxml_init_attr(void);
|
11
|
+
VALUE rxml_attr_wrap(xmlAttrPtr xattr);
|
12
|
+
VALUE rxml_attr_value_get(VALUE self);
|
13
|
+
VALUE rxml_attr_value_set(VALUE self, VALUE val);
|
14
|
+
#endif
|
@@ -0,0 +1,171 @@
|
|
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::AttrDecl
|
7
|
+
*
|
8
|
+
* At attribute declaration is used in XML::Dtds to define
|
9
|
+
* what attributes are allowed on an element. An attribute
|
10
|
+
* declaration defines an attribues name, data type and default
|
11
|
+
* value (if any).
|
12
|
+
*/
|
13
|
+
|
14
|
+
#include "ruby_libxml.h"
|
15
|
+
|
16
|
+
VALUE cXMLAttrDecl;
|
17
|
+
|
18
|
+
void rxml_attr_decl_mark(xmlAttributePtr xattr)
|
19
|
+
{
|
20
|
+
if (xattr->_private == NULL)
|
21
|
+
{
|
22
|
+
rb_warning("AttrDecl is not bound! (%s:%d)", __FILE__, __LINE__);
|
23
|
+
return;
|
24
|
+
}
|
25
|
+
|
26
|
+
rxml_node_mark((xmlNodePtr) xattr);
|
27
|
+
}
|
28
|
+
|
29
|
+
VALUE rxml_attr_decl_wrap(xmlAttributePtr xattr)
|
30
|
+
{
|
31
|
+
VALUE result;
|
32
|
+
|
33
|
+
// This node is already wrapped
|
34
|
+
if (xattr->_private != NULL)
|
35
|
+
return (VALUE) xattr->_private;
|
36
|
+
|
37
|
+
result = Data_Wrap_Struct(cXMLAttrDecl, rxml_attr_decl_mark, NULL, xattr);
|
38
|
+
|
39
|
+
xattr->_private = (void*) result;
|
40
|
+
|
41
|
+
return result;
|
42
|
+
}
|
43
|
+
|
44
|
+
/*
|
45
|
+
* call-seq:
|
46
|
+
* attr_decl.doc -> XML::Document
|
47
|
+
*
|
48
|
+
* Returns this attribute declaration's document.
|
49
|
+
*/
|
50
|
+
static VALUE rxml_attr_decl_doc_get(VALUE self)
|
51
|
+
{
|
52
|
+
xmlAttributePtr xattr;
|
53
|
+
Data_Get_Struct(self, xmlAttribute, xattr);
|
54
|
+
if (xattr->doc == NULL)
|
55
|
+
return Qnil;
|
56
|
+
else
|
57
|
+
return rxml_document_wrap(xattr->doc);
|
58
|
+
}
|
59
|
+
|
60
|
+
|
61
|
+
/*
|
62
|
+
* call-seq:
|
63
|
+
* attr_decl.name -> "name"
|
64
|
+
*
|
65
|
+
* Obtain this attribute declaration's name.
|
66
|
+
*/
|
67
|
+
static VALUE rxml_attr_decl_name_get(VALUE self)
|
68
|
+
{
|
69
|
+
xmlAttributePtr xattr;
|
70
|
+
Data_Get_Struct(self, xmlAttribute, xattr);
|
71
|
+
|
72
|
+
if (xattr->name == NULL)
|
73
|
+
return Qnil;
|
74
|
+
else
|
75
|
+
return rxml_str_new2((const char*) xattr->name, xattr->doc->encoding);
|
76
|
+
}
|
77
|
+
|
78
|
+
/*
|
79
|
+
* call-seq:
|
80
|
+
* attr_decl.next -> XML::AttrDecl
|
81
|
+
*
|
82
|
+
* Obtain the next attribute declaration.
|
83
|
+
*/
|
84
|
+
static VALUE rxml_attr_decl_next_get(VALUE self)
|
85
|
+
{
|
86
|
+
xmlAttributePtr xattr;
|
87
|
+
Data_Get_Struct(self, xmlAttribute, xattr);
|
88
|
+
if (xattr->next == NULL)
|
89
|
+
return Qnil;
|
90
|
+
else
|
91
|
+
return rxml_attr_decl_wrap((xmlAttributePtr)xattr->next);
|
92
|
+
}
|
93
|
+
|
94
|
+
/*
|
95
|
+
* call-seq:
|
96
|
+
* attr_decl.type -> num
|
97
|
+
*
|
98
|
+
* Obtain this attribute declaration's type node type.
|
99
|
+
*/
|
100
|
+
static VALUE rxml_attr_decl_node_type(VALUE self)
|
101
|
+
{
|
102
|
+
xmlAttrPtr xattr;
|
103
|
+
Data_Get_Struct(self, xmlAttr, xattr);
|
104
|
+
return INT2NUM(xattr->type);
|
105
|
+
}
|
106
|
+
|
107
|
+
/*
|
108
|
+
* call-seq:
|
109
|
+
* attr_decl.parent -> XML::Dtd
|
110
|
+
*
|
111
|
+
* Obtain this attribute declaration's parent which
|
112
|
+
* is an instance of a XML::DTD.
|
113
|
+
*/
|
114
|
+
static VALUE rxml_attr_decl_parent_get(VALUE self)
|
115
|
+
{
|
116
|
+
xmlAttributePtr xattr;
|
117
|
+
Data_Get_Struct(self, xmlAttribute, xattr);
|
118
|
+
|
119
|
+
if (xattr->parent == NULL)
|
120
|
+
return Qnil;
|
121
|
+
else
|
122
|
+
return rxml_dtd_wrap(xattr->parent);
|
123
|
+
}
|
124
|
+
|
125
|
+
/*
|
126
|
+
* call-seq:
|
127
|
+
* attr_decl.prev -> (XML::AttrDecl | XML::ElementDecl)
|
128
|
+
*
|
129
|
+
* Obtain the previous attribute declaration or the owning
|
130
|
+
* element declration (not implemented).
|
131
|
+
*/
|
132
|
+
static VALUE rxml_attr_decl_prev_get(VALUE self)
|
133
|
+
{
|
134
|
+
xmlAttributePtr xattr;
|
135
|
+
Data_Get_Struct(self, xmlAttribute, xattr);
|
136
|
+
|
137
|
+
if (xattr->prev == NULL)
|
138
|
+
return Qnil;
|
139
|
+
else
|
140
|
+
return rxml_attr_decl_wrap((xmlAttributePtr)xattr->prev);
|
141
|
+
}
|
142
|
+
|
143
|
+
/*
|
144
|
+
* call-seq:
|
145
|
+
* attr_decl.value -> "value"
|
146
|
+
*
|
147
|
+
* Obtain the default value of this attribute declaration.
|
148
|
+
*/
|
149
|
+
VALUE rxml_attr_decl_value_get(VALUE self)
|
150
|
+
{
|
151
|
+
xmlAttributePtr xattr;
|
152
|
+
|
153
|
+
Data_Get_Struct(self, xmlAttribute, xattr);
|
154
|
+
|
155
|
+
if (xattr->defaultValue)
|
156
|
+
return rxml_str_new2((const char *)xattr->defaultValue, xattr->doc->encoding);
|
157
|
+
else
|
158
|
+
return Qnil;
|
159
|
+
}
|
160
|
+
|
161
|
+
void rxml_init_attr_decl(void)
|
162
|
+
{
|
163
|
+
cXMLAttrDecl = rb_define_class_under(mXML, "AttrDecl", rb_cObject);
|
164
|
+
rb_define_method(cXMLAttrDecl, "doc", rxml_attr_decl_doc_get, 0);
|
165
|
+
rb_define_method(cXMLAttrDecl, "name", rxml_attr_decl_name_get, 0);
|
166
|
+
rb_define_method(cXMLAttrDecl, "next", rxml_attr_decl_next_get, 0);
|
167
|
+
rb_define_method(cXMLAttrDecl, "node_type", rxml_attr_decl_node_type, 0);
|
168
|
+
rb_define_method(cXMLAttrDecl, "parent", rxml_attr_decl_parent_get, 0);
|
169
|
+
rb_define_method(cXMLAttrDecl, "prev", rxml_attr_decl_prev_get, 0);
|
170
|
+
rb_define_method(cXMLAttrDecl, "value", rxml_attr_decl_value_get, 0);
|
171
|
+
}
|