libxml-ruby 0.9.8-x86-mswin32-60 → 0.9.9-x86-mswin32-60
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.
- data/CHANGES +41 -1
- data/LICENSE +3 -4
- data/README +37 -24
- data/Rakefile +2 -2
- data/ext/libxml/extconf.rb +31 -12
- data/ext/libxml/libxml.c +56 -858
- data/ext/libxml/ruby_libxml.h +93 -96
- data/ext/libxml/ruby_xml.c +855 -0
- data/ext/libxml/ruby_xml.h +9 -0
- data/ext/libxml/ruby_xml_attr.c +3 -9
- data/ext/libxml/ruby_xml_attr.h +2 -2
- data/ext/libxml/ruby_xml_attr_decl.c +2 -8
- data/ext/libxml/ruby_xml_attr_decl.h +1 -1
- data/ext/libxml/ruby_xml_attributes.c +6 -8
- data/ext/libxml/ruby_xml_attributes.h +1 -1
- data/ext/libxml/ruby_xml_document.c +915 -895
- data/ext/libxml/ruby_xml_document.h +2 -2
- data/ext/libxml/ruby_xml_dtd.c +257 -136
- data/ext/libxml/ruby_xml_dtd.h +1 -1
- data/ext/libxml/ruby_xml_encoding.c +55 -37
- data/ext/libxml/ruby_xml_encoding.h +1 -1
- data/ext/libxml/ruby_xml_error.c +526 -1058
- data/ext/libxml/ruby_xml_error.h +1 -1
- data/ext/libxml/ruby_xml_html_parser.c +2 -8
- data/ext/libxml/ruby_xml_html_parser.h +2 -2
- data/ext/libxml/ruby_xml_html_parser_context.c +175 -145
- data/ext/libxml/ruby_xml_html_parser_context.h +1 -1
- data/ext/libxml/ruby_xml_html_parser_options.c +12 -20
- data/ext/libxml/ruby_xml_html_parser_options.h +1 -1
- data/ext/libxml/ruby_xml_input_cbg.c +2 -8
- data/ext/libxml/ruby_xml_input_cbg.h +1 -1
- data/ext/libxml/ruby_xml_namespace.c +2 -8
- data/ext/libxml/ruby_xml_namespace.h +2 -2
- data/ext/libxml/ruby_xml_namespaces.c +1 -9
- data/ext/libxml/ruby_xml_namespaces.h +1 -1
- data/ext/libxml/ruby_xml_node.c +182 -121
- data/ext/libxml/ruby_xml_node.h +2 -2
- data/ext/libxml/ruby_xml_parser.c +2 -8
- data/ext/libxml/ruby_xml_parser.h +2 -2
- data/ext/libxml/ruby_xml_parser_context.c +952 -901
- data/ext/libxml/ruby_xml_parser_context.h +2 -2
- data/ext/libxml/ruby_xml_parser_options.c +2 -9
- data/ext/libxml/ruby_xml_parser_options.h +1 -1
- data/ext/libxml/ruby_xml_reader.c +1002 -993
- data/ext/libxml/ruby_xml_reader.h +1 -1
- data/ext/libxml/ruby_xml_relaxng.c +1 -7
- data/ext/libxml/ruby_xml_relaxng.h +1 -1
- data/ext/libxml/ruby_xml_sax2_handler.c +2 -2
- data/ext/libxml/ruby_xml_sax2_handler.h +1 -1
- data/ext/libxml/ruby_xml_sax_parser.c +2 -8
- data/ext/libxml/ruby_xml_sax_parser.h +2 -2
- data/ext/libxml/ruby_xml_schema.c +1 -7
- data/ext/libxml/ruby_xml_schema.h +1 -1
- data/ext/libxml/{version.h → ruby_xml_version.h} +2 -2
- data/ext/libxml/ruby_xml_xinclude.c +2 -8
- data/ext/libxml/ruby_xml_xinclude.h +2 -2
- data/ext/libxml/ruby_xml_xpath.c +17 -18
- data/ext/libxml/ruby_xml_xpath.h +2 -2
- data/ext/libxml/ruby_xml_xpath_context.c +387 -389
- data/ext/libxml/ruby_xml_xpath_context.h +2 -2
- data/ext/libxml/ruby_xml_xpath_expression.c +18 -8
- data/ext/libxml/ruby_xml_xpath_expression.h +1 -1
- data/ext/libxml/ruby_xml_xpath_object.c +19 -8
- data/ext/libxml/ruby_xml_xpath_object.h +1 -1
- data/ext/libxml/ruby_xml_xpointer.c +2 -8
- data/ext/libxml/ruby_xml_xpointer.h +2 -2
- data/ext/mingw/libxml_ruby.dll.a +0 -0
- data/ext/mingw/libxml_ruby.so +0 -0
- data/ext/vc/libxml_ruby.sln +7 -1
- data/lib/libxml.rb +1 -12
- data/lib/libxml/attr.rb +0 -3
- data/lib/libxml/attr_decl.rb +0 -3
- data/lib/libxml/attributes.rb +0 -3
- data/lib/libxml/document.rb +31 -5
- data/lib/libxml/error.rb +8 -4
- data/lib/libxml/properties.rb +0 -5
- data/lib/libxml/sax_callbacks.rb +30 -19
- data/lib/libxml/tree.rb +0 -1
- data/lib/libxml/xpath_object.rb +0 -13
- data/test/model/definition.dtd +8 -0
- data/test/tc_attributes.rb +4 -1
- data/test/tc_document.rb +16 -0
- data/test/tc_dtd.rb +30 -2
- data/test/tc_html_parser.rb +55 -10
- data/test/tc_node.rb +67 -1
- data/test/tc_node_edit.rb +26 -6
- data/test/tc_node_text.rb +41 -23
- data/test/tc_parser.rb +50 -0
- data/test/tc_reader.rb +15 -0
- data/test/tc_relaxng.rb +1 -1
- data/test/tc_sax_parser.rb +37 -5
- data/test/tc_schema.rb +1 -1
- data/test/tc_xpath.rb +1 -0
- data/test/tc_xpath_expression.rb +4 -2
- metadata +6 -6
- data/ext/libxml/ruby_xml_state.c +0 -51
- data/ext/libxml/ruby_xml_state.h +0 -11
- data/ext/vc/libxml_ruby.vcproj +0 -460
@@ -32,12 +32,6 @@
|
|
32
32
|
|
33
33
|
VALUE cXMLRelaxNG;
|
34
34
|
|
35
|
-
// Rdoc needs to know
|
36
|
-
#ifdef RDOC_NEVER_DEFINED
|
37
|
-
mLibXML = rb_define_module("LibXML");
|
38
|
-
mXML = rb_define_module_under(mLibXML, "XML");
|
39
|
-
#endif
|
40
|
-
|
41
35
|
static void rxml_relaxng_free(xmlRelaxNGPtr xrelaxng)
|
42
36
|
{
|
43
37
|
xmlRelaxNGFree(xrelaxng);
|
@@ -105,7 +99,7 @@ static VALUE rxml_relaxng_init_from_string(VALUE self, VALUE relaxng_str)
|
|
105
99
|
return Data_Wrap_Struct(cXMLRelaxNG, NULL, rxml_relaxng_free, xrelaxng);
|
106
100
|
}
|
107
101
|
|
108
|
-
void
|
102
|
+
void rxml_init_relaxng(void)
|
109
103
|
{
|
110
104
|
cXMLRelaxNG = rb_define_class_under(mXML, "RelaxNG", rb_cObject);
|
111
105
|
rb_define_singleton_method(cXMLRelaxNG, "new", rxml_relaxng_init_from_uri, 1);
|
@@ -222,7 +222,7 @@ static void start_element_ns_callback(void *ctx,
|
|
222
222
|
{
|
223
223
|
VALUE nsPrefix = xnamespaces[i+0] ? rb_str_new2(xnamespaces[i+0]) : Qnil;
|
224
224
|
VALUE nsURI = xnamespaces[i+1] ? rb_str_new2(xnamespaces[i+1]) : Qnil;
|
225
|
-
rb_hash_aset(
|
225
|
+
rb_hash_aset(namespaces, nsPrefix, nsURI);
|
226
226
|
}
|
227
227
|
}
|
228
228
|
|
@@ -298,7 +298,7 @@ xmlSAXHandler rxml_sax_handler = {
|
|
298
298
|
(xmlStructuredErrorFunc) structured_error_callback
|
299
299
|
};
|
300
300
|
|
301
|
-
void
|
301
|
+
void rxml_init_sax2_handler(void)
|
302
302
|
{
|
303
303
|
|
304
304
|
/* SaxCallbacks */
|
@@ -1,4 +1,4 @@
|
|
1
|
-
/* $Id: ruby_xml_sax_parser.c
|
1
|
+
/* $Id: ruby_xml_sax_parser.c 758 2009-01-25 20:36:03Z cfis $ */
|
2
2
|
|
3
3
|
/* Please see the LICENSE file for copyright and distribution information */
|
4
4
|
|
@@ -121,13 +121,7 @@ static VALUE rxml_sax_parser_parse(VALUE self)
|
|
121
121
|
return Qtrue;
|
122
122
|
}
|
123
123
|
|
124
|
-
|
125
|
-
#ifdef RDOC_NEVER_DEFINED
|
126
|
-
mLibXML = rb_define_module("LibXML");
|
127
|
-
mXML = rb_define_module_under(mLibXML, "XML");
|
128
|
-
#endif
|
129
|
-
|
130
|
-
void ruby_init_xml_sax_parser(void)
|
124
|
+
void rxml_init_sax_parser(void)
|
131
125
|
{
|
132
126
|
/* SaxParser */
|
133
127
|
cXMLSaxParser = rb_define_class_under(mXML, "SaxParser", rb_cObject);
|
@@ -1,4 +1,4 @@
|
|
1
|
-
/* $Id: ruby_xml_sax_parser.h
|
1
|
+
/* $Id: ruby_xml_sax_parser.h 758 2009-01-25 20:36:03Z cfis $ */
|
2
2
|
|
3
3
|
/* Please see the LICENSE file for copyright and distribution information */
|
4
4
|
|
@@ -7,6 +7,6 @@
|
|
7
7
|
|
8
8
|
extern VALUE cXMLSaxParser;
|
9
9
|
|
10
|
-
void
|
10
|
+
void rxml_init_sax_parser(void);
|
11
11
|
|
12
12
|
#endif
|
@@ -32,12 +32,6 @@
|
|
32
32
|
|
33
33
|
VALUE cXMLSchema;
|
34
34
|
|
35
|
-
// Rdoc needs to know
|
36
|
-
#ifdef RDOC_NEVER_DEFINED
|
37
|
-
mLibXML = rb_define_module("LibXML");
|
38
|
-
mXML = rb_define_module_under(mLibXML, "XML");
|
39
|
-
#endif
|
40
|
-
|
41
35
|
static void rxml_schema_free(xmlSchemaPtr xschema)
|
42
36
|
{
|
43
37
|
xmlSchemaFree(xschema);
|
@@ -153,7 +147,7 @@ static VALUE rxml_schema_init_from_string(VALUE self, VALUE schema_str)
|
|
153
147
|
} else if (!strcmp(method, "validate_schema_buffer")) {
|
154
148
|
*/
|
155
149
|
|
156
|
-
void
|
150
|
+
void rxml_init_schema(void)
|
157
151
|
{
|
158
152
|
cXMLSchema = rb_define_class_under(mXML, "Schema", rb_cObject);
|
159
153
|
rb_define_singleton_method(cXMLSchema, "new", rxml_schema_init_from_uri, 1);
|
@@ -1,9 +1,9 @@
|
|
1
1
|
/* Don't nuke this block! It is used for automatically updating the
|
2
2
|
* versions below. VERSION = string formatting, VERNUM = numbered
|
3
3
|
* version for inline testing: increment both or none at all.*/
|
4
|
-
#define RUBY_LIBXML_VERSION "0.9.
|
4
|
+
#define RUBY_LIBXML_VERSION "0.9.9"
|
5
5
|
#define RUBY_LIBXML_VERNUM 0
|
6
6
|
#define RUBY_LIBXML_VER_MAJ 0
|
7
7
|
#define RUBY_LIBXML_VER_MIN 9
|
8
|
-
#define RUBY_LIBXML_VER_MIC
|
8
|
+
#define RUBY_LIBXML_VER_MIC 9
|
9
9
|
#define RUBY_LIBXML_VER_PATCH 0
|
@@ -1,4 +1,4 @@
|
|
1
|
-
/* $Id: ruby_xml_xinclude.c
|
1
|
+
/* $Id: ruby_xml_xinclude.c 758 2009-01-25 20:36:03Z cfis $ */
|
2
2
|
|
3
3
|
#include "ruby_libxml.h"
|
4
4
|
#include "ruby_xml_xinclude.h"
|
@@ -12,13 +12,7 @@ VALUE cXMLXInclude;
|
|
12
12
|
* XInclude fuctionality.
|
13
13
|
*/
|
14
14
|
|
15
|
-
|
16
|
-
#ifdef RDOC_NEVER_DEFINED
|
17
|
-
mLibXML = rb_define_module("LibXML");
|
18
|
-
mXML = rb_define_module_under(mLibXML, "XML");
|
19
|
-
#endif
|
20
|
-
|
21
|
-
void ruby_init_xml_xinclude(void)
|
15
|
+
void rxml_init_xinclude(void)
|
22
16
|
{
|
23
17
|
cXMLXInclude = rb_define_class_under(mXML, "XInclude", rb_cObject);
|
24
18
|
}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
/* $Id: ruby_xml_xinclude.h
|
1
|
+
/* $Id: ruby_xml_xinclude.h 758 2009-01-25 20:36:03Z cfis $ */
|
2
2
|
|
3
3
|
/* Please see the LICENSE file for copyright and distribution information */
|
4
4
|
|
@@ -8,6 +8,6 @@
|
|
8
8
|
extern VALUE cXMLXInclude;
|
9
9
|
extern VALUE eXMLXIncludeError;
|
10
10
|
|
11
|
-
void
|
11
|
+
void rxml_init_xinclude(void);
|
12
12
|
|
13
13
|
#endif
|
data/ext/libxml/ruby_xml_xpath.c
CHANGED
@@ -1,10 +1,4 @@
|
|
1
|
-
/* $Id: ruby_xml_xpath.c
|
2
|
-
|
3
|
-
/* Please see the LICENSE file for copyright and distribution information */
|
4
|
-
|
5
|
-
#include "ruby_libxml.h"
|
6
|
-
#include "ruby_xml_xpath.h"
|
7
|
-
#include "ruby_xml_xpath_context.h"
|
1
|
+
/* $Id: ruby_xml_xpath.c 759 2009-01-26 00:15:49Z cfis $ */
|
8
2
|
|
9
3
|
/*
|
10
4
|
* Document-class: LibXML::XML::XPath
|
@@ -78,31 +72,36 @@
|
|
78
72
|
* # Here is an example showing a complex namespace aware
|
79
73
|
* # xpath expression.
|
80
74
|
* doc.find('/soap:Envelope/soap:Body/ns0:getManufacturerNamesResponse/ns0:IDAndNameList/ns1:IdAndName',
|
81
|
-
['ns0:http://services.somewhere.com', 'ns1:http://domain.somewhere.com'])
|
82
|
-
|
75
|
+
* ['ns0:http://services.somewhere.com', 'ns1:http://domain.somewhere.com'])
|
76
|
+
*/
|
83
77
|
|
84
|
-
VALUE mXPath;
|
85
78
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
mXML = rb_define_module_under(mLibXML, "XML");
|
90
|
-
#endif
|
79
|
+
#include "ruby_libxml.h"
|
80
|
+
|
81
|
+
VALUE mXPath;
|
91
82
|
|
92
|
-
void
|
83
|
+
void rxml_init_xpath(void)
|
93
84
|
{
|
94
85
|
mXPath = rb_define_module_under(mXML, "XPath");
|
95
86
|
|
87
|
+
/* 0: Undefined value. */
|
96
88
|
rb_define_const(mXPath, "UNDEFINED", INT2NUM(XPATH_UNDEFINED));
|
89
|
+
/* 1: A nodeset, will be wrapped by XPath Object. */
|
97
90
|
rb_define_const(mXPath, "NODESET", INT2NUM(XPATH_NODESET));
|
91
|
+
/* 2: A boolean value. */
|
98
92
|
rb_define_const(mXPath, "BOOLEAN", INT2NUM(XPATH_BOOLEAN));
|
93
|
+
/* 3: A numeric value. */
|
99
94
|
rb_define_const(mXPath, "NUMBER", INT2NUM(XPATH_NUMBER));
|
95
|
+
/* 4: A string value. */
|
100
96
|
rb_define_const(mXPath, "STRING", INT2NUM(XPATH_STRING));
|
97
|
+
/* 5: An xpointer point */
|
101
98
|
rb_define_const(mXPath, "POINT", INT2NUM(XPATH_POINT));
|
99
|
+
/* 6: An xpointer range */
|
102
100
|
rb_define_const(mXPath, "RANGE", INT2NUM(XPATH_RANGE));
|
101
|
+
/* 7: An xpointer location set */
|
103
102
|
rb_define_const(mXPath, "LOCATIONSET", INT2NUM(XPATH_LOCATIONSET));
|
103
|
+
/* 8: XPath user type */
|
104
104
|
rb_define_const(mXPath, "USERS", INT2NUM(XPATH_USERS));
|
105
|
+
/* 9: An XSLT value tree, non modifiable */
|
105
106
|
rb_define_const(mXPath, "XSLT_TREE", INT2NUM(XPATH_XSLT_TREE));
|
106
|
-
|
107
|
-
ruby_init_xml_xpath_object();
|
108
107
|
}
|
data/ext/libxml/ruby_xml_xpath.h
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
/* $Id: ruby_xml_xpath.h
|
1
|
+
/* $Id: ruby_xml_xpath.h 758 2009-01-25 20:36:03Z cfis $ */
|
2
2
|
|
3
3
|
/* Please see the LICENSE file for copyright and distribution information */
|
4
4
|
|
@@ -7,6 +7,6 @@
|
|
7
7
|
|
8
8
|
extern VALUE mXPath;
|
9
9
|
|
10
|
-
void
|
10
|
+
void rxml_init_xpath(void);
|
11
11
|
|
12
12
|
#endif
|
@@ -1,389 +1,387 @@
|
|
1
|
-
/* $Id: ruby_xml_xpath_context.c
|
2
|
-
|
3
|
-
/* Please see the LICENSE file for copyright and distribution information */
|
4
|
-
|
5
|
-
#include "ruby_libxml.h"
|
6
|
-
#include "ruby_xml_xpath_context.h"
|
7
|
-
#include "ruby_xml_xpath_expression.h"
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
*
|
17
|
-
*
|
18
|
-
*
|
19
|
-
*
|
20
|
-
*
|
21
|
-
*
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
static
|
34
|
-
{
|
35
|
-
|
36
|
-
}
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
*
|
45
|
-
*
|
46
|
-
*
|
47
|
-
*
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
document
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
*
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
*
|
115
|
-
*
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
Data_Get_Struct(node,
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
}
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
*
|
178
|
-
*
|
179
|
-
*
|
180
|
-
*
|
181
|
-
*
|
182
|
-
*
|
183
|
-
*
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
{
|
204
|
-
rprefix =
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
*
|
235
|
-
*
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
xctxt
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
*
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
{
|
272
|
-
|
273
|
-
xobject =
|
274
|
-
}
|
275
|
-
else
|
276
|
-
{
|
277
|
-
|
278
|
-
|
279
|
-
}
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
*
|
322
|
-
*
|
323
|
-
*
|
324
|
-
* cache
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
if (
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
cXMLXPathContext
|
377
|
-
|
378
|
-
|
379
|
-
rb_define_method(cXMLXPathContext, "
|
380
|
-
rb_define_method(cXMLXPathContext, "
|
381
|
-
rb_define_method(cXMLXPathContext, "
|
382
|
-
rb_define_method(cXMLXPathContext, "
|
383
|
-
|
384
|
-
rb_define_method(cXMLXPathContext, "
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
#endif
|
389
|
-
}
|
1
|
+
/* $Id: ruby_xml_xpath_context.c 799 2009-03-02 01:45:24Z cfis $ */
|
2
|
+
|
3
|
+
/* Please see the LICENSE file for copyright and distribution information */
|
4
|
+
|
5
|
+
#include "ruby_libxml.h"
|
6
|
+
#include "ruby_xml_xpath_context.h"
|
7
|
+
#include "ruby_xml_xpath_expression.h"
|
8
|
+
|
9
|
+
#if RUBY_ST_H
|
10
|
+
#include <ruby/st.h>
|
11
|
+
#else
|
12
|
+
#include <st.h>
|
13
|
+
#endif
|
14
|
+
|
15
|
+
/*
|
16
|
+
* Document-class: LibXML::XML::XPath::Context
|
17
|
+
*
|
18
|
+
* The XML::XPath::Context class is used to evaluate XPath
|
19
|
+
* expressions. Generally, you should not directly use this class,
|
20
|
+
* but instead use the XML::Document#find and XML::Node#find methods.
|
21
|
+
*
|
22
|
+
* doc = XML::Document.string('<header>content</header>')
|
23
|
+
* context = XPath::Context.new(doc)
|
24
|
+
* context.node = doc.root
|
25
|
+
* context.register_namespaces_from_node(doc.root)
|
26
|
+
* nodes = context.find('/header')
|
27
|
+
*/
|
28
|
+
|
29
|
+
VALUE cXMLXPathContext;
|
30
|
+
|
31
|
+
static ID DOC_ATTRIBUTE;
|
32
|
+
|
33
|
+
static void rxml_xpath_context_free(xmlXPathContextPtr ctxt)
|
34
|
+
{
|
35
|
+
xmlXPathFreeContext(ctxt);
|
36
|
+
}
|
37
|
+
|
38
|
+
static VALUE rxml_xpath_context_alloc(VALUE klass)
|
39
|
+
{
|
40
|
+
return Data_Wrap_Struct(cXMLXPathContext, NULL, rxml_xpath_context_free, NULL);
|
41
|
+
}
|
42
|
+
|
43
|
+
/* call-seq:
|
44
|
+
* XPath::Context.new(node) -> XPath::Context
|
45
|
+
*
|
46
|
+
* Creates a new XPath context for the specified document. The
|
47
|
+
* context can then be used to evaluate an XPath expression.
|
48
|
+
*
|
49
|
+
* doc = XML::Document.string('<header><first>hi</first></header>')
|
50
|
+
* context = XPath::Context.new(doc)
|
51
|
+
* nodes = XPath::Object.new('//first', context)
|
52
|
+
* nodes.length == 1
|
53
|
+
*/
|
54
|
+
static VALUE rxml_xpath_context_initialize(VALUE self, VALUE node)
|
55
|
+
{
|
56
|
+
xmlDocPtr xdoc;
|
57
|
+
VALUE document;
|
58
|
+
|
59
|
+
if (rb_obj_is_kind_of(node, cXMLNode) == Qtrue)
|
60
|
+
{
|
61
|
+
document = rb_funcall(node, rb_intern("doc"), 0);
|
62
|
+
if (NIL_P(document))
|
63
|
+
rb_raise(rb_eTypeError, "Supplied node must belong to a document.");
|
64
|
+
}
|
65
|
+
else if (rb_obj_is_kind_of(node, cXMLDocument) == Qtrue)
|
66
|
+
{
|
67
|
+
document = node;
|
68
|
+
}
|
69
|
+
else
|
70
|
+
{
|
71
|
+
rb_raise(rb_eTypeError, "Supplied argument must be a document or node.");
|
72
|
+
}
|
73
|
+
|
74
|
+
Data_Get_Struct(document, xmlDoc, xdoc);
|
75
|
+
DATA_PTR(self) = xmlXPathNewContext(xdoc);
|
76
|
+
|
77
|
+
/* Save the doc as an attribute, this will expose it to Ruby's GC. */
|
78
|
+
rb_ivar_set(self, DOC_ATTRIBUTE, document);
|
79
|
+
|
80
|
+
return self;
|
81
|
+
}
|
82
|
+
|
83
|
+
/*
|
84
|
+
* call-seq:
|
85
|
+
* context.register_namespace(prefix, uri) -> (true|false)
|
86
|
+
*
|
87
|
+
* Register the specified namespace URI with the specified prefix
|
88
|
+
* in this context.
|
89
|
+
|
90
|
+
* context.register_namespace('xi', 'http://www.w3.org/2001/XInclude')
|
91
|
+
*/
|
92
|
+
static VALUE rxml_xpath_context_register_namespace(VALUE self, VALUE prefix, VALUE uri)
|
93
|
+
{
|
94
|
+
xmlXPathContextPtr ctxt;
|
95
|
+
Data_Get_Struct(self, xmlXPathContext, ctxt);
|
96
|
+
|
97
|
+
/* Prefix could be a symbol. */
|
98
|
+
prefix = rb_obj_as_string(prefix);
|
99
|
+
|
100
|
+
if (xmlXPathRegisterNs(ctxt, (xmlChar*) StringValuePtr(prefix),
|
101
|
+
(xmlChar*) StringValuePtr(uri)) == 0)
|
102
|
+
{
|
103
|
+
return (Qtrue);
|
104
|
+
}
|
105
|
+
else
|
106
|
+
{
|
107
|
+
/* Should raise an exception, IMHO (whose?, why shouldnt it? -danj)*/
|
108
|
+
rb_warning("register namespace failed");
|
109
|
+
return (Qfalse);
|
110
|
+
}
|
111
|
+
}
|
112
|
+
|
113
|
+
/* call-seq:
|
114
|
+
* context.register_namespaces_from_node(node) -> self
|
115
|
+
*
|
116
|
+
* Helper method to read in namespaces defined on a node.
|
117
|
+
*
|
118
|
+
* doc = XML::Document.string('<header><first>hi</first></header>')
|
119
|
+
* context = XPath::Context.new(doc)
|
120
|
+
* context.register_namespaces_from_node(doc.root)
|
121
|
+
*/
|
122
|
+
static VALUE rxml_xpath_context_register_namespaces_from_node(VALUE self,
|
123
|
+
VALUE node)
|
124
|
+
{
|
125
|
+
xmlXPathContextPtr xctxt;
|
126
|
+
xmlNodePtr xnode;
|
127
|
+
xmlNsPtr *xnsArr;
|
128
|
+
|
129
|
+
Data_Get_Struct(self, xmlXPathContext, xctxt);
|
130
|
+
|
131
|
+
if (rb_obj_is_kind_of(node, cXMLDocument) == Qtrue)
|
132
|
+
{
|
133
|
+
xmlDocPtr xdoc;
|
134
|
+
Data_Get_Struct(node, xmlDoc, xdoc);
|
135
|
+
xnode = xmlDocGetRootElement(xdoc);
|
136
|
+
}
|
137
|
+
else if (rb_obj_is_kind_of(node, cXMLNode) == Qtrue)
|
138
|
+
{
|
139
|
+
Data_Get_Struct(node, xmlNode, xnode);
|
140
|
+
}
|
141
|
+
else
|
142
|
+
{
|
143
|
+
rb_raise(rb_eTypeError, "The first argument must be a document or node.");
|
144
|
+
}
|
145
|
+
|
146
|
+
xnsArr = xmlGetNsList(xnode->doc, xnode);
|
147
|
+
|
148
|
+
if (xnsArr)
|
149
|
+
{
|
150
|
+
xmlNsPtr xns = *xnsArr;
|
151
|
+
|
152
|
+
while (xns)
|
153
|
+
{
|
154
|
+
/* If there is no prefix, then this is the default namespace.
|
155
|
+
Skip it for now. */
|
156
|
+
if (xns->prefix)
|
157
|
+
{
|
158
|
+
VALUE prefix = rb_str_new2((const char*)xns->prefix);
|
159
|
+
VALUE uri = rb_str_new2((const char*)xns->href);
|
160
|
+
rxml_xpath_context_register_namespace(self, prefix, uri);
|
161
|
+
}
|
162
|
+
xns = xns->next;
|
163
|
+
}
|
164
|
+
xmlFree(xnsArr);
|
165
|
+
}
|
166
|
+
|
167
|
+
return self;
|
168
|
+
}
|
169
|
+
|
170
|
+
static int iterate_ns_hash(st_data_t prefix, st_data_t uri, st_data_t self)
|
171
|
+
{
|
172
|
+
rxml_xpath_context_register_namespace(self, prefix, uri);
|
173
|
+
return ST_CONTINUE;
|
174
|
+
}
|
175
|
+
|
176
|
+
/*
|
177
|
+
* call-seq:
|
178
|
+
* context.register_namespaces(["prefix:uri"]) -> self
|
179
|
+
*
|
180
|
+
* Register the specified namespaces in this context. There are
|
181
|
+
* three different forms that libxml accepts. These include
|
182
|
+
* a string, an array of strings, or a hash table:
|
183
|
+
*
|
184
|
+
* context.register_namespaces('xi:http://www.w3.org/2001/XInclude')
|
185
|
+
* context.register_namespaces(['xlink:http://www.w3.org/1999/xlink',
|
186
|
+
* 'xi:http://www.w3.org/2001/XInclude')
|
187
|
+
* context.register_namespaces('xlink' => 'http://www.w3.org/1999/xlink',
|
188
|
+
* 'xi' => 'http://www.w3.org/2001/XInclude')
|
189
|
+
*/
|
190
|
+
static VALUE rxml_xpath_context_register_namespaces(VALUE self, VALUE nslist)
|
191
|
+
{
|
192
|
+
char *cp;
|
193
|
+
long i;
|
194
|
+
VALUE rprefix, ruri;
|
195
|
+
|
196
|
+
/* Need to loop through the 2nd argument and iterate through the
|
197
|
+
* list of namespaces that we want to allow */
|
198
|
+
switch (TYPE(nslist))
|
199
|
+
{
|
200
|
+
case T_STRING:
|
201
|
+
cp = strchr(StringValuePtr(nslist), (int) ':');
|
202
|
+
if (cp == NULL)
|
203
|
+
{
|
204
|
+
rprefix = nslist;
|
205
|
+
ruri = Qnil;
|
206
|
+
}
|
207
|
+
else
|
208
|
+
{
|
209
|
+
rprefix = rb_str_new(StringValuePtr(nslist), (int) ((long) cp
|
210
|
+
- (long) StringValuePtr(nslist)));
|
211
|
+
ruri = rb_str_new2(&cp[1]);
|
212
|
+
}
|
213
|
+
/* Should test the results of this */
|
214
|
+
rxml_xpath_context_register_namespace(self, rprefix, ruri);
|
215
|
+
break;
|
216
|
+
case T_ARRAY:
|
217
|
+
for (i = 0; i < RARRAY_LEN(nslist); i++)
|
218
|
+
{
|
219
|
+
rxml_xpath_context_register_namespaces(self, RARRAY_PTR(nslist)[i]);
|
220
|
+
}
|
221
|
+
break;
|
222
|
+
case T_HASH:
|
223
|
+
st_foreach(RHASH_TBL(nslist), iterate_ns_hash, self);
|
224
|
+
break;
|
225
|
+
default:
|
226
|
+
rb_raise(
|
227
|
+
rb_eArgError,
|
228
|
+
"Invalid argument type, only accept string, array of strings, or an array of arrays");
|
229
|
+
}
|
230
|
+
return self;
|
231
|
+
}
|
232
|
+
|
233
|
+
/*
|
234
|
+
* call-seq:
|
235
|
+
* context.node = node
|
236
|
+
*
|
237
|
+
* Set the current node used by the XPath engine
|
238
|
+
|
239
|
+
* doc = XML::Document.string('<header><first>hi</first></header>')
|
240
|
+
* context.node = doc.root.first
|
241
|
+
*/
|
242
|
+
static VALUE rxml_xpath_context_node_set(VALUE self, VALUE node)
|
243
|
+
{
|
244
|
+
xmlXPathContextPtr xctxt;
|
245
|
+
xmlNodePtr xnode;
|
246
|
+
|
247
|
+
Data_Get_Struct(self, xmlXPathContext, xctxt);
|
248
|
+
Data_Get_Struct(node, xmlNode, xnode);
|
249
|
+
xctxt->node = xnode;
|
250
|
+
return node;
|
251
|
+
}
|
252
|
+
|
253
|
+
/*
|
254
|
+
* call-seq:
|
255
|
+
* context.find("xpath") -> true|false|number|string|XML::XPath::Object
|
256
|
+
*
|
257
|
+
* Executes the provided xpath function. The result depends on the execution
|
258
|
+
* of the xpath statement. It may be true, false, a number, a string or
|
259
|
+
* a node set.
|
260
|
+
*/
|
261
|
+
static VALUE rxml_xpath_context_find(VALUE self, VALUE xpath_expr)
|
262
|
+
{
|
263
|
+
xmlXPathContextPtr xctxt;
|
264
|
+
xmlXPathObjectPtr xobject;
|
265
|
+
xmlXPathCompExprPtr xcompexpr;
|
266
|
+
VALUE result;
|
267
|
+
|
268
|
+
Data_Get_Struct(self, xmlXPathContext, xctxt);
|
269
|
+
|
270
|
+
if (TYPE(xpath_expr) == T_STRING)
|
271
|
+
{
|
272
|
+
VALUE expression = rb_check_string_type(xpath_expr);
|
273
|
+
xobject = xmlXPathEval((xmlChar*) StringValueCStr(expression), xctxt);
|
274
|
+
}
|
275
|
+
else if (rb_obj_is_kind_of(xpath_expr, cXMLXPathExpression))
|
276
|
+
{
|
277
|
+
Data_Get_Struct(xpath_expr, xmlXPathCompExpr, xcompexpr);
|
278
|
+
xobject = xmlXPathCompiledEval(xcompexpr, xctxt);
|
279
|
+
}
|
280
|
+
else
|
281
|
+
{
|
282
|
+
rb_raise(rb_eTypeError,
|
283
|
+
"Argument should be an intance of a String or XPath::Expression");
|
284
|
+
}
|
285
|
+
|
286
|
+
if (xobject == NULL)
|
287
|
+
{
|
288
|
+
/* xmlLastError is different than xctxt->lastError. Use
|
289
|
+
xmlLastError since it has the message set while xctxt->lastError
|
290
|
+
does not. */
|
291
|
+
xmlErrorPtr xerror = xmlGetLastError();
|
292
|
+
rxml_raise(xerror);
|
293
|
+
}
|
294
|
+
|
295
|
+
switch (xobject->type)
|
296
|
+
{
|
297
|
+
case XPATH_NODESET:
|
298
|
+
result = rxml_xpath_object_wrap(xctxt->doc, xobject);
|
299
|
+
break;
|
300
|
+
case XPATH_BOOLEAN:
|
301
|
+
result = (xobject->boolval != 0) ? Qtrue : Qfalse;
|
302
|
+
xmlXPathFreeObject(xobject);
|
303
|
+
break;
|
304
|
+
case XPATH_NUMBER:
|
305
|
+
result = rb_float_new(xobject->floatval);
|
306
|
+
xmlXPathFreeObject(xobject);
|
307
|
+
break;
|
308
|
+
case XPATH_STRING:
|
309
|
+
result = rb_str_new2((const char*)xobject->stringval);
|
310
|
+
xmlXPathFreeObject(xobject);
|
311
|
+
break;
|
312
|
+
default:
|
313
|
+
result = Qnil;
|
314
|
+
xmlXPathFreeObject(xobject);
|
315
|
+
}
|
316
|
+
return result;
|
317
|
+
}
|
318
|
+
|
319
|
+
#if LIBXML_VERSION >= 20626
|
320
|
+
/*
|
321
|
+
* call-seq:
|
322
|
+
* context.enable_cache(size = nil)
|
323
|
+
*
|
324
|
+
* Enables an XPath::Context's built-in cache. If the cache is
|
325
|
+
* enabled then XPath objects will be cached internally for reuse.
|
326
|
+
* The size parameter controls sets the maximum number of XPath objects
|
327
|
+
* that will be cached per XPath object type (node-set, string, number,
|
328
|
+
* boolean, and misc objects). Set size to nil to use the default
|
329
|
+
* cache size of 100.
|
330
|
+
*/
|
331
|
+
static VALUE
|
332
|
+
rxml_xpath_context_enable_cache(int argc, VALUE *argv, VALUE self)
|
333
|
+
{
|
334
|
+
xmlXPathContextPtr xctxt;
|
335
|
+
VALUE size;
|
336
|
+
int value = -1;
|
337
|
+
|
338
|
+
Data_Get_Struct(self, xmlXPathContext, xctxt);
|
339
|
+
|
340
|
+
if (rb_scan_args(argc, argv, "01", &size) == 1)
|
341
|
+
{
|
342
|
+
value = NUM2INT(size);
|
343
|
+
}
|
344
|
+
|
345
|
+
if (xmlXPathContextSetCache(xctxt, 1, value, 0) == -1)
|
346
|
+
rxml_raise(&xmlLastError);
|
347
|
+
|
348
|
+
return self;
|
349
|
+
}
|
350
|
+
|
351
|
+
/*
|
352
|
+
* call-seq:
|
353
|
+
* context.disable_cache
|
354
|
+
*
|
355
|
+
* Disables an XPath::Context's built-in cache.
|
356
|
+
*/
|
357
|
+
static VALUE
|
358
|
+
rxml_xpath_context_disable_cache(VALUE self)
|
359
|
+
{
|
360
|
+
xmlXPathContextPtr xctxt;
|
361
|
+
Data_Get_Struct(self, xmlXPathContext, xctxt);
|
362
|
+
|
363
|
+
if (xmlXPathContextSetCache(xctxt, 0, 0, 0) == -1)
|
364
|
+
rxml_raise(&xmlLastError);
|
365
|
+
|
366
|
+
return self;
|
367
|
+
}
|
368
|
+
#endif
|
369
|
+
|
370
|
+
void rxml_init_xpath_context(void)
|
371
|
+
{
|
372
|
+
DOC_ATTRIBUTE = rb_intern("@doc");
|
373
|
+
|
374
|
+
cXMLXPathContext = rb_define_class_under(mXPath, "Context", rb_cObject);
|
375
|
+
rb_define_alloc_func(cXMLXPathContext, rxml_xpath_context_alloc);
|
376
|
+
rb_define_attr(cXMLXPathContext, "doc", 1, 0);
|
377
|
+
rb_define_method(cXMLXPathContext, "initialize", rxml_xpath_context_initialize, 1);
|
378
|
+
rb_define_method(cXMLXPathContext, "register_namespaces", rxml_xpath_context_register_namespaces, 1);
|
379
|
+
rb_define_method(cXMLXPathContext, "register_namespaces_from_node", rxml_xpath_context_register_namespaces_from_node, 1);
|
380
|
+
rb_define_method(cXMLXPathContext, "register_namespace", rxml_xpath_context_register_namespace, 2);
|
381
|
+
rb_define_method(cXMLXPathContext, "node=", rxml_xpath_context_node_set, 1);
|
382
|
+
rb_define_method(cXMLXPathContext, "find", rxml_xpath_context_find, 1);
|
383
|
+
#if LIBXML_VERSION >= 20626
|
384
|
+
rb_define_method(cXMLXPathContext, "enable_cache", rxml_xpath_context_enable_cache, -1);
|
385
|
+
rb_define_method(cXMLXPathContext, "disable_cache", rxml_xpath_context_disable_cache, 0);
|
386
|
+
#endif
|
387
|
+
}
|