libxml-ruby 0.6.0-x86-mswin32-60

Sign up to get free protection for your applications and to get access to all the features.
Files changed (127) hide show
  1. data/CHANGES +122 -0
  2. data/LICENSE +23 -0
  3. data/README +144 -0
  4. data/ext/libxml/cbg.c +76 -0
  5. data/ext/libxml/extconf.rb +308 -0
  6. data/ext/libxml/libxml.c +62 -0
  7. data/ext/libxml/ruby_libxml.h +93 -0
  8. data/ext/libxml/ruby_xml_attr.c +405 -0
  9. data/ext/libxml/ruby_xml_attr.h +19 -0
  10. data/ext/libxml/ruby_xml_document.c +1111 -0
  11. data/ext/libxml/ruby_xml_document.h +27 -0
  12. data/ext/libxml/ruby_xml_dtd.c +168 -0
  13. data/ext/libxml/ruby_xml_dtd.h +17 -0
  14. data/ext/libxml/ruby_xml_html_parser.c +449 -0
  15. data/ext/libxml/ruby_xml_html_parser.h +29 -0
  16. data/ext/libxml/ruby_xml_input_cbg.c +158 -0
  17. data/ext/libxml/ruby_xml_input_cbg.h +20 -0
  18. data/ext/libxml/ruby_xml_node.c +2410 -0
  19. data/ext/libxml/ruby_xml_node.h +27 -0
  20. data/ext/libxml/ruby_xml_node_set.c +170 -0
  21. data/ext/libxml/ruby_xml_node_set.h +20 -0
  22. data/ext/libxml/ruby_xml_ns.c +153 -0
  23. data/ext/libxml/ruby_xml_ns.h +21 -0
  24. data/ext/libxml/ruby_xml_parser.c +1425 -0
  25. data/ext/libxml/ruby_xml_parser.h +31 -0
  26. data/ext/libxml/ruby_xml_parser_context.c +750 -0
  27. data/ext/libxml/ruby_xml_parser_context.h +22 -0
  28. data/ext/libxml/ruby_xml_reader.c +900 -0
  29. data/ext/libxml/ruby_xml_reader.h +14 -0
  30. data/ext/libxml/ruby_xml_sax_parser.c +485 -0
  31. data/ext/libxml/ruby_xml_sax_parser.h +56 -0
  32. data/ext/libxml/ruby_xml_schema.c +146 -0
  33. data/ext/libxml/ruby_xml_schema.h +16 -0
  34. data/ext/libxml/ruby_xml_state.c +113 -0
  35. data/ext/libxml/ruby_xml_state.h +12 -0
  36. data/ext/libxml/ruby_xml_tree.c +43 -0
  37. data/ext/libxml/ruby_xml_tree.h +12 -0
  38. data/ext/libxml/ruby_xml_xinclude.c +20 -0
  39. data/ext/libxml/ruby_xml_xinclude.h +13 -0
  40. data/ext/libxml/ruby_xml_xpath.c +243 -0
  41. data/ext/libxml/ruby_xml_xpath.h +23 -0
  42. data/ext/libxml/ruby_xml_xpath_context.c +118 -0
  43. data/ext/libxml/ruby_xml_xpath_context.h +20 -0
  44. data/ext/libxml/ruby_xml_xpath_object.c +293 -0
  45. data/ext/libxml/ruby_xml_xpath_object.h +28 -0
  46. data/ext/libxml/ruby_xml_xpointer.c +100 -0
  47. data/ext/libxml/ruby_xml_xpointer.h +27 -0
  48. data/ext/libxml/ruby_xml_xpointer_context.c +21 -0
  49. data/ext/libxml/ruby_xml_xpointer_context.h +18 -0
  50. data/ext/libxml/sax_parser_callbacks.inc +213 -0
  51. data/ext/libxml/version.h +9 -0
  52. data/lib/libxml.rb +125 -0
  53. data/lib/libxml_ruby.so +0 -0
  54. data/lib/xml/libxml.rb +5 -0
  55. data/mingw/libiconv-2.dll +0 -0
  56. data/mingw/libxml2-2.dll +0 -0
  57. data/mingw/libxml_ruby.so +0 -0
  58. data/mingw/mingw.rake +36 -0
  59. data/test/dtd-test.rb +24 -0
  60. data/test/etc_doc_to_s.rb +19 -0
  61. data/test/ets_copy_bug.rb +21 -0
  62. data/test/ets_copy_bug2.rb +32 -0
  63. data/test/ets_copy_bug3.rb +38 -0
  64. data/test/ets_doc_file.rb +15 -0
  65. data/test/ets_doc_to_s.rb +21 -0
  66. data/test/ets_gpx.rb +26 -0
  67. data/test/ets_node_gc.rb +21 -0
  68. data/test/ets_test.xml +2 -0
  69. data/test/ets_tsr.rb +9 -0
  70. data/test/gc.log +0 -0
  71. data/test/merge_bug.rb +55 -0
  72. data/test/schema-test.rb +74 -0
  73. data/test/tc_well_formed.rb +11 -0
  74. data/test/tc_xml_document.rb +52 -0
  75. data/test/tc_xml_document_write.rb +24 -0
  76. data/test/tc_xml_document_write2.rb +54 -0
  77. data/test/tc_xml_document_write3.rb +96 -0
  78. data/test/tc_xml_html_parser.rb +63 -0
  79. data/test/tc_xml_node.rb +59 -0
  80. data/test/tc_xml_node2.rb +25 -0
  81. data/test/tc_xml_node3.rb +27 -0
  82. data/test/tc_xml_node4.rb +86 -0
  83. data/test/tc_xml_node5.rb +52 -0
  84. data/test/tc_xml_node6.rb +27 -0
  85. data/test/tc_xml_node7.rb +35 -0
  86. data/test/tc_xml_node8.rb +32 -0
  87. data/test/tc_xml_node9.rb +32 -0
  88. data/test/tc_xml_node_copy.rb +40 -0
  89. data/test/tc_xml_node_set.rb +24 -0
  90. data/test/tc_xml_node_set2.rb +37 -0
  91. data/test/tc_xml_node_text.rb +17 -0
  92. data/test/tc_xml_node_xlink.rb +28 -0
  93. data/test/tc_xml_parser.rb +190 -0
  94. data/test/tc_xml_parser2.rb +16 -0
  95. data/test/tc_xml_parser3.rb +23 -0
  96. data/test/tc_xml_parser4.rb +33 -0
  97. data/test/tc_xml_parser5.rb +27 -0
  98. data/test/tc_xml_parser6.rb +23 -0
  99. data/test/tc_xml_parser7.rb +28 -0
  100. data/test/tc_xml_parser8.rb +32 -0
  101. data/test/tc_xml_parser9.rb +11 -0
  102. data/test/tc_xml_parser_context.rb +88 -0
  103. data/test/tc_xml_reader.rb +112 -0
  104. data/test/tc_xml_sax_parser.rb +104 -0
  105. data/test/tc_xml_sax_parser2.rb +51 -0
  106. data/test/tc_xml_xinclude.rb +30 -0
  107. data/test/tc_xml_xpath.rb +38 -0
  108. data/test/tc_xml_xpath2.rb +14 -0
  109. data/test/tc_xml_xpointer.rb +78 -0
  110. data/vc/libxml.sln +20 -0
  111. data/vc/libxml.vcproj +389 -0
  112. data/work/Rakefile +247 -0
  113. data/work/task/make +26 -0
  114. data/work/task/memory +37 -0
  115. data/work/task/rdoc +39 -0
  116. data/work/task/setup +1616 -0
  117. data/work/task/test +29 -0
  118. data/work/test/ets_runner.rb +33 -0
  119. data/work/test/libxml_test.rb +3 -0
  120. data/work/test/runner.rb +0 -0
  121. data/work/test/runner_ets.rb +33 -0
  122. data/work/vc/debug/libxml.exp +0 -0
  123. data/work/vc/debug/libxml.ilk +0 -0
  124. data/work/vc/debug/libxml.lib +0 -0
  125. data/work/vc/debug/libxml.pdb +0 -0
  126. data/work/vc/debug/libxml.so +0 -0
  127. metadata +224 -0
@@ -0,0 +1,62 @@
1
+ /* $Id: libxml.c 300 2008-07-01 19:14:15Z cfis $ */
2
+
3
+ /* Please see the LICENSE file for copyright and distribution information */
4
+
5
+ #include "ruby_libxml.h"
6
+
7
+ VALUE mXML;
8
+ VALUE eXMLError;
9
+
10
+ static xmlFreeFunc freeFunc = NULL;
11
+ static xmlMallocFunc mallocFunc = NULL;
12
+ static xmlReallocFunc reallocFunc = NULL;
13
+ static xmlStrdupFunc strdupFunc = NULL;
14
+
15
+ #if defined(_WIN32)
16
+ __declspec(dllexport)
17
+ #endif
18
+
19
+ void
20
+ Init_libxml_ruby(void) {
21
+ /* Some libxml memory goo that should be done before anything else */
22
+ #ifdef NONE
23
+ xmlMemGet((xmlFreeFunc *) & freeFunc,
24
+ (xmlMallocFunc *) & mallocFunc,
25
+ (xmlReallocFunc *) & reallocFunc,
26
+ (xmlStrdupFunc *) & strdupFunc);
27
+
28
+ if (xmlMemSetup((xmlFreeFunc)RubyMemFree, (xmlMallocFunc)RubyMemMalloc,
29
+ (xmlReallocFunc)RubyMemRealloc, (xmlStrdupFunc)RubyMemStrdup) != 0)
30
+ rb_fatal("could not install the memory handlers for libxml");
31
+ #endif
32
+ xmlInitParser();
33
+
34
+ mXML = rb_define_module("XML");
35
+ eXMLError = rb_define_class_under(mXML, "Error", rb_eRuntimeError);
36
+
37
+ rb_define_const(mXML, "XML_NAMESPACE", rb_str_new2((const char*)XML_XML_NAMESPACE));
38
+
39
+ ruby_init_state();
40
+ ruby_init_parser();
41
+ ruby_init_xml_parser_context();
42
+ ruby_init_xml_attr();
43
+ ruby_init_xml_document();
44
+ ruby_init_xml_node();
45
+ ruby_init_xml_node_set();
46
+ ruby_init_xml_ns();
47
+ ruby_init_xml_sax_parser();
48
+ ruby_init_xml_tree();
49
+ ruby_init_xml_xinclude();
50
+ ruby_init_xml_xpath();
51
+ ruby_init_xml_xpath_context();
52
+ ruby_init_xml_xpointer();
53
+ ruby_init_xml_xpointer_context();
54
+ ruby_init_html_parser();
55
+ ruby_init_input_callbacks();
56
+ ruby_init_xml_dtd();
57
+ ruby_init_xml_schema();
58
+ ruby_init_xml_reader();
59
+
60
+ ruby_xml_parser_default_substitute_entities_set(cXMLParser, Qtrue);
61
+ ruby_xml_parser_default_load_external_dtd_set(cXMLParser, Qtrue);
62
+ }
@@ -0,0 +1,93 @@
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
+ // Maybe not yet defined in ruby
23
+ #ifndef RSTRING_LEN
24
+ #define RSTRING_LEN(x) RSTRING(x)->len
25
+ #endif
26
+
27
+ // not in Ruby 1.9
28
+ #ifndef GetWriteFile
29
+ #define GetWriteFile(fp) rb_io_stdio_file(fp)
30
+ #define OpenFile rb_io_t
31
+ #endif
32
+
33
+ #ifdef LIBXML_DEBUG_ENABLED
34
+ #include <libxml/xpathInternals.h>
35
+ #endif
36
+ #ifdef LIBXML_XINCLUDE_ENABLED
37
+ #include <libxml/xinclude.h>
38
+ #endif
39
+ #ifdef LIBXML_XPTR_ENABLED
40
+ #include <libxml/xpointer.h>
41
+ #endif
42
+
43
+ #define RUBY_LIBXML_SRC_TYPE_NULL 0
44
+ #define RUBY_LIBXML_SRC_TYPE_FILE 1
45
+ #define RUBY_LIBXML_SRC_TYPE_STRING 2
46
+ #define RUBY_LIBXML_SRC_TYPE_IO 3
47
+ #define RUBY_LIBXML_SRC_TYPE_XPATH 4
48
+
49
+ typedef struct rx_file_data {
50
+ VALUE filename; /* Filename/path to self */
51
+ } rx_file_data;
52
+
53
+ typedef struct rx_io_data {
54
+ VALUE io;
55
+ } rx_io_data;
56
+
57
+ typedef struct rx_string_data {
58
+ VALUE str;
59
+ } rx_string_data;
60
+
61
+ typedef struct rx_xpath_data {
62
+ VALUE ctxt;
63
+ } rx_xpath_data;
64
+
65
+ #include "ruby_xml_state.h"
66
+ #include "ruby_xml_attr.h"
67
+ #include "ruby_xml_document.h"
68
+ #include "ruby_xml_node.h"
69
+ #include "ruby_xml_node_set.h"
70
+ #include "ruby_xml_ns.h"
71
+ #include "ruby_xml_parser.h"
72
+ #include "ruby_xml_parser_context.h"
73
+ #include "ruby_xml_sax_parser.h"
74
+ #include "ruby_xml_tree.h"
75
+ #include "ruby_xml_xinclude.h"
76
+ #include "ruby_xml_xpath.h"
77
+ #include "ruby_xml_xpath_context.h"
78
+ #include "ruby_xml_xpath_object.h"
79
+ #include "ruby_xml_xpointer.h"
80
+ #include "ruby_xml_xpointer_context.h"
81
+ #include "ruby_xml_input_cbg.h"
82
+ #include "ruby_xml_dtd.h"
83
+ #include "ruby_xml_schema.h"
84
+ #include "ruby_xml_html_parser.h"
85
+ #include "ruby_xml_reader.h"
86
+
87
+ extern VALUE mXML;
88
+ extern VALUE eXMLError;
89
+
90
+ void ruby_init_parser(void);
91
+ void ruby_xml_parser_free(ruby_xml_parser *rxp);
92
+
93
+ #endif
@@ -0,0 +1,405 @@
1
+ /* $Id: ruby_xml_attr.c 300 2008-07-01 19:14:15Z cfis $ */
2
+
3
+ /* Please see the LICENSE file for copyright and distribution information */
4
+
5
+ #include "ruby_libxml.h"
6
+ #include "ruby_xml_attr.h"
7
+
8
+ VALUE cXMLAttr;
9
+
10
+ void ruby_xml_attr_free(ruby_xml_attr_t *rx) {
11
+ if (rx == NULL ) return;
12
+
13
+ if (rx->attr != NULL ) {
14
+ rx->attr->_private=NULL;
15
+ if (rx->attr->parent == NULL && rx->attr->doc == NULL ) {
16
+ #ifdef NODE_DEBUG
17
+ fprintf(stderr,"ruby_xfree rxn=0x%x xn=0x%x o=0x%x\n",(long)rxn,(long)rxn->node,(long)rxn->node->_private);
18
+ #endif
19
+ xmlFreeProp(rx->attr);
20
+ }
21
+
22
+ rx->attr=NULL;
23
+ }
24
+
25
+ ruby_xfree(rx);
26
+ }
27
+
28
+ void
29
+ ruby_xml_attr_mark(ruby_xml_attr_t *rx) {
30
+ if ( rx == NULL ) return;
31
+ if ( rx->attr == NULL ) return;
32
+
33
+ if (rx->attr->_private == NULL ) {
34
+ rb_warning("XmlAttr is not bound! (%s:%d)",
35
+ __FILE__,__LINE__);
36
+ return;
37
+ }
38
+
39
+ ruby_xml_node_mark_common((xmlNodePtr)rx->attr);
40
+ }
41
+
42
+ VALUE
43
+ ruby_xml_attr_wrap(VALUE class, xmlAttrPtr xnode)
44
+ {
45
+ VALUE obj;
46
+ ruby_xml_attr_t *rx;
47
+
48
+ // This node is already wrapped
49
+ if (xnode->_private != NULL)
50
+ return (VALUE)xnode->_private;
51
+
52
+ obj=Data_Make_Struct(class,ruby_xml_attr_t,ruby_xml_attr_mark,
53
+ ruby_xml_attr_free,rx);
54
+
55
+ rx->attr=xnode;
56
+ xnode->_private=(void*)obj;
57
+ #ifdef NODE_DEBUG
58
+ fprintf(stderr,"wrap rxn=0x%x xn=0x%x o=0x%x\n",(long)rxn,(long)xnode,(long)obj);
59
+ #endif
60
+ return obj;
61
+ }
62
+
63
+ /*
64
+ * Only use this when a xmlAttr has just been created since
65
+ * oblitterates the _private. Not exposed to ruby interp.
66
+ */
67
+ VALUE
68
+ ruby_xml_attr_new(VALUE class, xmlAttrPtr xnode)
69
+ {
70
+ xnode->_private=NULL;
71
+ return ruby_xml_attr_wrap(class,xnode);
72
+ }
73
+ /*
74
+ * call-seq:
75
+ * attr.child => node
76
+ *
77
+ * Obtain this attribute's child attribute(s).
78
+ */
79
+ VALUE
80
+ ruby_xml_attr_child_get(VALUE self) {
81
+ ruby_xml_attr_t *rxa;
82
+ Data_Get_Struct(self, ruby_xml_attr_t, rxa);
83
+ if (rxa->attr->children == NULL)
84
+ return(Qnil);
85
+ else
86
+ return(ruby_xml_node2_wrap(cXMLNode, rxa->attr->children));
87
+ }
88
+
89
+
90
+ /*
91
+ * call-seq:
92
+ * attr.child? => (true|false)
93
+ *
94
+ * Determine whether this attribute has child attributes.
95
+ */
96
+ VALUE
97
+ ruby_xml_attr_child_q(VALUE self) {
98
+ ruby_xml_attr_t *rxa;
99
+ Data_Get_Struct(self, ruby_xml_attr_t, rxa);
100
+ if (rxa->attr->children == NULL)
101
+ return(Qfalse);
102
+ else
103
+ return(Qtrue);
104
+ }
105
+
106
+
107
+ /*
108
+ * call-seq:
109
+ * attr.doc => document
110
+ *
111
+ * Obtain the XML::Document this attribute is associated with,
112
+ * if any.
113
+ */
114
+ VALUE
115
+ ruby_xml_attr_doc_get(VALUE self) {
116
+ ruby_xml_attr_t *rxa;
117
+ Data_Get_Struct(self, ruby_xml_attr_t, rxa);
118
+ if (rxa->attr->doc == NULL)
119
+ return(Qnil);
120
+ else
121
+ return(ruby_xml_document_wrap(rxa->attr->doc));
122
+ }
123
+
124
+ /*
125
+ * call-seq:
126
+ * attr.doc? => (true|false)
127
+ *
128
+ * Determine whether this attribute is associated with an
129
+ * XML::Document.
130
+ */
131
+ VALUE
132
+ ruby_xml_attr_doc_q(VALUE self) {
133
+ ruby_xml_attr_t *rxa;
134
+ Data_Get_Struct(self, ruby_xml_attr_t, rxa);
135
+ if (rxa->attr->doc == NULL)
136
+ return(Qfalse);
137
+ else
138
+ return(Qtrue);
139
+ }
140
+
141
+
142
+ /*
143
+ * call-seq:
144
+ * attr.last => node
145
+ *
146
+ * Obtain the last attribute.
147
+ */
148
+ VALUE
149
+ ruby_xml_attr_last_get(VALUE self) {
150
+ ruby_xml_attr_t *rxa;
151
+ Data_Get_Struct(self, ruby_xml_attr_t, rxa);
152
+ if (rxa->attr->last == NULL)
153
+ return(Qnil);
154
+ else
155
+ return(ruby_xml_node2_wrap(cXMLNode, rxa->attr->last));
156
+ }
157
+
158
+
159
+ /*
160
+ * call-seq:
161
+ * attr.last? => (true|false)
162
+ *
163
+ * Determine whether this is the last attribute.
164
+ */
165
+ VALUE
166
+ ruby_xml_attr_last_q(VALUE self) {
167
+ ruby_xml_attr_t *rxa;
168
+ Data_Get_Struct(self, ruby_xml_attr_t, rxa);
169
+ if (rxa->attr->last == NULL)
170
+ return(Qfalse);
171
+ else
172
+ return(Qtrue);
173
+ }
174
+
175
+ /*
176
+ * call-seq:
177
+ * attr.name => "name"
178
+ *
179
+ * Obtain this attribute's name.
180
+ */
181
+ VALUE
182
+ ruby_xml_attr_name_get(VALUE self) {
183
+ ruby_xml_attr_t *rxa;
184
+ Data_Get_Struct(self, ruby_xml_attr_t, rxa);
185
+
186
+ if (rxa->attr->name == NULL)
187
+ return(Qnil);
188
+ else
189
+ return(rb_str_new2((const char*)rxa->attr->name));
190
+ }
191
+
192
+ /*
193
+ * call-seq:
194
+ * attr.next => node
195
+ *
196
+ * Obtain the next attribute.
197
+ */
198
+ VALUE
199
+ ruby_xml_attr_next_get(VALUE self) {
200
+ ruby_xml_attr_t *rxa;
201
+ Data_Get_Struct(self, ruby_xml_attr_t, rxa);
202
+ if (rxa->attr->next == NULL)
203
+ return(Qnil);
204
+ else
205
+ return(ruby_xml_attr_wrap(cXMLAttr, rxa->attr->next));
206
+ }
207
+
208
+
209
+ /*
210
+ * call-seq:
211
+ * attr.next? => (true|false)
212
+ *
213
+ * Determine whether there is a next attribute.
214
+ */
215
+ VALUE
216
+ ruby_xml_attr_next_q(VALUE self) {
217
+ ruby_xml_attr_t *rxa;
218
+ Data_Get_Struct(self, ruby_xml_attr_t, rxa);
219
+ if (rxa->attr->next == NULL)
220
+ return(Qfalse);
221
+ else
222
+ return(Qtrue);
223
+ }
224
+
225
+
226
+ /*
227
+ * call-seq:
228
+ * attr.type_name => "attribute"
229
+ *
230
+ * Obtain this attribute node's type name.
231
+ */
232
+ VALUE
233
+ ruby_xml_attr_node_type_name(VALUE self) {
234
+ return(rb_str_new2("attribute"));
235
+ }
236
+
237
+
238
+ /*
239
+ * call-seq:
240
+ * attr.ns => namespace
241
+ *
242
+ * Obtain this attribute's associated XML::NS, if any.
243
+ */
244
+ VALUE
245
+ ruby_xml_attr_ns_get(VALUE self) {
246
+ ruby_xml_attr_t *rxa;
247
+ Data_Get_Struct(self, ruby_xml_attr_t, rxa);
248
+ if (rxa->attr->ns == NULL)
249
+ return(Qnil);
250
+ else
251
+ return(ruby_xml_ns_new2(cXMLNS, Qnil, rxa->attr->ns));
252
+ }
253
+
254
+
255
+ /*
256
+ * call-seq:
257
+ * attr.ns? => (true|false)
258
+ *
259
+ * Determine whether this attribute has an associated
260
+ * namespace.
261
+ */
262
+ VALUE
263
+ ruby_xml_attr_ns_q(VALUE self) {
264
+ ruby_xml_attr_t *rxa;
265
+ Data_Get_Struct(self, ruby_xml_attr_t, rxa);
266
+ if (rxa->attr->ns == NULL)
267
+ return(Qfalse);
268
+ else
269
+ return(Qtrue);
270
+ }
271
+
272
+
273
+ /*
274
+ * call-seq:
275
+ * attr.parent => node
276
+ *
277
+ * Obtain this attribute node's parent.
278
+ */
279
+ VALUE
280
+ ruby_xml_attr_parent_get(VALUE self) {
281
+ ruby_xml_attr_t *rxa;
282
+ Data_Get_Struct(self, ruby_xml_attr_t, rxa);
283
+ if (rxa->attr->parent == NULL)
284
+ return(Qnil);
285
+ else
286
+ return(ruby_xml_node2_wrap(cXMLNode, rxa->attr->parent));
287
+ }
288
+
289
+
290
+ /*
291
+ * call-seq:
292
+ * attr.parent? => (true|false)
293
+ *
294
+ * Determine whether this attribute has a parent.
295
+ */
296
+ VALUE
297
+ ruby_xml_attr_parent_q(VALUE self) {
298
+ ruby_xml_attr_t *rxa;
299
+ Data_Get_Struct(self, ruby_xml_attr_t, rxa);
300
+ if (rxa->attr->parent == NULL)
301
+ return(Qfalse);
302
+ else
303
+ return(Qtrue);
304
+ }
305
+
306
+
307
+ /*
308
+ * call-seq:
309
+ * attr.prev => node
310
+ *
311
+ * Obtain the previous attribute.
312
+ */
313
+ VALUE
314
+ ruby_xml_attr_prev_get(VALUE self) {
315
+ ruby_xml_attr_t *rxa;
316
+ Data_Get_Struct(self, ruby_xml_attr_t, rxa);
317
+ if (rxa->attr->prev == NULL)
318
+ return(Qnil);
319
+ else
320
+ return(ruby_xml_attr_wrap(cXMLAttr, rxa->attr->prev));
321
+ }
322
+
323
+
324
+ /*
325
+ * call-seq:
326
+ * attr.prev? => (true|false)
327
+ *
328
+ * Determine whether there is a previous attribute.
329
+ */
330
+ VALUE
331
+ ruby_xml_attr_prev_q(VALUE self) {
332
+ ruby_xml_attr_t *rxa;
333
+ Data_Get_Struct(self, ruby_xml_attr_t, rxa);
334
+ if (rxa->attr->prev == NULL)
335
+ return(Qfalse);
336
+ else
337
+ return(Qtrue);
338
+ }
339
+
340
+
341
+ /*
342
+ * call-seq:
343
+ * node.remove! => nil
344
+ *
345
+ * Removes this attribute from it's parent.
346
+ */
347
+ VALUE
348
+ ruby_xml_attr_remove_ex(VALUE self) {
349
+ ruby_xml_attr_t *rxa;
350
+ Data_Get_Struct(self, ruby_xml_attr_t, rxa);
351
+ xmlUnlinkNode(rxa->attr);
352
+ return(Qnil);
353
+ }
354
+
355
+ /*
356
+ * call-seq:
357
+ * attr.value => "value"
358
+ *
359
+ * Obtain the value of this attribute.
360
+ */
361
+ VALUE
362
+ ruby_xml_attr_value(VALUE self) {
363
+ ruby_xml_attr_t *rxa;
364
+ xmlChar *value;
365
+ VALUE result = Qnil;
366
+
367
+ Data_Get_Struct(self, ruby_xml_attr_t, rxa);
368
+ if (ruby_xml_attr_parent_q(self) == Qtrue) {
369
+ value = xmlGetProp(rxa->attr->parent, rxa->attr->name);
370
+ if (value != NULL)
371
+ {
372
+ result = rb_str_new2((const char*)value);
373
+ xmlFree(value);
374
+ }
375
+ }
376
+ return(result);
377
+ }
378
+
379
+ // Rdoc needs to know
380
+ #ifdef RDOC_NEVER_DEFINED
381
+ mXML = rb_define_module("XML");
382
+ #endif
383
+
384
+ void
385
+ ruby_init_xml_attr(void) {
386
+ cXMLAttr = rb_define_class_under(mXML, "Attr", rb_cObject);
387
+ rb_define_method(cXMLAttr, "child", ruby_xml_attr_child_get, 0);
388
+ rb_define_method(cXMLAttr, "child?", ruby_xml_attr_child_q, 0);
389
+ rb_define_method(cXMLAttr, "doc", ruby_xml_attr_doc_get, 0);
390
+ rb_define_method(cXMLAttr, "doc?", ruby_xml_attr_doc_q, 0);
391
+ rb_define_method(cXMLAttr, "last", ruby_xml_attr_last_get, 0);
392
+ rb_define_method(cXMLAttr, "last?", ruby_xml_attr_last_q, 0);
393
+ rb_define_method(cXMLAttr, "name", ruby_xml_attr_name_get, 0);
394
+ rb_define_method(cXMLAttr, "next", ruby_xml_attr_next_get, 0);
395
+ rb_define_method(cXMLAttr, "next?", ruby_xml_attr_next_q, 0);
396
+ rb_define_method(cXMLAttr, "node_type_name", ruby_xml_attr_node_type_name, 0);
397
+ rb_define_method(cXMLAttr, "ns", ruby_xml_attr_ns_get, 0);
398
+ rb_define_method(cXMLAttr, "ns?", ruby_xml_attr_ns_q, 0);
399
+ rb_define_method(cXMLAttr, "parent", ruby_xml_attr_parent_get, 0);
400
+ rb_define_method(cXMLAttr, "parent?", ruby_xml_attr_parent_q, 0);
401
+ rb_define_method(cXMLAttr, "prev", ruby_xml_attr_prev_get, 0);
402
+ rb_define_method(cXMLAttr, "prev?", ruby_xml_attr_prev_q, 0);
403
+ rb_define_method(cXMLAttr, "remove!", ruby_xml_attr_remove_ex, 0);
404
+ rb_define_method(cXMLAttr, "value", ruby_xml_attr_value, 0);
405
+ }