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_domattribute.h
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
/* Please see the COPYING file for copyright and distribution information */
|
2
|
+
|
3
|
+
#ifndef __RBXS_DOMATTRIBUTE_H__
|
4
|
+
#define __RBXS_DOMATTRIBUTE_H__
|
5
|
+
|
6
|
+
#include "rbxs.h"
|
7
|
+
|
8
|
+
RUBY_EXTERN VALUE cSmartDomAttribute;
|
9
|
+
|
10
|
+
typedef struct rbxs_domattribute {
|
11
|
+
VALUE doc;
|
12
|
+
xmlAttrPtr attribute;
|
13
|
+
} rbxs_domattribute;
|
14
|
+
|
15
|
+
RUBY_EXTERN VALUE rbxs_domattribute_new(VALUE class, VALUE doc, xmlAttrPtr attribute);
|
16
|
+
RUBY_EXTERN void init_rbxs_domattribute(void);
|
17
|
+
|
18
|
+
#endif
|
@@ -0,0 +1,182 @@
|
|
1
|
+
#include "rbxs_dom.h"
|
2
|
+
#include "rbxs_domelement.h"
|
3
|
+
#include "rbxs_domattribute.h"
|
4
|
+
#include "rbxs_domattributeset.h"
|
5
|
+
|
6
|
+
/* -- */
|
7
|
+
//***********************************************************************************
|
8
|
+
// GC
|
9
|
+
//***********************************************************************************
|
10
|
+
void rbxs_domattributeset_free(rbxs_domattributeset *prbxs_domattributeset) {
|
11
|
+
if (prbxs_domattributeset != NULL) {
|
12
|
+
free(prbxs_domattributeset);
|
13
|
+
}
|
14
|
+
}
|
15
|
+
|
16
|
+
void rbxs_domattributeset_mark(rbxs_domattributeset *prbxs_domattributeset) {
|
17
|
+
if (prbxs_domattributeset == NULL) return;
|
18
|
+
if (!NIL_P(prbxs_domattributeset->node)) rb_gc_mark(prbxs_domattributeset->node);
|
19
|
+
}
|
20
|
+
|
21
|
+
//***********************************************************************************
|
22
|
+
// Methods
|
23
|
+
//***********************************************************************************
|
24
|
+
/* ++ */
|
25
|
+
|
26
|
+
/*
|
27
|
+
* Documentation
|
28
|
+
*/
|
29
|
+
VALUE rbxs_domattributeset_include(VALUE self, VALUE key)
|
30
|
+
{
|
31
|
+
rbxs_domattributeset *prbxs_domattributeset;
|
32
|
+
rbxs_domelement *prbxs_domelement;
|
33
|
+
Check_Type(key, T_STRING);
|
34
|
+
Data_Get_Struct(self, rbxs_domattributeset, prbxs_domattributeset);
|
35
|
+
Data_Get_Struct(prbxs_domattributeset->node, rbxs_domelement, prbxs_domelement);
|
36
|
+
if (xmlHasProp(prbxs_domelement->node,(unsigned char *)StringValuePtr(key)))
|
37
|
+
return(Qtrue);
|
38
|
+
else
|
39
|
+
return(Qfalse);
|
40
|
+
}
|
41
|
+
|
42
|
+
/*
|
43
|
+
* Documentation
|
44
|
+
*/
|
45
|
+
VALUE rbxs_domattributeset_get(VALUE self, VALUE key)
|
46
|
+
{
|
47
|
+
rbxs_domattributeset *prbxs_domattributeset;
|
48
|
+
rbxs_domelement *prbxs_domelement;
|
49
|
+
xmlChar *ret;
|
50
|
+
VALUE val;
|
51
|
+
|
52
|
+
Check_Type(key, T_STRING);
|
53
|
+
Data_Get_Struct(self, rbxs_domattributeset, prbxs_domattributeset);
|
54
|
+
Data_Get_Struct(prbxs_domattributeset->node, rbxs_domelement, prbxs_domelement);
|
55
|
+
|
56
|
+
ret = xmlGetProp(prbxs_domelement->node,(unsigned char *)StringValuePtr(key));
|
57
|
+
if (ret) {
|
58
|
+
val = rb_str_new2((char *)ret);
|
59
|
+
xmlFree(ret);
|
60
|
+
return(val);
|
61
|
+
} else
|
62
|
+
return(Qnil);
|
63
|
+
}
|
64
|
+
|
65
|
+
/*
|
66
|
+
* Documentation
|
67
|
+
*/
|
68
|
+
VALUE rbxs_domattributeset_set(VALUE self, VALUE key, VALUE value)
|
69
|
+
{
|
70
|
+
rbxs_domattributeset *prbxs_domattributeset;
|
71
|
+
rbxs_domelement *prbxs_domelement;
|
72
|
+
rbxs_dom *prbxs_dom;
|
73
|
+
xmlAttrPtr attr;
|
74
|
+
unsigned char *tc;
|
75
|
+
unsigned short int type;
|
76
|
+
VALUE ret,str;
|
77
|
+
|
78
|
+
Check_Type(key, T_STRING);
|
79
|
+
Data_Get_Struct(self, rbxs_domattributeset, prbxs_domattributeset);
|
80
|
+
Data_Get_Struct(prbxs_domattributeset->node, rbxs_domelement, prbxs_domelement);
|
81
|
+
Data_Get_Struct(prbxs_domelement->doc, rbxs_dom, prbxs_dom);
|
82
|
+
|
83
|
+
str = rb_obj_as_string(value);
|
84
|
+
if (NIL_P(str) || TYPE(str) != T_STRING)
|
85
|
+
rb_raise(rb_eTypeError, "cannot convert obj to string");
|
86
|
+
tc = (unsigned char *)StringValuePtr(str);
|
87
|
+
if (!xmlCheckUTF8((unsigned char *)tc))
|
88
|
+
rb_raise(rb_eArgError, "text must be utf8 encoded");
|
89
|
+
type = xmlHasProp(prbxs_domelement->node,(unsigned char *)StringValuePtr(key)) ? RBXS_DOM_SIGNAL_CHANGE : RBXS_DOM_SIGNAL_ADD;
|
90
|
+
|
91
|
+
attr = xmlSetProp(prbxs_domelement->node,(unsigned char *)StringValuePtr(key),tc);
|
92
|
+
if (attr == NULL)
|
93
|
+
rb_raise(rb_eRuntimeError, "Couldn't set attribute");
|
94
|
+
|
95
|
+
ret = rbxs_domattribute_new(cSmartDomAttribute, prbxs_domelement->doc, (xmlAttrPtr)attr);
|
96
|
+
rbxs_dom_change_handlers_execute(prbxs_dom,type,ret);
|
97
|
+
return(ret);
|
98
|
+
}
|
99
|
+
|
100
|
+
/*
|
101
|
+
* Documentation
|
102
|
+
*/
|
103
|
+
VALUE rbxs_domattributeset_get_attr(VALUE self, VALUE key)
|
104
|
+
{
|
105
|
+
rbxs_domattributeset *prbxs_domattributeset;
|
106
|
+
rbxs_domelement *prbxs_domelement;
|
107
|
+
xmlAttrPtr attr;
|
108
|
+
|
109
|
+
Check_Type(key, T_STRING);
|
110
|
+
Data_Get_Struct(self, rbxs_domattributeset, prbxs_domattributeset);
|
111
|
+
Data_Get_Struct(prbxs_domattributeset->node, rbxs_domelement, prbxs_domelement);
|
112
|
+
|
113
|
+
attr = prbxs_domelement->node->properties;
|
114
|
+
while (attr != NULL) {
|
115
|
+
if (xmlStrEqual(attr->name,BAD_CAST(StringValuePtr(key)))) {
|
116
|
+
return rbxs_domattribute_new(cSmartDomAttribute, prbxs_domelement->doc, (xmlAttrPtr)attr);
|
117
|
+
}
|
118
|
+
attr = attr->next;
|
119
|
+
}
|
120
|
+
rb_raise(rb_eRuntimeError, "Couldn't get attribute");
|
121
|
+
return(Qnil);
|
122
|
+
}
|
123
|
+
|
124
|
+
/*
|
125
|
+
* Documentation
|
126
|
+
*/
|
127
|
+
VALUE rbxs_domattributeset_each(VALUE self)
|
128
|
+
{
|
129
|
+
rbxs_domattributeset *prbxs_domattributeset;
|
130
|
+
rbxs_domelement *prbxs_domelement;
|
131
|
+
VALUE obj;
|
132
|
+
xmlAttrPtr attr;
|
133
|
+
|
134
|
+
Data_Get_Struct(self, rbxs_domattributeset, prbxs_domattributeset);
|
135
|
+
Data_Get_Struct(prbxs_domattributeset->node, rbxs_domelement, prbxs_domelement);
|
136
|
+
|
137
|
+
attr = prbxs_domelement->node->properties;
|
138
|
+
while (attr != NULL) {
|
139
|
+
obj = rbxs_domattribute_new(cSmartDomAttribute, prbxs_domelement->doc, (xmlAttrPtr)attr);
|
140
|
+
rb_yield(obj);
|
141
|
+
attr = attr->next;
|
142
|
+
}
|
143
|
+
return(self);
|
144
|
+
}
|
145
|
+
|
146
|
+
//***********************************************************************************
|
147
|
+
// Constructors
|
148
|
+
//***********************************************************************************
|
149
|
+
VALUE rbxs_domattributeset_new(VALUE class, VALUE node) {
|
150
|
+
rbxs_domattributeset *prbxs_domattributeset;
|
151
|
+
|
152
|
+
prbxs_domattributeset = (rbxs_domattributeset *)malloc(sizeof(rbxs_domattributeset));
|
153
|
+
if (prbxs_domattributeset == NULL )
|
154
|
+
rb_raise(rb_eNoMemError, "No memory left for XML::Smart::Dom::AttributeSet struct");
|
155
|
+
|
156
|
+
prbxs_domattributeset->node = node;
|
157
|
+
|
158
|
+
return(Data_Wrap_Struct(class, rbxs_domattributeset_mark, rbxs_domattributeset_free, prbxs_domattributeset));
|
159
|
+
}
|
160
|
+
|
161
|
+
//***********************************************************************************
|
162
|
+
// Initialize class Node
|
163
|
+
//***********************************************************************************
|
164
|
+
#ifdef RDOC__
|
165
|
+
mXML = rb_define_module( "XML" );
|
166
|
+
cSmart = rb_define_class_under( mXML, "Smart", rb_cObject );
|
167
|
+
cSmartDom = rb_define_class_under( cSmart, "Dom", rb_cObject );
|
168
|
+
#endif
|
169
|
+
VALUE cSmartDomAttributeSet;
|
170
|
+
|
171
|
+
void init_rbxs_domattributeset(void) {
|
172
|
+
cSmartDomAttributeSet = rb_define_class_under( cSmartDom, "AttributeSet", rb_cObject );
|
173
|
+
rb_include_module(cSmartDomAttributeSet, rb_mEnumerable);
|
174
|
+
|
175
|
+
rb_define_method(cSmartDomAttributeSet, "has_attr?", rbxs_domattributeset_include, 1);
|
176
|
+
rb_define_method(cSmartDomAttributeSet, "get_attr", rbxs_domattributeset_get_attr, 1);
|
177
|
+
rb_define_method(cSmartDomAttributeSet, "include?", rbxs_domattributeset_include, 1);
|
178
|
+
rb_define_method(cSmartDomAttributeSet, "[]", rbxs_domattributeset_get, 1);
|
179
|
+
rb_define_method(cSmartDomAttributeSet, "[]=", rbxs_domattributeset_set, 2);
|
180
|
+
rb_define_method(cSmartDomAttributeSet, "add", rbxs_domattributeset_set, 2);
|
181
|
+
rb_define_method(cSmartDomAttributeSet, "each", rbxs_domattributeset_each, 0);
|
182
|
+
}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
/* Please see the COPYING file for copyright and distribution information */
|
2
|
+
|
3
|
+
#ifndef __RBXS_DOMATTRIBUTESET_H__
|
4
|
+
#define __RBXS_DOMATTRIBUTESET_H__
|
5
|
+
|
6
|
+
#include "rbxs.h"
|
7
|
+
|
8
|
+
RUBY_EXTERN VALUE cSmartDomAttributeSet;
|
9
|
+
|
10
|
+
typedef struct rbxs_domattributeset {
|
11
|
+
VALUE node;
|
12
|
+
} rbxs_domattributeset;
|
13
|
+
|
14
|
+
RUBY_EXTERN VALUE rbxs_domattributeset_new(VALUE class, VALUE node);
|
15
|
+
RUBY_EXTERN void init_rbxs_domattributeset(void);
|
16
|
+
|
17
|
+
#endif
|