ruby-xml-smart 0.1.11-i486-linux

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. data/AUTHORS +4 -0
  2. data/COPYING +504 -0
  3. data/Changelog +192 -0
  4. data/README +52 -0
  5. data/Rakefile +112 -0
  6. data/TODO +6 -0
  7. data/examples/EXAMPLE.xml +17 -0
  8. data/examples/EXAMPLE.xml.sic +17 -0
  9. data/examples/Visualise/EXAMPLE.xml +18 -0
  10. data/examples/Visualise/term-ansicolor-0.0.4/CHANGES +11 -0
  11. data/examples/Visualise/term-ansicolor-0.0.4/GPL +340 -0
  12. data/examples/Visualise/term-ansicolor-0.0.4/README.en +23 -0
  13. data/examples/Visualise/term-ansicolor-0.0.4/Rakefile +72 -0
  14. data/examples/Visualise/term-ansicolor-0.0.4/VERSION +1 -0
  15. data/examples/Visualise/term-ansicolor-0.0.4/examples/cdiff.rb +20 -0
  16. data/examples/Visualise/term-ansicolor-0.0.4/examples/example.rb +82 -0
  17. data/examples/Visualise/term-ansicolor-0.0.4/install.rb +12 -0
  18. data/examples/Visualise/term-ansicolor-0.0.4/lib/term/ansicolor.rb +78 -0
  19. data/examples/Visualise/xpath_visual.rb +45 -0
  20. data/examples/add_children.rb +14 -0
  21. data/examples/add_elements.rb +13 -0
  22. data/examples/attrs.rb +15 -0
  23. data/examples/children.rb +14 -0
  24. data/examples/concurrent.rb +30 -0
  25. data/examples/copy.rb +23 -0
  26. data/examples/create.rb +18 -0
  27. data/examples/delete.rb +30 -0
  28. data/examples/move_elements.rb +12 -0
  29. data/examples/namespace.rb +14 -0
  30. data/examples/namespace_detailed.rb +36 -0
  31. data/examples/namespace_find.rb +20 -0
  32. data/examples/pull.rb +18 -0
  33. data/examples/qname.rb +16 -0
  34. data/examples/replace.rb +14 -0
  35. data/examples/set_OR_replace.rb +32 -0
  36. data/examples/signals.rb +28 -0
  37. data/examples/string.rb +27 -0
  38. data/examples/write.rb +11 -0
  39. data/examples/xpath_attrs.rb +19 -0
  40. data/examples/xpath_functions.rb +7 -0
  41. data/examples/xpath_root.rb +6 -0
  42. data/extconf.rb +29 -0
  43. data/rbxs.c +136 -0
  44. data/rbxs.h +53 -0
  45. data/rbxs_dom.c +483 -0
  46. data/rbxs_dom.h +32 -0
  47. data/rbxs_domattribute.c +189 -0
  48. data/rbxs_domattribute.h +18 -0
  49. data/rbxs_domattributeset.c +182 -0
  50. data/rbxs_domattributeset.h +17 -0
  51. data/rbxs_domelement.c +656 -0
  52. data/rbxs_domelement.h +18 -0
  53. data/rbxs_domnamespace.c +127 -0
  54. data/rbxs_domnamespace.h +18 -0
  55. data/rbxs_domnamespaceset.c +276 -0
  56. data/rbxs_domnamespaceset.h +17 -0
  57. data/rbxs_domnodeset.c +284 -0
  58. data/rbxs_domnodeset.h +19 -0
  59. data/rbxs_domother.c +121 -0
  60. data/rbxs_domother.h +18 -0
  61. data/rbxs_domtext.c +165 -0
  62. data/rbxs_domtext.h +18 -0
  63. data/rbxs_pull.c +244 -0
  64. data/rbxs_pull.h +17 -0
  65. data/rbxs_pullattribute.c +124 -0
  66. data/rbxs_pullattribute.h +18 -0
  67. data/rbxs_pullattributeset.c +156 -0
  68. data/rbxs_pullattributeset.h +17 -0
  69. data/rbxs_qname.c +267 -0
  70. data/rbxs_qname.h +18 -0
  71. data/rbxs_utils.h +39 -0
  72. data/test/namespace_test.rb +83 -0
  73. metadata +125 -0
data/rbxs_pull.c ADDED
@@ -0,0 +1,244 @@
1
+ #include "rbxs_pull.h"
2
+ #include "rbxs_qname.h"
3
+ #include "rbxs_pullattributeset.h"
4
+
5
+ /* -- */
6
+ //***********************************************************************************
7
+ // GC
8
+ //***********************************************************************************
9
+ void rbxs_pull_free(rbxs_pull *prbxs_pull) {
10
+ if (prbxs_pull != NULL) {
11
+ xmlFreeTextReader(prbxs_pull->reader);
12
+ prbxs_pull->reader = NULL;
13
+ free(prbxs_pull);
14
+ }
15
+ }
16
+
17
+ void rbxs_pull_mark(rbxs_pull *prbxs_pull) { }
18
+
19
+ //***********************************************************************************
20
+ // Methods
21
+ //***********************************************************************************
22
+ /* ++ */
23
+
24
+ /*
25
+ * Documentation
26
+ */
27
+ VALUE rbxs_pull_next(VALUE self)
28
+ {
29
+ rbxs_pull *prbxs_pull;
30
+ Data_Get_Struct(self, rbxs_pull, prbxs_pull);
31
+ if (xmlTextReaderRead(prbxs_pull->reader) >= 1)
32
+ return self;
33
+ else
34
+ return Qnil;
35
+ }
36
+
37
+ /*
38
+ * Documentation
39
+ */
40
+ VALUE rbxs_pull_name(VALUE self)
41
+ {
42
+ return(rbxs_qname_new(cSmartQName,self,RBXS_PARSER_TYPE_READER));
43
+ }
44
+
45
+ /*
46
+ * Documentation
47
+ */
48
+ VALUE rbxs_pull_base(VALUE self)
49
+ {
50
+ unsigned char *base_uri;
51
+ rbxs_pull *prbxs_pull;
52
+
53
+ Data_Get_Struct(self, rbxs_pull, prbxs_pull);
54
+ base_uri = xmlTextReaderBaseUri(prbxs_pull->reader);
55
+ if (base_uri)
56
+ return(rb_str_new2((char *)base_uri));
57
+ else
58
+ return(Qnil);
59
+ }
60
+
61
+ /*
62
+ * Documentation
63
+ */
64
+ VALUE rbxs_pull_xml_lang(VALUE self)
65
+ {
66
+ unsigned char *xml_lang;
67
+ rbxs_pull *prbxs_pull;
68
+
69
+ Data_Get_Struct(self, rbxs_pull, prbxs_pull);
70
+ xml_lang = xmlTextReaderXmlLang(prbxs_pull->reader);
71
+ if (xml_lang)
72
+ return(rb_str_new2((char *)xml_lang));
73
+ else
74
+ return(Qnil);
75
+ }
76
+
77
+ /*
78
+ * Documentation
79
+ */
80
+ VALUE rbxs_pull_depth(VALUE self)
81
+ {
82
+ int depth;
83
+ rbxs_pull *prbxs_pull;
84
+
85
+ Data_Get_Struct(self, rbxs_pull, prbxs_pull);
86
+ depth = xmlTextReaderDepth(prbxs_pull->reader);
87
+ if (depth >= 0)
88
+ return(INT2FIX(depth));
89
+ else
90
+ return(Qnil);
91
+ }
92
+
93
+ /*
94
+ * Documentation
95
+ */
96
+ VALUE rbxs_pull_attributes(VALUE self)
97
+ {
98
+ return rbxs_pullattributeset_new(cSmartPullAttributeSet,self);
99
+ }
100
+
101
+ /*
102
+ * Documentation
103
+ */
104
+ VALUE rbxs_pull_emptyp(VALUE self)
105
+ {
106
+ rbxs_pull *prbxs_pull;
107
+
108
+ Data_Get_Struct(self, rbxs_pull, prbxs_pull);
109
+ return (xmlTextReaderIsEmptyElement(prbxs_pull->reader) ? Qtrue : Qfalse);
110
+ }
111
+
112
+ /*
113
+ * Documentation
114
+ */
115
+ VALUE rbxs_pull_valuep(VALUE self)
116
+ {
117
+ rbxs_pull *prbxs_pull;
118
+
119
+ Data_Get_Struct(self, rbxs_pull, prbxs_pull);
120
+ return (xmlTextReaderHasValue(prbxs_pull->reader) ? Qtrue : Qfalse);
121
+ }
122
+
123
+ /*
124
+ * Documentation
125
+ */
126
+ VALUE rbxs_pull_value(VALUE self)
127
+ {
128
+ rbxs_pull *prbxs_pull;
129
+ unsigned char *value;
130
+
131
+ Data_Get_Struct(self, rbxs_pull, prbxs_pull);
132
+ value = xmlTextReaderValue(prbxs_pull->reader);
133
+
134
+ if (value) {
135
+ VALUE retval = rb_str_new2((char *)value);
136
+ xmlFree(value);
137
+ return retval;
138
+ } else
139
+ return Qnil;
140
+ }
141
+
142
+ static VALUE type2symbol[18];
143
+
144
+ /*
145
+ * Documentation
146
+ */
147
+ VALUE rbxs_pull_node_type(VALUE self)
148
+ {
149
+ rbxs_pull *prbxs_pull;
150
+ int node_type;
151
+
152
+ Data_Get_Struct(self, rbxs_pull, prbxs_pull);
153
+ node_type = xmlTextReaderNodeType(prbxs_pull->reader);
154
+
155
+ if (node_type < 0)
156
+ return(Qnil);
157
+
158
+ return ID2SYM(type2symbol[node_type]);
159
+ }
160
+
161
+ //***********************************************************************************
162
+ // Constructors
163
+ //***********************************************************************************
164
+ VALUE rbxs_pull_new(VALUE class, VALUE what) {
165
+ rbxs_pull *prbxs_pull;
166
+ RB_IO_T *fptr;
167
+
168
+ prbxs_pull = (rbxs_pull *)malloc(sizeof(rbxs_pull));
169
+ if (prbxs_pull == NULL )
170
+ rb_raise(rb_eNoMemError, "No memory left for XML::Smart::Pull struct");
171
+
172
+ switch (TYPE(what)) {
173
+ case T_STRING:
174
+ prbxs_pull->reader = xmlReaderForMemory(RSTRING_PTR(what),
175
+ RSTRING_LEN(what),
176
+ NULL, NULL, 0);
177
+ break;
178
+ case T_FILE:
179
+ GetOpenFile(what,fptr);
180
+ prbxs_pull->reader = xmlReaderForFd(RB_IO_T_FD(fptr),NULL,NULL,0);
181
+ break;
182
+ default:
183
+ rb_raise(rb_eArgError, "argument must me String or File");
184
+ }
185
+
186
+ if (prbxs_pull->reader == NULL)
187
+ rb_raise(rb_eRuntimeError, "Document could not be opend");
188
+
189
+ if (rb_block_given_p()) {
190
+ VALUE self;
191
+ self = Data_Wrap_Struct(class, rbxs_pull_mark, rbxs_pull_free, prbxs_pull);
192
+ while (xmlTextReaderRead(prbxs_pull->reader)) {
193
+ rb_yield(self);
194
+ }
195
+ return(Qnil);
196
+ }
197
+
198
+ return(Data_Wrap_Struct(class, rbxs_pull_mark, rbxs_pull_free, prbxs_pull));
199
+ }
200
+
201
+ //***********************************************************************************
202
+ // Initialize class Pull
203
+ //***********************************************************************************
204
+ #ifdef RDOC__
205
+ mXML = rb_define_module( "XML" );
206
+ cSmart = rb_define_class_under( mXML, "Smart", rb_cObject );
207
+ #endif
208
+ VALUE cSmartPull;
209
+
210
+ void init_rbxs_pull(void) {
211
+ cSmartPull = rb_define_class_under( cSmart, "Pull", rb_cObject );
212
+
213
+ type2symbol[XML_READER_TYPE_NONE] = rb_intern("none");
214
+ type2symbol[XML_READER_TYPE_ELEMENT] = rb_intern("element");
215
+ type2symbol[XML_READER_TYPE_ATTRIBUTE] = rb_intern("attribute");
216
+ type2symbol[XML_READER_TYPE_TEXT] = rb_intern("text");
217
+ type2symbol[XML_READER_TYPE_CDATA] = rb_intern("cdata");
218
+ type2symbol[XML_READER_TYPE_ENTITY_REFERENCE] = rb_intern("entity_reference");
219
+ type2symbol[XML_READER_TYPE_ENTITY] = rb_intern("entity");
220
+ type2symbol[XML_READER_TYPE_PROCESSING_INSTRUCTION] = rb_intern("processing_instruction");
221
+ type2symbol[XML_READER_TYPE_COMMENT] = rb_intern("comment");
222
+ type2symbol[XML_READER_TYPE_DOCUMENT] = rb_intern("document");
223
+ type2symbol[XML_READER_TYPE_DOCUMENT_TYPE] = rb_intern("document_type");
224
+ type2symbol[XML_READER_TYPE_DOCUMENT_FRAGMENT] = rb_intern("document_fragment");
225
+ type2symbol[XML_READER_TYPE_NOTATION] = rb_intern("notation");
226
+ type2symbol[XML_READER_TYPE_WHITESPACE] = rb_intern("whitespace");
227
+ type2symbol[XML_READER_TYPE_SIGNIFICANT_WHITESPACE] = rb_intern("significant_whitespace");
228
+ type2symbol[XML_READER_TYPE_END_ELEMENT] = rb_intern("end_element");
229
+ type2symbol[XML_READER_TYPE_END_ENTITY] = rb_intern("end_entity");
230
+ type2symbol[XML_READER_TYPE_XML_DECLARATION] = rb_intern("xml_declaration");
231
+
232
+ rb_define_method(cSmartPull, "to_s", rbxs_pull_value, 0);
233
+ rb_define_method(cSmartPull, "next", rbxs_pull_next, 0);
234
+ rb_define_method(cSmartPull, "name", rbxs_pull_name, 0);
235
+
236
+ rb_define_method(cSmartPull, "base", rbxs_pull_base, 0);
237
+ rb_define_method(cSmartPull, "depth", rbxs_pull_depth, 0);
238
+ rb_define_method(cSmartPull, "attributes", rbxs_pull_attributes, 0);
239
+ rb_define_method(cSmartPull, "value?", rbxs_pull_valuep, 0);
240
+ rb_define_method(cSmartPull, "value", rbxs_pull_value, 0);
241
+ rb_define_method(cSmartPull, "empty?", rbxs_pull_emptyp, 0);
242
+ rb_define_method(cSmartPull, "lang", rbxs_pull_xml_lang, 0);
243
+ rb_define_method(cSmartPull, "node_type", rbxs_pull_node_type, 0);
244
+ }
data/rbxs_pull.h ADDED
@@ -0,0 +1,17 @@
1
+ /* Please see the COPYING file for copyright and distribution information */
2
+
3
+ #ifndef __RBXS_PULL_H__
4
+ #define __RBXS_PULL_H__
5
+
6
+ #include "rbxs.h"
7
+
8
+ RUBY_EXTERN VALUE cSmartPull;
9
+
10
+ typedef struct rbxs_pull {
11
+ xmlTextReaderPtr reader;
12
+ } rbxs_pull;
13
+
14
+ RUBY_EXTERN VALUE rbxs_pull_new(VALUE class, VALUE what);
15
+ RUBY_EXTERN void init_rbxs_pull(void);
16
+
17
+ #endif
@@ -0,0 +1,124 @@
1
+ #include "rbxs_pullattribute.h"
2
+ #include "rbxs_pullattributeset.h"
3
+ #include "rbxs_qname.h"
4
+ #include "rbxs_pull.h"
5
+
6
+ /* -- */
7
+ //***********************************************************************************
8
+ // GC
9
+ //***********************************************************************************
10
+ void rbxs_pullattribute_free(rbxs_pullattribute *prbxs_pullattribute) {
11
+ if (prbxs_pullattribute != NULL) {
12
+ free(prbxs_pullattribute);
13
+ }
14
+ }
15
+
16
+ void rbxs_pullattribute_mark(rbxs_pullattribute *prbxs_pullattribute) {
17
+ if (prbxs_pullattribute == NULL) return;
18
+ if (!NIL_P(prbxs_pullattribute->node)) rb_gc_mark(prbxs_pullattribute->node);
19
+ }
20
+
21
+ //***********************************************************************************
22
+ // Methods
23
+ //***********************************************************************************
24
+ /* ++ */
25
+ void searchPosition(xmlTextReaderPtr reader, VALUE which)
26
+ {
27
+ int position,length;
28
+
29
+ switch (TYPE(which)) {
30
+ case T_STRING:
31
+ if (!xmlTextReaderMoveToAttribute(reader,(unsigned char *)StringValuePtr(which))) {
32
+ xmlTextReaderMoveToElement(reader);
33
+ rb_raise(rb_eRuntimeError, "attribute could not be found");
34
+ }
35
+ break;
36
+ case T_FIXNUM:
37
+ position = NUM2INT(which);
38
+ length = xmlTextReaderAttributeCount(reader);
39
+ if (position < 0)
40
+ position = length + position;
41
+ if ((position >= 0) && (position < length)) {
42
+ if (!xmlTextReaderMoveToAttributeNo(reader,position)) {
43
+ xmlTextReaderMoveToElement(reader);
44
+ rb_raise(rb_eRuntimeError, "weird things occured");
45
+ }
46
+ } else
47
+ rb_raise(rb_eRuntimeError, "index out of range");
48
+ break;
49
+ default:
50
+ rb_raise(rb_eArgError, "argument must me String or a Fixnum");
51
+ }
52
+ }
53
+
54
+ /*
55
+ * Documentation
56
+ */
57
+ VALUE rbxs_pullattribute_name(VALUE self)
58
+ {
59
+ rbxs_pullattribute *prbxs_pullattribute;
60
+ rbxs_pull *prbxs_pull;
61
+
62
+ Data_Get_Struct(self, rbxs_pullattribute, prbxs_pullattribute);
63
+ Data_Get_Struct(prbxs_pullattribute->node, rbxs_pull, prbxs_pull);
64
+
65
+ searchPosition(prbxs_pull->reader,prbxs_pullattribute->which);
66
+ return(rbxs_qname_new(cSmartQName,prbxs_pullattribute->node,RBXS_PARSER_TYPE_READER));
67
+ }
68
+
69
+ /*
70
+ * Documentation
71
+ */
72
+ VALUE rbxs_pullattribute_value(VALUE self)
73
+ {
74
+ rbxs_pullattribute *prbxs_pullattribute;
75
+ rbxs_pull *prbxs_pull;
76
+ unsigned char *value;
77
+
78
+ Data_Get_Struct(self, rbxs_pullattribute, prbxs_pullattribute);
79
+ Data_Get_Struct(prbxs_pullattribute->node, rbxs_pull, prbxs_pull);
80
+
81
+ searchPosition(prbxs_pull->reader,prbxs_pullattribute->which);
82
+
83
+ value = xmlTextReaderValue(prbxs_pull->reader);
84
+ if (value) {
85
+ VALUE retval = rb_str_new2((char *)value);
86
+ xmlFree(value);
87
+ return retval;
88
+ } else
89
+ return Qnil;
90
+ return Qnil;
91
+ }
92
+
93
+ //***********************************************************************************
94
+ // Constructors
95
+ //***********************************************************************************
96
+ VALUE rbxs_pullattribute_new(VALUE class, VALUE node, VALUE which) {
97
+ rbxs_pullattribute *prbxs_pullattribute;
98
+
99
+ prbxs_pullattribute = (rbxs_pullattribute *)malloc(sizeof(rbxs_pullattribute));
100
+ if (prbxs_pullattribute == NULL )
101
+ rb_raise(rb_eNoMemError, "No memory left for XML::Smart::Pull::AttributeSet::Attribute struct");
102
+
103
+ prbxs_pullattribute->node = node;
104
+ prbxs_pullattribute->which = which;
105
+
106
+ return(Data_Wrap_Struct(class, rbxs_pullattribute_mark, rbxs_pullattribute_free, prbxs_pullattribute));
107
+ }
108
+
109
+ //***********************************************************************************
110
+ // Initialize class Node
111
+ //***********************************************************************************
112
+ #ifdef RDOC__
113
+ mXML = rb_define_module( "XML" );
114
+ cSmart = rb_define_class_under( mXML, "Smart", rb_cObject );
115
+ cSmartPull = rb_define_class_under( cSmart, "Pull", rb_cObject );
116
+ cSmartPullAttributeSet = rb_define_class_under( cSmartPull, "AttributeSet", rb_cObject );
117
+ #endif
118
+ VALUE cSmartPullAttribute;
119
+ void init_rbxs_pullattribute(void) {
120
+ cSmartPullAttribute = rb_define_class_under( cSmartPullAttributeSet, "Attribute", rb_cObject );
121
+
122
+ rb_define_method(cSmartPullAttribute, "name", rbxs_pullattribute_name, 0);
123
+ rb_define_method(cSmartPullAttribute, "value", rbxs_pullattribute_value, 0);
124
+ }
@@ -0,0 +1,18 @@
1
+ /* Please see the COPYING file for copyright and distribution information */
2
+
3
+ #ifndef __RBXS_PULLATTRIBUTE_H__
4
+ #define __RBXS_PULLATTRIBUTE_H__
5
+
6
+ #include "rbxs.h"
7
+
8
+ RUBY_EXTERN VALUE cSmartPullAttribute;
9
+
10
+ typedef struct rbxs_pullattribute {
11
+ VALUE node;
12
+ VALUE which;
13
+ } rbxs_pullattribute;
14
+
15
+ RUBY_EXTERN VALUE rbxs_pullattribute_new(VALUE class, VALUE node, VALUE which);
16
+ RUBY_EXTERN void init_rbxs_pullattribute(void);
17
+
18
+ #endif
@@ -0,0 +1,156 @@
1
+ #include "rbxs_pullattributeset.h"
2
+ #include "rbxs_pullattribute.h"
3
+ #include "rbxs_qname.h"
4
+ #include "rbxs_pull.h"
5
+
6
+ /* -- */
7
+ //***********************************************************************************
8
+ // GC
9
+ //***********************************************************************************
10
+ void rbxs_pullattributeset_free(rbxs_pullattributeset *prbxs_pullattributeset)
11
+ {
12
+ if (prbxs_pullattributeset != NULL) {
13
+ free(prbxs_pullattributeset);
14
+ }
15
+ }
16
+
17
+ void rbxs_pullattributeset_mark(rbxs_pullattributeset *prbxs_pullattributeset)
18
+ {
19
+ if (prbxs_pullattributeset == NULL) return;
20
+ if (!NIL_P(prbxs_pullattributeset->node)) rb_gc_mark(prbxs_pullattributeset->node);
21
+ }
22
+
23
+ //***********************************************************************************
24
+ // Methods
25
+ //***********************************************************************************
26
+ /* ++ */
27
+
28
+ /*
29
+ * call-seq:
30
+ * include? => (true|false)
31
+ *
32
+ * Documentation
33
+ */
34
+ VALUE rbxs_pullattributeset_include(VALUE self, VALUE which)
35
+ {
36
+ rbxs_pullattributeset *prbxs_pullattributeset;
37
+ rbxs_pull *prbxs_pull;
38
+ Data_Get_Struct(self, rbxs_pullattributeset, prbxs_pullattributeset);
39
+ Data_Get_Struct(prbxs_pullattributeset->node, rbxs_pull, prbxs_pull);
40
+
41
+ Check_Type(which, T_STRING);
42
+
43
+ if (xmlTextReaderMoveToAttribute(prbxs_pull->reader,(unsigned char *)StringValuePtr(which)))
44
+ return(Qtrue);
45
+ else
46
+ return(Qfalse);
47
+ }
48
+
49
+ /*
50
+ * Documentation
51
+ */
52
+ VALUE rbxs_pullattributeset_empty(VALUE self)
53
+ {
54
+ rbxs_pullattributeset *prbxs_pullattributeset;
55
+ rbxs_pull *prbxs_pull;
56
+ Data_Get_Struct(self, rbxs_pullattributeset, prbxs_pullattributeset);
57
+ Data_Get_Struct(prbxs_pullattributeset->node, rbxs_pull, prbxs_pull);
58
+ return(xmlTextReaderHasAttributes(prbxs_pull->reader) ? Qfalse : Qtrue);
59
+ }
60
+
61
+ /*
62
+ * Documentation
63
+ */
64
+ VALUE rbxs_pullattributeset_length(VALUE self)
65
+ {
66
+ rbxs_pullattributeset *prbxs_pullattributeset;
67
+ rbxs_pull *prbxs_pull;
68
+ Data_Get_Struct(self, rbxs_pullattributeset, prbxs_pullattributeset);
69
+ Data_Get_Struct(prbxs_pullattributeset->node, rbxs_pull, prbxs_pull);
70
+ return(NUM2INT(xmlTextReaderAttributeCount(prbxs_pull->reader)));
71
+ }
72
+
73
+ /*
74
+ * Documentation
75
+ */
76
+ VALUE rbxs_pullattributeset_each(VALUE self)
77
+ {
78
+ rbxs_pullattributeset *prbxs_pullattributeset;
79
+ rbxs_pull *prbxs_pull;
80
+ Data_Get_Struct(self, rbxs_pullattributeset, prbxs_pullattributeset);
81
+ Data_Get_Struct(prbxs_pullattributeset->node, rbxs_pull, prbxs_pull);
82
+ while (xmlTextReaderMoveToNextAttribute(prbxs_pull->reader)) {
83
+ xmlChar *ret;
84
+ VALUE val;
85
+ ret = xmlTextReaderValue(prbxs_pull->reader);
86
+ val = rb_str_new2((char *)ret);
87
+ xmlFree(ret);
88
+ rb_yield_values(2,rbxs_qname_new(cSmartQName,prbxs_pullattributeset->node,RBXS_PARSER_TYPE_READER),val);
89
+ }
90
+ xmlTextReaderMoveToElement(prbxs_pull->reader);
91
+ return(self);
92
+ }
93
+
94
+ /*
95
+ * Documentation
96
+ */
97
+ VALUE rbxs_pullattributeset_get(VALUE self, VALUE which)
98
+ {
99
+ rbxs_pullattributeset *prbxs_pullattributeset;
100
+ Data_Get_Struct(self, rbxs_pullattributeset, prbxs_pullattributeset);
101
+ return(rbxs_pullattribute_new(cSmartPullAttribute,prbxs_pullattributeset->node,which));
102
+ }
103
+
104
+ /*
105
+ * Documentation
106
+ */
107
+ VALUE rbxs_pullattributeset_first(VALUE self)
108
+ {
109
+ return rbxs_pullattributeset_get(self,INT2NUM(0));
110
+ }
111
+
112
+ /*
113
+ * Documentation
114
+ */
115
+ VALUE rbxs_pullattributeset_last(VALUE self)
116
+ {
117
+ return rbxs_pullattributeset_get(self,INT2NUM(-1));
118
+ }
119
+
120
+ //***********************************************************************************
121
+ // Constructors
122
+ //***********************************************************************************
123
+ VALUE rbxs_pullattributeset_new(VALUE class, VALUE node) {
124
+ rbxs_pullattributeset *prbxs_pullattributeset;
125
+
126
+ prbxs_pullattributeset = (rbxs_pullattributeset *)malloc(sizeof(rbxs_pullattributeset));
127
+ if (prbxs_pullattributeset == NULL )
128
+ rb_raise(rb_eNoMemError, "No memory left for XML::Smart::Pull::AttributeSet struct");
129
+
130
+ prbxs_pullattributeset->node = node;
131
+
132
+ return(Data_Wrap_Struct(class, rbxs_pullattributeset_mark, rbxs_pullattributeset_free, prbxs_pullattributeset));
133
+ }
134
+
135
+ //***********************************************************************************
136
+ // Initialize class Node
137
+ //***********************************************************************************
138
+ #ifdef RDOC__
139
+ mXML = rb_define_module( "XML" );
140
+ cSmart = rb_define_class_under( mXML, "Smart", rb_cObject );
141
+ cSmartPull = rb_define_class_under( cSmart, "Pull", rb_cObject );
142
+ #endif
143
+ VALUE cSmartPullAttributeSet;
144
+
145
+ void init_rbxs_pullattributeset(void) {
146
+ cSmartPullAttributeSet = rb_define_class_under( cSmartPull, "AttributeSet", rb_cObject );
147
+ rb_include_module(cSmartPullAttributeSet, rb_mEnumerable);
148
+
149
+ rb_define_method(cSmartPullAttributeSet, "length", rbxs_pullattributeset_length, 0);
150
+ rb_define_method(cSmartPullAttributeSet, "empty?", rbxs_pullattributeset_empty, 0);
151
+ rb_define_method(cSmartPullAttributeSet, "each", rbxs_pullattributeset_each, 0);
152
+ rb_define_method(cSmartPullAttributeSet, "[]", rbxs_pullattributeset_get, 1);
153
+ rb_define_method(cSmartPullAttributeSet, "first", rbxs_pullattributeset_first, 0);
154
+ rb_define_method(cSmartPullAttributeSet, "last", rbxs_pullattributeset_last, 0);
155
+ rb_define_method(cSmartPullAttributeSet, "include?", rbxs_pullattributeset_include, 1);
156
+ }
@@ -0,0 +1,17 @@
1
+ /* Please see the COPYING file for copyright and distribution information */
2
+
3
+ #ifndef __RBXS_PULLATTRIBUTESET_H__
4
+ #define __RBXS_PULLATTRIBUTESET_H__
5
+
6
+ #include "rbxs.h"
7
+
8
+ RUBY_EXTERN VALUE cSmartPullAttributeSet;
9
+
10
+ typedef struct rbxs_pullattributeset {
11
+ VALUE node;
12
+ } rbxs_pullattributeset;
13
+
14
+ RUBY_EXTERN VALUE rbxs_pullattributeset_new(VALUE class, VALUE node);
15
+ RUBY_EXTERN void init_rbxs_pullattributeset(void);
16
+
17
+ #endif