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.
- data/AUTHORS +4 -0
- data/COPYING +504 -0
- data/Changelog +192 -0
- data/README +52 -0
- data/Rakefile +112 -0
- data/TODO +6 -0
- data/examples/EXAMPLE.xml +17 -0
- data/examples/EXAMPLE.xml.sic +17 -0
- data/examples/Visualise/EXAMPLE.xml +18 -0
- data/examples/Visualise/term-ansicolor-0.0.4/CHANGES +11 -0
- data/examples/Visualise/term-ansicolor-0.0.4/GPL +340 -0
- data/examples/Visualise/term-ansicolor-0.0.4/README.en +23 -0
- data/examples/Visualise/term-ansicolor-0.0.4/Rakefile +72 -0
- data/examples/Visualise/term-ansicolor-0.0.4/VERSION +1 -0
- data/examples/Visualise/term-ansicolor-0.0.4/examples/cdiff.rb +20 -0
- data/examples/Visualise/term-ansicolor-0.0.4/examples/example.rb +82 -0
- data/examples/Visualise/term-ansicolor-0.0.4/install.rb +12 -0
- data/examples/Visualise/term-ansicolor-0.0.4/lib/term/ansicolor.rb +78 -0
- data/examples/Visualise/xpath_visual.rb +45 -0
- data/examples/add_children.rb +14 -0
- data/examples/add_elements.rb +13 -0
- data/examples/attrs.rb +15 -0
- data/examples/children.rb +14 -0
- data/examples/concurrent.rb +30 -0
- data/examples/copy.rb +23 -0
- data/examples/create.rb +18 -0
- data/examples/delete.rb +30 -0
- data/examples/move_elements.rb +12 -0
- data/examples/namespace.rb +14 -0
- data/examples/namespace_detailed.rb +36 -0
- data/examples/namespace_find.rb +20 -0
- data/examples/pull.rb +18 -0
- data/examples/qname.rb +16 -0
- data/examples/replace.rb +14 -0
- data/examples/set_OR_replace.rb +32 -0
- data/examples/signals.rb +28 -0
- data/examples/string.rb +27 -0
- data/examples/write.rb +11 -0
- data/examples/xpath_attrs.rb +19 -0
- data/examples/xpath_functions.rb +7 -0
- data/examples/xpath_root.rb +6 -0
- data/extconf.rb +29 -0
- data/rbxs.c +136 -0
- data/rbxs.h +53 -0
- data/rbxs_dom.c +483 -0
- data/rbxs_dom.h +32 -0
- data/rbxs_domattribute.c +189 -0
- data/rbxs_domattribute.h +18 -0
- data/rbxs_domattributeset.c +182 -0
- data/rbxs_domattributeset.h +17 -0
- data/rbxs_domelement.c +656 -0
- data/rbxs_domelement.h +18 -0
- data/rbxs_domnamespace.c +127 -0
- data/rbxs_domnamespace.h +18 -0
- data/rbxs_domnamespaceset.c +276 -0
- data/rbxs_domnamespaceset.h +17 -0
- data/rbxs_domnodeset.c +284 -0
- data/rbxs_domnodeset.h +19 -0
- data/rbxs_domother.c +121 -0
- data/rbxs_domother.h +18 -0
- data/rbxs_domtext.c +165 -0
- data/rbxs_domtext.h +18 -0
- data/rbxs_pull.c +244 -0
- data/rbxs_pull.h +17 -0
- data/rbxs_pullattribute.c +124 -0
- data/rbxs_pullattribute.h +18 -0
- data/rbxs_pullattributeset.c +156 -0
- data/rbxs_pullattributeset.h +17 -0
- data/rbxs_qname.c +267 -0
- data/rbxs_qname.h +18 -0
- data/rbxs_utils.h +39 -0
- data/test/namespace_test.rb +83 -0
- metadata +125 -0
data/rbxs_domnamespace.c
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
#include "rbxs_dom.h"
|
2
|
+
#include "rbxs_domnamespace.h"
|
3
|
+
|
4
|
+
/* -- */
|
5
|
+
//***********************************************************************************
|
6
|
+
// GC
|
7
|
+
//***********************************************************************************
|
8
|
+
void rbxs_domnamespace_free(rbxs_domnamespace *prbxs_domnamespace) {
|
9
|
+
if (prbxs_domnamespace != NULL) {
|
10
|
+
prbxs_domnamespace->ns->_private = NULL;
|
11
|
+
free(prbxs_domnamespace);
|
12
|
+
}
|
13
|
+
}
|
14
|
+
|
15
|
+
void rbxs_domnamespace_mark(rbxs_domnamespace *prbxs_domnamespace) {
|
16
|
+
if (prbxs_domnamespace == NULL) return;
|
17
|
+
if (!NIL_P(prbxs_domnamespace->node)) rb_gc_mark(prbxs_domnamespace->node);
|
18
|
+
}
|
19
|
+
|
20
|
+
//***********************************************************************************
|
21
|
+
// Methods
|
22
|
+
//***********************************************************************************
|
23
|
+
/* ++ */
|
24
|
+
|
25
|
+
/*
|
26
|
+
* Documentation
|
27
|
+
*/
|
28
|
+
VALUE rbxs_domnamespace_inspect(VALUE self)
|
29
|
+
{
|
30
|
+
rbxs_domnamespace *prbxs_domnamespace;
|
31
|
+
VALUE *argv;
|
32
|
+
|
33
|
+
Data_Get_Struct(self, rbxs_domnamespace, prbxs_domnamespace);
|
34
|
+
if (prbxs_domnamespace->ns != NULL) {
|
35
|
+
argv = ALLOCA_N(VALUE, 5);
|
36
|
+
argv[0] = rb_str_new2("#<%s:0x%x %s=\"%s\">");
|
37
|
+
argv[1] = CLASS_OF(self);
|
38
|
+
argv[2] = rb_obj_id(self);
|
39
|
+
argv[3] = rb_str_new2(prbxs_domnamespace->ns->prefix ? (char *)prbxs_domnamespace->ns->prefix : "");
|
40
|
+
argv[4] = rb_str_new2((char *)prbxs_domnamespace->ns->href);
|
41
|
+
return(rb_f_sprintf(5, argv));
|
42
|
+
}
|
43
|
+
return(Qnil);
|
44
|
+
}
|
45
|
+
|
46
|
+
/*
|
47
|
+
* Documentation
|
48
|
+
*/
|
49
|
+
VALUE rbxs_domnamespace_to_s(VALUE self)
|
50
|
+
{
|
51
|
+
rbxs_domnamespace *prbxs_domnamespace;
|
52
|
+
|
53
|
+
Data_Get_Struct(self, rbxs_domnamespace, prbxs_domnamespace);
|
54
|
+
if (prbxs_domnamespace->ns != NULL)
|
55
|
+
return(rb_str_new2(prbxs_domnamespace->ns->prefix ? (char *)prbxs_domnamespace->ns->prefix : ""));
|
56
|
+
return(Qnil);
|
57
|
+
}
|
58
|
+
|
59
|
+
/*
|
60
|
+
* Documentation
|
61
|
+
*/
|
62
|
+
VALUE rbxs_domnamespace_prefix(VALUE self)
|
63
|
+
{
|
64
|
+
rbxs_domnamespace *prbxs_domnamespace;
|
65
|
+
Data_Get_Struct(self, rbxs_domnamespace, prbxs_domnamespace);
|
66
|
+
|
67
|
+
if (prbxs_domnamespace->ns && prbxs_domnamespace->ns->prefix)
|
68
|
+
return rb_str_new2((char *)prbxs_domnamespace->ns->prefix);
|
69
|
+
|
70
|
+
return Qnil;
|
71
|
+
}
|
72
|
+
|
73
|
+
/*
|
74
|
+
* Documentation
|
75
|
+
*/
|
76
|
+
VALUE rbxs_domnamespace_href(VALUE self)
|
77
|
+
{
|
78
|
+
rbxs_domnamespace *prbxs_domnamespace;
|
79
|
+
Data_Get_Struct(self, rbxs_domnamespace, prbxs_domnamespace);
|
80
|
+
|
81
|
+
if (prbxs_domnamespace->ns && prbxs_domnamespace->ns->href)
|
82
|
+
return rb_str_new2((char *)prbxs_domnamespace->ns->href);
|
83
|
+
|
84
|
+
return Qnil;
|
85
|
+
}
|
86
|
+
|
87
|
+
//***********************************************************************************
|
88
|
+
// Constructors
|
89
|
+
//***********************************************************************************
|
90
|
+
VALUE rbxs_domnamespace_new(VALUE class, VALUE node, xmlNsPtr ns) {
|
91
|
+
rbxs_domnamespace *prbxs_domnamespace;
|
92
|
+
VALUE result;
|
93
|
+
|
94
|
+
if (ns->_private) {
|
95
|
+
return (VALUE) ns->_private;
|
96
|
+
}
|
97
|
+
|
98
|
+
prbxs_domnamespace = (rbxs_domnamespace *)malloc(sizeof(rbxs_domnamespace));
|
99
|
+
if (prbxs_domnamespace == NULL )
|
100
|
+
rb_raise(rb_eNoMemError, "No memory left for XML::Smart::domNamespace struct");
|
101
|
+
|
102
|
+
prbxs_domnamespace->node = node;
|
103
|
+
prbxs_domnamespace->ns = ns;
|
104
|
+
|
105
|
+
result = Data_Wrap_Struct(class, rbxs_domnamespace_mark, rbxs_domnamespace_free, prbxs_domnamespace);
|
106
|
+
prbxs_domnamespace->ns->_private = (void*) result;
|
107
|
+
return result;
|
108
|
+
}
|
109
|
+
|
110
|
+
//***********************************************************************************
|
111
|
+
// Initialize class Node
|
112
|
+
//***********************************************************************************
|
113
|
+
#ifdef RDOC__
|
114
|
+
mXML = rb_define_module( "XML" );
|
115
|
+
cSmart = rb_define_class_under( mXML, "Smart", rb_cObject );
|
116
|
+
cSmartDom = rb_define_class_under( cSmart, "Dom", rb_cObject );
|
117
|
+
#endif
|
118
|
+
VALUE cSmartDomNamespace;
|
119
|
+
|
120
|
+
void init_rbxs_domnamespace(void) {
|
121
|
+
cSmartDomNamespace = rb_define_class_under( cSmartDom, "Namespace", rb_cObject );
|
122
|
+
|
123
|
+
rb_define_method(cSmartDomNamespace, "inspect", rbxs_domnamespace_inspect, 0);
|
124
|
+
rb_define_method(cSmartDomNamespace, "to_s", rbxs_domnamespace_to_s, 0);
|
125
|
+
rb_define_method(cSmartDomNamespace, "prefix", rbxs_domnamespace_prefix, 0);
|
126
|
+
rb_define_method(cSmartDomNamespace, "href", rbxs_domnamespace_href, 0);
|
127
|
+
}
|
data/rbxs_domnamespace.h
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
/* Please see the COPYING file for copyright and distribution information */
|
2
|
+
|
3
|
+
#ifndef __RBXS_DOMNAMESPACE_H__
|
4
|
+
#define __RBXS_DOMNAMESPACE_H__
|
5
|
+
|
6
|
+
#include "rbxs.h"
|
7
|
+
|
8
|
+
RUBY_EXTERN VALUE cSmartDomNamespace;
|
9
|
+
|
10
|
+
typedef struct rbxs_domnamespace {
|
11
|
+
VALUE node;
|
12
|
+
xmlNsPtr ns;
|
13
|
+
} rbxs_domnamespace;
|
14
|
+
|
15
|
+
RUBY_EXTERN VALUE rbxs_domnamespace_new(VALUE class, VALUE node, xmlNsPtr ns);
|
16
|
+
RUBY_EXTERN void init_rbxs_domnamespace(void);
|
17
|
+
|
18
|
+
#endif
|
@@ -0,0 +1,276 @@
|
|
1
|
+
#include "rbxs_dom.h"
|
2
|
+
#include "rbxs_domelement.h"
|
3
|
+
#include "rbxs_domnamespace.h"
|
4
|
+
#include "rbxs_domnamespaceset.h"
|
5
|
+
|
6
|
+
#define XML_XMLNS_NAMESPACE (unsigned char *) "http://www.w3.org/2000/xmlns/"
|
7
|
+
|
8
|
+
/* -- */
|
9
|
+
//***********************************************************************************
|
10
|
+
// GC
|
11
|
+
//***********************************************************************************
|
12
|
+
void rbxs_domnamespaceset_free(rbxs_domnamespaceset *prbxs_domnamespaceset) {
|
13
|
+
if (prbxs_domnamespaceset != NULL) {
|
14
|
+
free(prbxs_domnamespaceset);
|
15
|
+
}
|
16
|
+
}
|
17
|
+
|
18
|
+
void rbxs_domnamespaceset_mark(rbxs_domnamespaceset *prbxs_domnamespaceset) {
|
19
|
+
if (prbxs_domnamespaceset == NULL) return;
|
20
|
+
if (!NIL_P(prbxs_domnamespaceset->node)) rb_gc_mark(prbxs_domnamespaceset->node);
|
21
|
+
}
|
22
|
+
|
23
|
+
//***********************************************************************************
|
24
|
+
// Methods
|
25
|
+
//***********************************************************************************
|
26
|
+
/* ++ */
|
27
|
+
|
28
|
+
/*
|
29
|
+
* Documentation
|
30
|
+
*/
|
31
|
+
VALUE rbxs_domnamespaceset_include(VALUE self, VALUE prefix)
|
32
|
+
{
|
33
|
+
rbxs_domnamespaceset *prbxs_domnamespaceset;
|
34
|
+
rbxs_domelement *prbxs_domelement;
|
35
|
+
xmlNsPtr ns;
|
36
|
+
unsigned char *cmp;
|
37
|
+
|
38
|
+
Check_Type(prefix, T_STRING);
|
39
|
+
Data_Get_Struct(self, rbxs_domnamespaceset, prbxs_domnamespaceset);
|
40
|
+
Data_Get_Struct(prbxs_domnamespaceset->node, rbxs_domelement, prbxs_domelement);
|
41
|
+
|
42
|
+
ns = prbxs_domelement->node->nsDef;
|
43
|
+
cmp = (unsigned char *)StringValuePtr(prefix);
|
44
|
+
while (ns != NULL) {
|
45
|
+
if (xmlStrEqual(ns->prefix,cmp)) {
|
46
|
+
return Qtrue;
|
47
|
+
}
|
48
|
+
ns = ns->next;
|
49
|
+
}
|
50
|
+
return(Qfalse);
|
51
|
+
}
|
52
|
+
|
53
|
+
/*
|
54
|
+
* Documentation
|
55
|
+
*/
|
56
|
+
VALUE rbxs_domnamespaceset_length(VALUE self)
|
57
|
+
{
|
58
|
+
rbxs_domnamespaceset *prbxs_domnamespaceset;
|
59
|
+
rbxs_domelement *prbxs_domelement;
|
60
|
+
int counter = 0;
|
61
|
+
xmlNsPtr ns;
|
62
|
+
|
63
|
+
Data_Get_Struct(self, rbxs_domnamespaceset, prbxs_domnamespaceset);
|
64
|
+
Data_Get_Struct(prbxs_domnamespaceset->node, rbxs_domelement, prbxs_domelement);
|
65
|
+
|
66
|
+
ns = prbxs_domelement->node->nsDef;
|
67
|
+
while (ns != NULL) {
|
68
|
+
counter++;
|
69
|
+
ns = ns->next;
|
70
|
+
}
|
71
|
+
return(INT2NUM(counter));
|
72
|
+
}
|
73
|
+
|
74
|
+
/*
|
75
|
+
* Documentation
|
76
|
+
*/
|
77
|
+
VALUE rbxs_domnamespaceset_find(VALUE self,VALUE value)
|
78
|
+
{
|
79
|
+
rbxs_domnamespaceset *prbxs_domnamespaceset;
|
80
|
+
rbxs_domelement *prbxs_domelement;
|
81
|
+
xmlNsPtr ns;
|
82
|
+
|
83
|
+
Check_Type(value,T_STRING);
|
84
|
+
Data_Get_Struct(self, rbxs_domnamespaceset, prbxs_domnamespaceset);
|
85
|
+
Data_Get_Struct(prbxs_domnamespaceset->node, rbxs_domelement, prbxs_domelement);
|
86
|
+
|
87
|
+
ns = xmlSearchNs(prbxs_domelement->node->doc, prbxs_domelement->node, (unsigned char *)StringValuePtr(value));
|
88
|
+
if (ns)
|
89
|
+
return rbxs_domnamespace_new(cSmartDomNamespace,self,ns);
|
90
|
+
else {
|
91
|
+
ns = xmlSearchNsByHref(prbxs_domelement->node->doc, prbxs_domelement->node, (unsigned char *)StringValuePtr(value));
|
92
|
+
if (ns) return rbxs_domnamespace_new(cSmartDomNamespace,self,ns);
|
93
|
+
}
|
94
|
+
|
95
|
+
return Qnil;
|
96
|
+
}
|
97
|
+
|
98
|
+
/*
|
99
|
+
* Documentation
|
100
|
+
*/
|
101
|
+
VALUE rbxs_domnamespaceset_get_ns(VALUE self, VALUE prefix)
|
102
|
+
{
|
103
|
+
rbxs_domnamespaceset *prbxs_domnamespaceset;
|
104
|
+
rbxs_domelement *prbxs_domelement;
|
105
|
+
xmlNsPtr ns;
|
106
|
+
unsigned char *cmp;
|
107
|
+
|
108
|
+
Check_Type(prefix, T_STRING);
|
109
|
+
Data_Get_Struct(self, rbxs_domnamespaceset, prbxs_domnamespaceset);
|
110
|
+
Data_Get_Struct(prbxs_domnamespaceset->node, rbxs_domelement, prbxs_domelement);
|
111
|
+
|
112
|
+
ns = prbxs_domelement->node->nsDef;
|
113
|
+
cmp = (unsigned char *)StringValuePtr(prefix);
|
114
|
+
while (ns != NULL) {
|
115
|
+
if (xmlStrEqual(ns->prefix,cmp)) {
|
116
|
+
return rbxs_domnamespace_new(cSmartDomNamespace, prbxs_domnamespaceset->node, ns);
|
117
|
+
}
|
118
|
+
ns = ns->next;
|
119
|
+
}
|
120
|
+
return(Qnil);
|
121
|
+
}
|
122
|
+
|
123
|
+
/*
|
124
|
+
* Documentation
|
125
|
+
*/
|
126
|
+
VALUE rbxs_domnamespaceset_get(VALUE self, VALUE prefix)
|
127
|
+
{
|
128
|
+
rbxs_domnamespaceset *prbxs_domnamespaceset;
|
129
|
+
rbxs_domelement *prbxs_domelement;
|
130
|
+
xmlNsPtr ns;
|
131
|
+
unsigned char *cmp;
|
132
|
+
|
133
|
+
Check_Type(prefix, T_STRING);
|
134
|
+
Data_Get_Struct(self, rbxs_domnamespaceset, prbxs_domnamespaceset);
|
135
|
+
Data_Get_Struct(prbxs_domnamespaceset->node, rbxs_domelement, prbxs_domelement);
|
136
|
+
|
137
|
+
ns = prbxs_domelement->node->nsDef;
|
138
|
+
cmp = (unsigned char *)StringValuePtr(prefix);
|
139
|
+
while (ns != NULL) {
|
140
|
+
if (xmlStrEqual(ns->prefix,cmp))
|
141
|
+
return(rb_str_new2((char *)ns->href));
|
142
|
+
ns = ns->next;
|
143
|
+
}
|
144
|
+
return(Qnil);
|
145
|
+
}
|
146
|
+
|
147
|
+
/*
|
148
|
+
* Documentation
|
149
|
+
*/
|
150
|
+
VALUE rbxs_domnamespaceset_set(VALUE self, VALUE prefix, VALUE href)
|
151
|
+
{
|
152
|
+
rbxs_domnamespaceset *prbxs_domnamespaceset;
|
153
|
+
rbxs_domelement *prbxs_domelement;
|
154
|
+
rbxs_dom *prbxs_dom;
|
155
|
+
unsigned char *t_href, *t_prefix;
|
156
|
+
xmlNsPtr ns = NULL;
|
157
|
+
unsigned short int type;
|
158
|
+
VALUE ret,str;
|
159
|
+
|
160
|
+
Check_Type(prefix, T_STRING);
|
161
|
+
Data_Get_Struct(self, rbxs_domnamespaceset, prbxs_domnamespaceset);
|
162
|
+
Data_Get_Struct(prbxs_domnamespaceset->node, rbxs_domelement, prbxs_domelement);
|
163
|
+
Data_Get_Struct(prbxs_domelement->doc, rbxs_dom, prbxs_dom);
|
164
|
+
|
165
|
+
str = rb_obj_as_string(href);
|
166
|
+
if (NIL_P(str) || TYPE(str) != T_STRING)
|
167
|
+
rb_raise(rb_eTypeError, "cannot convert href to string");
|
168
|
+
t_href = (unsigned char *)StringValuePtr(str);
|
169
|
+
if (!xmlCheckUTF8(t_href))
|
170
|
+
rb_raise(rb_eArgError, "href must be utf8 encoded");
|
171
|
+
|
172
|
+
str = rb_obj_as_string(prefix);
|
173
|
+
if (NIL_P(str) || TYPE(str) != T_STRING)
|
174
|
+
rb_raise(rb_eTypeError, "cannot convert prefix to string");
|
175
|
+
t_prefix = (unsigned char *)StringValuePtr(str);
|
176
|
+
if (!xmlCheckUTF8(t_prefix))
|
177
|
+
rb_raise(rb_eArgError, "prefix must be utf8 encoded");
|
178
|
+
|
179
|
+
type = RBXS_DOM_SIGNAL_CHANGE;
|
180
|
+
if (t_href == NULL ||
|
181
|
+
(!xmlStrEqual(t_prefix, (unsigned char *)"xml") && xmlStrEqual(t_href, XML_XML_NAMESPACE)) ||
|
182
|
+
(prbxs_domelement->node->type == XML_ATTRIBUTE_NODE && !xmlStrEqual(t_prefix, (unsigned char *)"xmlns") && xmlStrEqual(t_href, XML_XMLNS_NAMESPACE)) ||
|
183
|
+
(prbxs_domelement->node->type == XML_ATTRIBUTE_NODE && !xmlStrEqual(prbxs_domelement->node->name, (unsigned char *)"xmlns"))) {
|
184
|
+
ns = NULL;
|
185
|
+
} else {
|
186
|
+
xmlNsPtr cmp;
|
187
|
+
cmp = prbxs_domelement->node->nsDef;
|
188
|
+
while (cmp != NULL) {
|
189
|
+
if (xmlStrEqual(t_prefix, cmp->prefix)) {
|
190
|
+
if (xmlStrEqual(t_href, cmp->href)) {
|
191
|
+
ns = cmp;
|
192
|
+
break;
|
193
|
+
} else {
|
194
|
+
xmlFree((char *) cmp->href);
|
195
|
+
cmp->href = xmlStrdup(t_href);
|
196
|
+
ns = cmp;
|
197
|
+
break;
|
198
|
+
}
|
199
|
+
}
|
200
|
+
cmp = cmp->next;
|
201
|
+
}
|
202
|
+
if (ns == NULL) {
|
203
|
+
ns = xmlNewNs(prbxs_domelement->node,t_href,t_prefix);
|
204
|
+
type = RBXS_DOM_SIGNAL_ADD;
|
205
|
+
}
|
206
|
+
}
|
207
|
+
if (ns == NULL)
|
208
|
+
rb_raise(rb_eRuntimeError, "Couldn't add namespace");
|
209
|
+
xmlSetNs(prbxs_domelement->node, ns);
|
210
|
+
|
211
|
+
ret = rbxs_domnamespace_new(cSmartDomNamespace,prbxs_domnamespaceset->node,ns);
|
212
|
+
rbxs_dom_change_handlers_execute(prbxs_dom,type,ret);
|
213
|
+
return(ret);
|
214
|
+
}
|
215
|
+
|
216
|
+
/*
|
217
|
+
* Documentation
|
218
|
+
*/
|
219
|
+
VALUE rbxs_domnamespaceset_each(VALUE self)
|
220
|
+
{
|
221
|
+
rbxs_domnamespaceset *prbxs_domnamespaceset;
|
222
|
+
rbxs_domelement *prbxs_domelement;
|
223
|
+
VALUE obj;
|
224
|
+
xmlNsPtr ns;
|
225
|
+
|
226
|
+
Data_Get_Struct(self, rbxs_domnamespaceset, prbxs_domnamespaceset);
|
227
|
+
Data_Get_Struct(prbxs_domnamespaceset->node, rbxs_domelement, prbxs_domelement);
|
228
|
+
|
229
|
+
ns = prbxs_domelement->node->nsDef;
|
230
|
+
while (ns != NULL) {
|
231
|
+
obj = rbxs_domnamespace_new(cSmartDomNamespace, prbxs_domnamespaceset->node, ns);
|
232
|
+
rb_yield(obj);
|
233
|
+
ns = ns->next;
|
234
|
+
}
|
235
|
+
return(self);
|
236
|
+
}
|
237
|
+
|
238
|
+
//***********************************************************************************
|
239
|
+
// Constructors
|
240
|
+
//***********************************************************************************
|
241
|
+
VALUE rbxs_domnamespaceset_new(VALUE class, VALUE node) {
|
242
|
+
rbxs_domnamespaceset *prbxs_domnamespaceset;
|
243
|
+
|
244
|
+
prbxs_domnamespaceset = (rbxs_domnamespaceset *)malloc(sizeof(rbxs_domnamespaceset));
|
245
|
+
if (prbxs_domnamespaceset == NULL )
|
246
|
+
rb_raise(rb_eNoMemError, "No memory left for XML::Smart::Dom::NamespaceSet struct");
|
247
|
+
|
248
|
+
prbxs_domnamespaceset->node = node;
|
249
|
+
|
250
|
+
return(Data_Wrap_Struct(class, rbxs_domnamespaceset_mark, rbxs_domnamespaceset_free, prbxs_domnamespaceset));
|
251
|
+
}
|
252
|
+
|
253
|
+
//***********************************************************************************
|
254
|
+
// Initialize class Node
|
255
|
+
//***********************************************************************************
|
256
|
+
#ifdef RDOC__
|
257
|
+
mXML = rb_define_module( "XML" );
|
258
|
+
cSmart = rb_define_class_under( mXML, "Smart", rb_cObject );
|
259
|
+
cSmartDom = rb_define_class_under( cSmart, "Dom", rb_cObject );
|
260
|
+
#endif
|
261
|
+
VALUE cSmartDomNamespaceSet;
|
262
|
+
|
263
|
+
void init_rbxs_domnamespaceset(void) {
|
264
|
+
cSmartDomNamespaceSet = rb_define_class_under( cSmartDom, "NamespaceSet", rb_cObject );
|
265
|
+
rb_include_module(cSmartDomNamespaceSet, rb_mEnumerable);
|
266
|
+
|
267
|
+
rb_define_method(cSmartDomNamespaceSet, "has_ns?", rbxs_domnamespaceset_include, 1);
|
268
|
+
rb_define_method(cSmartDomNamespaceSet, "get_ns", rbxs_domnamespaceset_get_ns, 1);
|
269
|
+
rb_define_method(cSmartDomNamespaceSet, "include?", rbxs_domnamespaceset_include, 1);
|
270
|
+
rb_define_method(cSmartDomNamespaceSet, "[]", rbxs_domnamespaceset_get, 1);
|
271
|
+
rb_define_method(cSmartDomNamespaceSet, "[]=", rbxs_domnamespaceset_set, 2);
|
272
|
+
rb_define_method(cSmartDomNamespaceSet, "add", rbxs_domnamespaceset_set, 2);
|
273
|
+
rb_define_method(cSmartDomNamespaceSet, "length", rbxs_domnamespaceset_length, 0);
|
274
|
+
rb_define_method(cSmartDomNamespaceSet, "each", rbxs_domnamespaceset_each, 0);
|
275
|
+
rb_define_method(cSmartDomNamespaceSet, "find", rbxs_domnamespaceset_find, 1);
|
276
|
+
}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
/* Please see the COPYING file for copyright and distribution information */
|
2
|
+
|
3
|
+
#ifndef __RBXS_DOMNAMESPACESET_H__
|
4
|
+
#define __RBXS_DOMNAMESPACESET_H__
|
5
|
+
|
6
|
+
#include "rbxs.h"
|
7
|
+
|
8
|
+
RUBY_EXTERN VALUE cSmartDomNamespaceSet;
|
9
|
+
|
10
|
+
typedef struct rbxs_domnamespaceset {
|
11
|
+
VALUE node;
|
12
|
+
} rbxs_domnamespaceset;
|
13
|
+
|
14
|
+
RUBY_EXTERN VALUE rbxs_domnamespaceset_new(VALUE class, VALUE node);
|
15
|
+
RUBY_EXTERN void init_rbxs_domnamespaceset(void);
|
16
|
+
|
17
|
+
#endif
|