libxml-ruby 5.0.4 → 5.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/HISTORY +10 -6
- data/README.rdoc +1 -1
- data/ext/libxml/extconf.rb +5 -0
- data/ext/libxml/ruby_xml.c +556 -556
- data/ext/libxml/ruby_xml_attributes.h +17 -17
- data/ext/libxml/ruby_xml_document.c +1129 -1129
- data/ext/libxml/ruby_xml_dtd.c +257 -257
- data/ext/libxml/ruby_xml_encoding.c +250 -250
- data/ext/libxml/ruby_xml_error.c +1003 -1003
- data/ext/libxml/ruby_xml_error.h +14 -14
- data/ext/libxml/ruby_xml_html_parser_context.c +351 -351
- data/ext/libxml/ruby_xml_input_cbg.c +188 -188
- data/ext/libxml/ruby_xml_namespace.c +151 -151
- data/ext/libxml/ruby_xml_parser.h +10 -10
- data/ext/libxml/ruby_xml_parser_context.c +1009 -1009
- data/ext/libxml/ruby_xml_parser_options.c +74 -74
- data/ext/libxml/ruby_xml_parser_options.h +10 -10
- data/ext/libxml/ruby_xml_sax2_handler.c +326 -326
- data/ext/libxml/ruby_xml_sax_parser.c +108 -108
- data/ext/libxml/ruby_xml_version.h +9 -9
- data/lib/libxml/attr.rb +122 -122
- data/lib/libxml/attr_decl.rb +80 -80
- data/lib/libxml/attributes.rb +13 -13
- data/lib/libxml/document.rb +194 -194
- data/lib/libxml/error.rb +95 -95
- data/lib/libxml/hpricot.rb +77 -77
- data/lib/libxml/html_parser.rb +96 -96
- data/lib/libxml/namespace.rb +61 -61
- data/lib/libxml/namespaces.rb +37 -37
- data/lib/libxml/node.rb +323 -323
- data/lib/libxml/parser.rb +102 -102
- data/lib/libxml/sax_callbacks.rb +179 -179
- data/lib/libxml/sax_parser.rb +40 -40
- data/lib/libxml/tree.rb +28 -28
- data/lib/libxml.rb +4 -4
- data/lib/xml/libxml.rb +10 -10
- data/lib/xml.rb +13 -13
- data/libxml-ruby.gemspec +50 -49
- data/test/test_document.rb +140 -140
- data/test/test_document_write.rb +142 -142
- data/test/test_dtd.rb +126 -126
- data/test/test_encoding.rb +126 -126
- data/test/test_error.rb +194 -194
- data/test/test_helper.rb +20 -20
- data/test/test_namespace.rb +58 -58
- data/test/test_node.rb +235 -235
- data/test/test_node_write.rb +93 -93
- data/test/test_parser.rb +333 -333
- data/test/test_reader.rb +364 -364
- data/test/test_xml.rb +168 -168
- metadata +5 -4
@@ -1,188 +1,188 @@
|
|
1
|
-
/* Author: Martin Povolny (xpovolny@fi.muni.cz) */
|
2
|
-
|
3
|
-
#include "ruby_libxml.h"
|
4
|
-
#include "ruby_xml_input_cbg.h"
|
5
|
-
|
6
|
-
/* Document-class: LibXML::XML::InputCallbacks
|
7
|
-
*
|
8
|
-
* Support for adding custom scheme handlers. */
|
9
|
-
|
10
|
-
static ic_scheme *first_scheme = 0;
|
11
|
-
|
12
|
-
int ic_match(char const *filename)
|
13
|
-
{
|
14
|
-
ic_scheme *scheme;
|
15
|
-
|
16
|
-
//fprintf( stderr, "ic_match: %s\n", filename );
|
17
|
-
|
18
|
-
scheme = first_scheme;
|
19
|
-
while (0 != scheme)
|
20
|
-
{
|
21
|
-
if (!xmlStrncasecmp(BAD_CAST filename, BAD_CAST scheme->scheme_name, scheme->name_len))
|
22
|
-
{
|
23
|
-
return 1;
|
24
|
-
}
|
25
|
-
scheme = scheme->next_scheme;
|
26
|
-
}
|
27
|
-
return 0;
|
28
|
-
}
|
29
|
-
|
30
|
-
void* ic_open(char const *filename)
|
31
|
-
{
|
32
|
-
ic_doc_context *ic_doc;
|
33
|
-
ic_scheme *scheme;
|
34
|
-
VALUE res;
|
35
|
-
|
36
|
-
scheme = first_scheme;
|
37
|
-
while (0 != scheme)
|
38
|
-
{
|
39
|
-
if (!xmlStrncasecmp(BAD_CAST filename, BAD_CAST scheme->scheme_name, scheme->name_len))
|
40
|
-
{
|
41
|
-
ic_doc = (ic_doc_context*) malloc(sizeof(ic_doc_context));
|
42
|
-
|
43
|
-
res = rb_funcall(scheme->class, rb_intern("document_query"), 1,
|
44
|
-
rb_str_new2(filename));
|
45
|
-
|
46
|
-
ic_doc->buffer = strdup(StringValuePtr(res));
|
47
|
-
|
48
|
-
ic_doc->bpos = ic_doc->buffer;
|
49
|
-
ic_doc->remaining = (int)strlen(ic_doc->buffer);
|
50
|
-
return ic_doc;
|
51
|
-
}
|
52
|
-
scheme = scheme->next_scheme;
|
53
|
-
}
|
54
|
-
return 0;
|
55
|
-
}
|
56
|
-
|
57
|
-
int ic_read(void *context, char *buffer, int len)
|
58
|
-
{
|
59
|
-
ic_doc_context *ic_doc;
|
60
|
-
int ret_len;
|
61
|
-
ic_doc = (ic_doc_context*) context;
|
62
|
-
|
63
|
-
if (len >= ic_doc->remaining)
|
64
|
-
{
|
65
|
-
ret_len = ic_doc->remaining;
|
66
|
-
}
|
67
|
-
else
|
68
|
-
{
|
69
|
-
ret_len = len;
|
70
|
-
}
|
71
|
-
ic_doc->remaining -= ret_len;
|
72
|
-
strncpy(buffer, ic_doc->bpos, ret_len);
|
73
|
-
ic_doc->bpos += ret_len;
|
74
|
-
|
75
|
-
return ret_len;
|
76
|
-
}
|
77
|
-
|
78
|
-
int ic_close(void *context)
|
79
|
-
{
|
80
|
-
ruby_xfree(((ic_doc_context*) context)->buffer);
|
81
|
-
ruby_xfree(context);
|
82
|
-
return 1;
|
83
|
-
}
|
84
|
-
|
85
|
-
/*
|
86
|
-
* call-seq:
|
87
|
-
* register
|
88
|
-
*
|
89
|
-
* Register a new set of I/O callback for handling parser input.
|
90
|
-
*/
|
91
|
-
static VALUE input_callbacks_register_input_callbacks(VALUE self)
|
92
|
-
{
|
93
|
-
xmlRegisterInputCallbacks(ic_match, ic_open, ic_read, ic_close);
|
94
|
-
return (Qtrue);
|
95
|
-
}
|
96
|
-
|
97
|
-
/*
|
98
|
-
* call-seq:
|
99
|
-
* add_scheme
|
100
|
-
*
|
101
|
-
* No documentation available.
|
102
|
-
*/
|
103
|
-
static VALUE input_callbacks_add_scheme(VALUE self, VALUE scheme_name,
|
104
|
-
VALUE class)
|
105
|
-
{
|
106
|
-
ic_scheme *scheme;
|
107
|
-
|
108
|
-
Check_Type(scheme_name, T_STRING);
|
109
|
-
|
110
|
-
scheme = (ic_scheme*) malloc(sizeof(ic_scheme));
|
111
|
-
scheme->next_scheme = 0;
|
112
|
-
scheme->scheme_name = strdup(StringValuePtr(scheme_name)); /* TODO alloc, dealloc */
|
113
|
-
scheme->name_len = (int)strlen(scheme->scheme_name);
|
114
|
-
scheme->class = class; /* TODO alloc, dealloc */
|
115
|
-
|
116
|
-
//fprintf( stderr, "registered: %s, %d, %s\n", scheme->scheme_name, scheme->name_len, scheme->class );
|
117
|
-
|
118
|
-
if (0 == first_scheme)
|
119
|
-
first_scheme = scheme;
|
120
|
-
else
|
121
|
-
{
|
122
|
-
ic_scheme *pos;
|
123
|
-
pos = first_scheme;
|
124
|
-
while (0 != pos->next_scheme)
|
125
|
-
pos = pos->next_scheme;
|
126
|
-
pos->next_scheme = scheme;
|
127
|
-
}
|
128
|
-
|
129
|
-
return (Qtrue);
|
130
|
-
}
|
131
|
-
|
132
|
-
/*
|
133
|
-
* call-seq:
|
134
|
-
* remove_scheme
|
135
|
-
*
|
136
|
-
* No documentation available.
|
137
|
-
*/
|
138
|
-
static VALUE input_callbacks_remove_scheme(VALUE self, VALUE scheme_name)
|
139
|
-
{
|
140
|
-
char *name;
|
141
|
-
ic_scheme *save_scheme, *scheme;
|
142
|
-
|
143
|
-
Check_Type(scheme_name, T_STRING);
|
144
|
-
name = StringValuePtr(scheme_name);
|
145
|
-
|
146
|
-
if (0 == first_scheme)
|
147
|
-
return Qfalse;
|
148
|
-
|
149
|
-
if (!strncmp(name, first_scheme->scheme_name, first_scheme->name_len))
|
150
|
-
{
|
151
|
-
save_scheme = first_scheme->next_scheme;
|
152
|
-
|
153
|
-
ruby_xfree(first_scheme->scheme_name);
|
154
|
-
ruby_xfree(first_scheme);
|
155
|
-
|
156
|
-
first_scheme = save_scheme;
|
157
|
-
return Qtrue;
|
158
|
-
}
|
159
|
-
|
160
|
-
scheme = first_scheme;
|
161
|
-
while (0 != scheme->next_scheme)
|
162
|
-
{
|
163
|
-
if (!strncmp(name, scheme->next_scheme->scheme_name,
|
164
|
-
scheme->next_scheme->name_len))
|
165
|
-
{
|
166
|
-
save_scheme = scheme->next_scheme->next_scheme;
|
167
|
-
|
168
|
-
ruby_xfree(scheme->next_scheme->scheme_name);
|
169
|
-
ruby_xfree(scheme->next_scheme);
|
170
|
-
|
171
|
-
scheme->next_scheme = save_scheme;
|
172
|
-
return Qtrue;
|
173
|
-
}
|
174
|
-
scheme = scheme->next_scheme;
|
175
|
-
}
|
176
|
-
return Qfalse;
|
177
|
-
}
|
178
|
-
|
179
|
-
void rxml_init_input_callbacks(void)
|
180
|
-
{
|
181
|
-
VALUE cInputCallbacks;
|
182
|
-
cInputCallbacks = rb_define_class_under(mXML, "InputCallbacks", rb_cObject);
|
183
|
-
|
184
|
-
/* Class Methods */
|
185
|
-
rb_define_singleton_method(cInputCallbacks, "register", input_callbacks_register_input_callbacks, 0);
|
186
|
-
rb_define_singleton_method(cInputCallbacks, "add_scheme", input_callbacks_add_scheme, 2);
|
187
|
-
rb_define_singleton_method(cInputCallbacks, "remove_scheme", input_callbacks_remove_scheme, 1);
|
188
|
-
}
|
1
|
+
/* Author: Martin Povolny (xpovolny@fi.muni.cz) */
|
2
|
+
|
3
|
+
#include "ruby_libxml.h"
|
4
|
+
#include "ruby_xml_input_cbg.h"
|
5
|
+
|
6
|
+
/* Document-class: LibXML::XML::InputCallbacks
|
7
|
+
*
|
8
|
+
* Support for adding custom scheme handlers. */
|
9
|
+
|
10
|
+
static ic_scheme *first_scheme = 0;
|
11
|
+
|
12
|
+
int ic_match(char const *filename)
|
13
|
+
{
|
14
|
+
ic_scheme *scheme;
|
15
|
+
|
16
|
+
//fprintf( stderr, "ic_match: %s\n", filename );
|
17
|
+
|
18
|
+
scheme = first_scheme;
|
19
|
+
while (0 != scheme)
|
20
|
+
{
|
21
|
+
if (!xmlStrncasecmp(BAD_CAST filename, BAD_CAST scheme->scheme_name, scheme->name_len))
|
22
|
+
{
|
23
|
+
return 1;
|
24
|
+
}
|
25
|
+
scheme = scheme->next_scheme;
|
26
|
+
}
|
27
|
+
return 0;
|
28
|
+
}
|
29
|
+
|
30
|
+
void* ic_open(char const *filename)
|
31
|
+
{
|
32
|
+
ic_doc_context *ic_doc;
|
33
|
+
ic_scheme *scheme;
|
34
|
+
VALUE res;
|
35
|
+
|
36
|
+
scheme = first_scheme;
|
37
|
+
while (0 != scheme)
|
38
|
+
{
|
39
|
+
if (!xmlStrncasecmp(BAD_CAST filename, BAD_CAST scheme->scheme_name, scheme->name_len))
|
40
|
+
{
|
41
|
+
ic_doc = (ic_doc_context*) malloc(sizeof(ic_doc_context));
|
42
|
+
|
43
|
+
res = rb_funcall(scheme->class, rb_intern("document_query"), 1,
|
44
|
+
rb_str_new2(filename));
|
45
|
+
|
46
|
+
ic_doc->buffer = strdup(StringValuePtr(res));
|
47
|
+
|
48
|
+
ic_doc->bpos = ic_doc->buffer;
|
49
|
+
ic_doc->remaining = (int)strlen(ic_doc->buffer);
|
50
|
+
return ic_doc;
|
51
|
+
}
|
52
|
+
scheme = scheme->next_scheme;
|
53
|
+
}
|
54
|
+
return 0;
|
55
|
+
}
|
56
|
+
|
57
|
+
int ic_read(void *context, char *buffer, int len)
|
58
|
+
{
|
59
|
+
ic_doc_context *ic_doc;
|
60
|
+
int ret_len;
|
61
|
+
ic_doc = (ic_doc_context*) context;
|
62
|
+
|
63
|
+
if (len >= ic_doc->remaining)
|
64
|
+
{
|
65
|
+
ret_len = ic_doc->remaining;
|
66
|
+
}
|
67
|
+
else
|
68
|
+
{
|
69
|
+
ret_len = len;
|
70
|
+
}
|
71
|
+
ic_doc->remaining -= ret_len;
|
72
|
+
strncpy(buffer, ic_doc->bpos, ret_len);
|
73
|
+
ic_doc->bpos += ret_len;
|
74
|
+
|
75
|
+
return ret_len;
|
76
|
+
}
|
77
|
+
|
78
|
+
int ic_close(void *context)
|
79
|
+
{
|
80
|
+
ruby_xfree(((ic_doc_context*) context)->buffer);
|
81
|
+
ruby_xfree(context);
|
82
|
+
return 1;
|
83
|
+
}
|
84
|
+
|
85
|
+
/*
|
86
|
+
* call-seq:
|
87
|
+
* register
|
88
|
+
*
|
89
|
+
* Register a new set of I/O callback for handling parser input.
|
90
|
+
*/
|
91
|
+
static VALUE input_callbacks_register_input_callbacks(VALUE self)
|
92
|
+
{
|
93
|
+
xmlRegisterInputCallbacks(ic_match, ic_open, ic_read, ic_close);
|
94
|
+
return (Qtrue);
|
95
|
+
}
|
96
|
+
|
97
|
+
/*
|
98
|
+
* call-seq:
|
99
|
+
* add_scheme
|
100
|
+
*
|
101
|
+
* No documentation available.
|
102
|
+
*/
|
103
|
+
static VALUE input_callbacks_add_scheme(VALUE self, VALUE scheme_name,
|
104
|
+
VALUE class)
|
105
|
+
{
|
106
|
+
ic_scheme *scheme;
|
107
|
+
|
108
|
+
Check_Type(scheme_name, T_STRING);
|
109
|
+
|
110
|
+
scheme = (ic_scheme*) malloc(sizeof(ic_scheme));
|
111
|
+
scheme->next_scheme = 0;
|
112
|
+
scheme->scheme_name = strdup(StringValuePtr(scheme_name)); /* TODO alloc, dealloc */
|
113
|
+
scheme->name_len = (int)strlen(scheme->scheme_name);
|
114
|
+
scheme->class = class; /* TODO alloc, dealloc */
|
115
|
+
|
116
|
+
//fprintf( stderr, "registered: %s, %d, %s\n", scheme->scheme_name, scheme->name_len, scheme->class );
|
117
|
+
|
118
|
+
if (0 == first_scheme)
|
119
|
+
first_scheme = scheme;
|
120
|
+
else
|
121
|
+
{
|
122
|
+
ic_scheme *pos;
|
123
|
+
pos = first_scheme;
|
124
|
+
while (0 != pos->next_scheme)
|
125
|
+
pos = pos->next_scheme;
|
126
|
+
pos->next_scheme = scheme;
|
127
|
+
}
|
128
|
+
|
129
|
+
return (Qtrue);
|
130
|
+
}
|
131
|
+
|
132
|
+
/*
|
133
|
+
* call-seq:
|
134
|
+
* remove_scheme
|
135
|
+
*
|
136
|
+
* No documentation available.
|
137
|
+
*/
|
138
|
+
static VALUE input_callbacks_remove_scheme(VALUE self, VALUE scheme_name)
|
139
|
+
{
|
140
|
+
char *name;
|
141
|
+
ic_scheme *save_scheme, *scheme;
|
142
|
+
|
143
|
+
Check_Type(scheme_name, T_STRING);
|
144
|
+
name = StringValuePtr(scheme_name);
|
145
|
+
|
146
|
+
if (0 == first_scheme)
|
147
|
+
return Qfalse;
|
148
|
+
|
149
|
+
if (!strncmp(name, first_scheme->scheme_name, first_scheme->name_len))
|
150
|
+
{
|
151
|
+
save_scheme = first_scheme->next_scheme;
|
152
|
+
|
153
|
+
ruby_xfree(first_scheme->scheme_name);
|
154
|
+
ruby_xfree(first_scheme);
|
155
|
+
|
156
|
+
first_scheme = save_scheme;
|
157
|
+
return Qtrue;
|
158
|
+
}
|
159
|
+
|
160
|
+
scheme = first_scheme;
|
161
|
+
while (0 != scheme->next_scheme)
|
162
|
+
{
|
163
|
+
if (!strncmp(name, scheme->next_scheme->scheme_name,
|
164
|
+
scheme->next_scheme->name_len))
|
165
|
+
{
|
166
|
+
save_scheme = scheme->next_scheme->next_scheme;
|
167
|
+
|
168
|
+
ruby_xfree(scheme->next_scheme->scheme_name);
|
169
|
+
ruby_xfree(scheme->next_scheme);
|
170
|
+
|
171
|
+
scheme->next_scheme = save_scheme;
|
172
|
+
return Qtrue;
|
173
|
+
}
|
174
|
+
scheme = scheme->next_scheme;
|
175
|
+
}
|
176
|
+
return Qfalse;
|
177
|
+
}
|
178
|
+
|
179
|
+
void rxml_init_input_callbacks(void)
|
180
|
+
{
|
181
|
+
VALUE cInputCallbacks;
|
182
|
+
cInputCallbacks = rb_define_class_under(mXML, "InputCallbacks", rb_cObject);
|
183
|
+
|
184
|
+
/* Class Methods */
|
185
|
+
rb_define_singleton_method(cInputCallbacks, "register", input_callbacks_register_input_callbacks, 0);
|
186
|
+
rb_define_singleton_method(cInputCallbacks, "add_scheme", input_callbacks_add_scheme, 2);
|
187
|
+
rb_define_singleton_method(cInputCallbacks, "remove_scheme", input_callbacks_remove_scheme, 1);
|
188
|
+
}
|
@@ -1,151 +1,151 @@
|
|
1
|
-
/* Please see the LICENSE file for copyright and distribution information */
|
2
|
-
|
3
|
-
#include "ruby_libxml.h"
|
4
|
-
#include "ruby_xml_namespace.h"
|
5
|
-
|
6
|
-
VALUE cXMLNamespace;
|
7
|
-
|
8
|
-
/* Document-class: LibXML::XML::Namespace
|
9
|
-
*
|
10
|
-
* The Namespace class represents an XML namespace.
|
11
|
-
* To add a namespace to a node, create a new instance
|
12
|
-
* of this class. Note that this does *not* assign the
|
13
|
-
* node to the namespace. To do that see the
|
14
|
-
* XML::Namespaces#namespace method.
|
15
|
-
*
|
16
|
-
* Usage:
|
17
|
-
*
|
18
|
-
* node = XML::Node.new('<Envelope>')
|
19
|
-
* XML::Namespace.new(node, 'soap', 'http://schemas.xmlsoap.org/soap/envelope/')
|
20
|
-
* assert_equal("<Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"/>", node.to_s)
|
21
|
-
* assert_nil(node.namespaces.namespace)
|
22
|
-
*/
|
23
|
-
|
24
|
-
/* Namespaces are owned and freed by their nodes. Thus, its easier for the
|
25
|
-
ruby bindings to not manage attribute memory management. */
|
26
|
-
|
27
|
-
static VALUE rxml_namespace_alloc(VALUE klass)
|
28
|
-
{
|
29
|
-
return Data_Wrap_Struct(klass, NULL, NULL, NULL);
|
30
|
-
}
|
31
|
-
|
32
|
-
VALUE rxml_namespace_wrap(xmlNsPtr xns)
|
33
|
-
{
|
34
|
-
return Data_Wrap_Struct(cXMLNamespace, NULL, NULL, xns);
|
35
|
-
}
|
36
|
-
|
37
|
-
|
38
|
-
/*
|
39
|
-
* call-seq:
|
40
|
-
* initialize(node, "prefix", "href") -> XML::Namespace
|
41
|
-
*
|
42
|
-
* Create a new namespace and adds it to the specified node.
|
43
|
-
* Note this does *not* assign the node to the namespace.
|
44
|
-
* To do that see the XML::Namespaces#namespace method.
|
45
|
-
*/
|
46
|
-
static VALUE rxml_namespace_initialize(VALUE self, VALUE node, VALUE prefix,
|
47
|
-
VALUE href)
|
48
|
-
{
|
49
|
-
xmlNodePtr xnode;
|
50
|
-
xmlChar *xmlPrefix;
|
51
|
-
xmlNsPtr xns;
|
52
|
-
|
53
|
-
Check_Type(node, T_DATA);
|
54
|
-
Data_Get_Struct(node, xmlNode, xnode);
|
55
|
-
xmlResetLastError();
|
56
|
-
|
57
|
-
/* Prefix can be null - that means its the default namespace */
|
58
|
-
xmlPrefix = NIL_P(prefix) ? NULL : (xmlChar *)StringValuePtr(prefix);
|
59
|
-
xns = xmlNewNs(xnode, (xmlChar*) StringValuePtr(href), xmlPrefix);
|
60
|
-
|
61
|
-
DATA_PTR(self) = xns;
|
62
|
-
return self;
|
63
|
-
}
|
64
|
-
|
65
|
-
/*
|
66
|
-
* call-seq:
|
67
|
-
* ns.href -> "href"
|
68
|
-
*
|
69
|
-
* Usage:
|
70
|
-
*
|
71
|
-
* doc = XML::Document.string('<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"/>')
|
72
|
-
* ns = doc.root.namespaces.find_by_href('http://schemas.xmlsoap.org/soap/envelope/')
|
73
|
-
* assert_equal('http://schemas.xmlsoap.org/soap/envelope/', ns.href)
|
74
|
-
*/
|
75
|
-
static VALUE rxml_namespace_href_get(VALUE self)
|
76
|
-
{
|
77
|
-
xmlNsPtr xns;
|
78
|
-
Data_Get_Struct(self, xmlNs, xns);
|
79
|
-
if (xns->href == NULL)
|
80
|
-
return Qnil;
|
81
|
-
else
|
82
|
-
return rxml_new_cstr( xns->href, NULL);
|
83
|
-
}
|
84
|
-
|
85
|
-
/*
|
86
|
-
* call-seq:
|
87
|
-
* ns.node_type -> num
|
88
|
-
*
|
89
|
-
* Obtain this namespace's type identifier.
|
90
|
-
*/
|
91
|
-
static VALUE rxml_namespace_node_type(VALUE self)
|
92
|
-
{
|
93
|
-
xmlNsPtr xns;
|
94
|
-
Data_Get_Struct(self, xmlNs, xns);
|
95
|
-
return INT2NUM(xns->type);
|
96
|
-
}
|
97
|
-
|
98
|
-
/*
|
99
|
-
* call-seq:
|
100
|
-
* ns.prefix -> "prefix"
|
101
|
-
*
|
102
|
-
* Obtain the namespace's prefix.
|
103
|
-
*
|
104
|
-
* Usage:
|
105
|
-
*
|
106
|
-
* doc = XML::Document.string('<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"/>')
|
107
|
-
* ns = doc.root.namespaces.find_by_href('http://schemas.xmlsoap.org/soap/envelope/')
|
108
|
-
* assert_equal('soap', ns.prefix)
|
109
|
-
*/
|
110
|
-
static VALUE rxml_namespace_prefix_get(VALUE self)
|
111
|
-
{
|
112
|
-
xmlNsPtr xns;
|
113
|
-
Data_Get_Struct(self, xmlNs, xns);
|
114
|
-
if (xns->prefix == NULL)
|
115
|
-
return Qnil;
|
116
|
-
else
|
117
|
-
return rxml_new_cstr( xns->prefix, NULL);
|
118
|
-
}
|
119
|
-
|
120
|
-
/*
|
121
|
-
* call-seq:
|
122
|
-
* ns.next -> XML::Namespace
|
123
|
-
*
|
124
|
-
* Obtain the next namespace.
|
125
|
-
*
|
126
|
-
* Usage:
|
127
|
-
*
|
128
|
-
* doc = XML::Document.string('<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"/>')
|
129
|
-
* ns = doc.root.namespaces.find_by_href('http://schemas.xmlsoap.org/soap/envelope/')
|
130
|
-
* assert_nil(ns.next)
|
131
|
-
*/
|
132
|
-
static VALUE rxml_namespace_next(VALUE self)
|
133
|
-
{
|
134
|
-
xmlNsPtr xns;
|
135
|
-
Data_Get_Struct(self, xmlNs, xns);
|
136
|
-
if (xns == NULL || xns->next == NULL)
|
137
|
-
return (Qnil);
|
138
|
-
else
|
139
|
-
return rxml_namespace_wrap(xns->next);
|
140
|
-
}
|
141
|
-
|
142
|
-
void rxml_init_namespace(void)
|
143
|
-
{
|
144
|
-
cXMLNamespace = rb_define_class_under(mXML, "Namespace", rb_cObject);
|
145
|
-
rb_define_alloc_func(cXMLNamespace, rxml_namespace_alloc);
|
146
|
-
rb_define_method(cXMLNamespace, "initialize", rxml_namespace_initialize, 3);
|
147
|
-
rb_define_method(cXMLNamespace, "href", rxml_namespace_href_get, 0);
|
148
|
-
rb_define_method(cXMLNamespace, "next", rxml_namespace_next, 0);
|
149
|
-
rb_define_method(cXMLNamespace, "node_type", rxml_namespace_node_type, 0);
|
150
|
-
rb_define_method(cXMLNamespace, "prefix", rxml_namespace_prefix_get, 0);
|
151
|
-
}
|
1
|
+
/* Please see the LICENSE file for copyright and distribution information */
|
2
|
+
|
3
|
+
#include "ruby_libxml.h"
|
4
|
+
#include "ruby_xml_namespace.h"
|
5
|
+
|
6
|
+
VALUE cXMLNamespace;
|
7
|
+
|
8
|
+
/* Document-class: LibXML::XML::Namespace
|
9
|
+
*
|
10
|
+
* The Namespace class represents an XML namespace.
|
11
|
+
* To add a namespace to a node, create a new instance
|
12
|
+
* of this class. Note that this does *not* assign the
|
13
|
+
* node to the namespace. To do that see the
|
14
|
+
* XML::Namespaces#namespace method.
|
15
|
+
*
|
16
|
+
* Usage:
|
17
|
+
*
|
18
|
+
* node = XML::Node.new('<Envelope>')
|
19
|
+
* XML::Namespace.new(node, 'soap', 'http://schemas.xmlsoap.org/soap/envelope/')
|
20
|
+
* assert_equal("<Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"/>", node.to_s)
|
21
|
+
* assert_nil(node.namespaces.namespace)
|
22
|
+
*/
|
23
|
+
|
24
|
+
/* Namespaces are owned and freed by their nodes. Thus, its easier for the
|
25
|
+
ruby bindings to not manage attribute memory management. */
|
26
|
+
|
27
|
+
static VALUE rxml_namespace_alloc(VALUE klass)
|
28
|
+
{
|
29
|
+
return Data_Wrap_Struct(klass, NULL, NULL, NULL);
|
30
|
+
}
|
31
|
+
|
32
|
+
VALUE rxml_namespace_wrap(xmlNsPtr xns)
|
33
|
+
{
|
34
|
+
return Data_Wrap_Struct(cXMLNamespace, NULL, NULL, xns);
|
35
|
+
}
|
36
|
+
|
37
|
+
|
38
|
+
/*
|
39
|
+
* call-seq:
|
40
|
+
* initialize(node, "prefix", "href") -> XML::Namespace
|
41
|
+
*
|
42
|
+
* Create a new namespace and adds it to the specified node.
|
43
|
+
* Note this does *not* assign the node to the namespace.
|
44
|
+
* To do that see the XML::Namespaces#namespace method.
|
45
|
+
*/
|
46
|
+
static VALUE rxml_namespace_initialize(VALUE self, VALUE node, VALUE prefix,
|
47
|
+
VALUE href)
|
48
|
+
{
|
49
|
+
xmlNodePtr xnode;
|
50
|
+
xmlChar *xmlPrefix;
|
51
|
+
xmlNsPtr xns;
|
52
|
+
|
53
|
+
Check_Type(node, T_DATA);
|
54
|
+
Data_Get_Struct(node, xmlNode, xnode);
|
55
|
+
xmlResetLastError();
|
56
|
+
|
57
|
+
/* Prefix can be null - that means its the default namespace */
|
58
|
+
xmlPrefix = NIL_P(prefix) ? NULL : (xmlChar *)StringValuePtr(prefix);
|
59
|
+
xns = xmlNewNs(xnode, (xmlChar*) StringValuePtr(href), xmlPrefix);
|
60
|
+
|
61
|
+
DATA_PTR(self) = xns;
|
62
|
+
return self;
|
63
|
+
}
|
64
|
+
|
65
|
+
/*
|
66
|
+
* call-seq:
|
67
|
+
* ns.href -> "href"
|
68
|
+
*
|
69
|
+
* Usage:
|
70
|
+
*
|
71
|
+
* doc = XML::Document.string('<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"/>')
|
72
|
+
* ns = doc.root.namespaces.find_by_href('http://schemas.xmlsoap.org/soap/envelope/')
|
73
|
+
* assert_equal('http://schemas.xmlsoap.org/soap/envelope/', ns.href)
|
74
|
+
*/
|
75
|
+
static VALUE rxml_namespace_href_get(VALUE self)
|
76
|
+
{
|
77
|
+
xmlNsPtr xns;
|
78
|
+
Data_Get_Struct(self, xmlNs, xns);
|
79
|
+
if (xns->href == NULL)
|
80
|
+
return Qnil;
|
81
|
+
else
|
82
|
+
return rxml_new_cstr( xns->href, NULL);
|
83
|
+
}
|
84
|
+
|
85
|
+
/*
|
86
|
+
* call-seq:
|
87
|
+
* ns.node_type -> num
|
88
|
+
*
|
89
|
+
* Obtain this namespace's type identifier.
|
90
|
+
*/
|
91
|
+
static VALUE rxml_namespace_node_type(VALUE self)
|
92
|
+
{
|
93
|
+
xmlNsPtr xns;
|
94
|
+
Data_Get_Struct(self, xmlNs, xns);
|
95
|
+
return INT2NUM(xns->type);
|
96
|
+
}
|
97
|
+
|
98
|
+
/*
|
99
|
+
* call-seq:
|
100
|
+
* ns.prefix -> "prefix"
|
101
|
+
*
|
102
|
+
* Obtain the namespace's prefix.
|
103
|
+
*
|
104
|
+
* Usage:
|
105
|
+
*
|
106
|
+
* doc = XML::Document.string('<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"/>')
|
107
|
+
* ns = doc.root.namespaces.find_by_href('http://schemas.xmlsoap.org/soap/envelope/')
|
108
|
+
* assert_equal('soap', ns.prefix)
|
109
|
+
*/
|
110
|
+
static VALUE rxml_namespace_prefix_get(VALUE self)
|
111
|
+
{
|
112
|
+
xmlNsPtr xns;
|
113
|
+
Data_Get_Struct(self, xmlNs, xns);
|
114
|
+
if (xns->prefix == NULL)
|
115
|
+
return Qnil;
|
116
|
+
else
|
117
|
+
return rxml_new_cstr( xns->prefix, NULL);
|
118
|
+
}
|
119
|
+
|
120
|
+
/*
|
121
|
+
* call-seq:
|
122
|
+
* ns.next -> XML::Namespace
|
123
|
+
*
|
124
|
+
* Obtain the next namespace.
|
125
|
+
*
|
126
|
+
* Usage:
|
127
|
+
*
|
128
|
+
* doc = XML::Document.string('<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"/>')
|
129
|
+
* ns = doc.root.namespaces.find_by_href('http://schemas.xmlsoap.org/soap/envelope/')
|
130
|
+
* assert_nil(ns.next)
|
131
|
+
*/
|
132
|
+
static VALUE rxml_namespace_next(VALUE self)
|
133
|
+
{
|
134
|
+
xmlNsPtr xns;
|
135
|
+
Data_Get_Struct(self, xmlNs, xns);
|
136
|
+
if (xns == NULL || xns->next == NULL)
|
137
|
+
return (Qnil);
|
138
|
+
else
|
139
|
+
return rxml_namespace_wrap(xns->next);
|
140
|
+
}
|
141
|
+
|
142
|
+
void rxml_init_namespace(void)
|
143
|
+
{
|
144
|
+
cXMLNamespace = rb_define_class_under(mXML, "Namespace", rb_cObject);
|
145
|
+
rb_define_alloc_func(cXMLNamespace, rxml_namespace_alloc);
|
146
|
+
rb_define_method(cXMLNamespace, "initialize", rxml_namespace_initialize, 3);
|
147
|
+
rb_define_method(cXMLNamespace, "href", rxml_namespace_href_get, 0);
|
148
|
+
rb_define_method(cXMLNamespace, "next", rxml_namespace_next, 0);
|
149
|
+
rb_define_method(cXMLNamespace, "node_type", rxml_namespace_node_type, 0);
|
150
|
+
rb_define_method(cXMLNamespace, "prefix", rxml_namespace_prefix_get, 0);
|
151
|
+
}
|