libxml-ruby 0.5.4 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +23 -23
- data/README +144 -144
- data/ext/libxml/extconf.rb +26 -27
- data/ext/libxml/libxml.c +7 -37
- data/ext/libxml/{libxml.h → ruby_libxml.h} +93 -98
- data/ext/libxml/ruby_xml_attr.c +405 -387
- data/ext/libxml/ruby_xml_attr.h +19 -18
- data/ext/libxml/ruby_xml_document.c +1111 -1115
- data/ext/libxml/ruby_xml_document.h +27 -24
- data/ext/libxml/ruby_xml_dtd.c +168 -168
- data/ext/libxml/ruby_xml_html_parser.c +449 -450
- data/ext/libxml/ruby_xml_html_parser.h +1 -1
- data/ext/libxml/ruby_xml_input_cbg.c +158 -158
- data/ext/libxml/ruby_xml_node.c +2410 -2395
- data/ext/libxml/ruby_xml_node.h +1 -1
- data/ext/libxml/ruby_xml_node_set.c +170 -170
- data/ext/libxml/ruby_xml_node_set.h +1 -1
- data/ext/libxml/ruby_xml_ns.c +153 -153
- data/ext/libxml/ruby_xml_ns.h +1 -1
- data/ext/libxml/ruby_xml_parser.c +1425 -1422
- data/ext/libxml/ruby_xml_parser.h +1 -1
- data/ext/libxml/ruby_xml_parser_context.c +750 -716
- data/ext/libxml/ruby_xml_parser_context.h +1 -1
- data/ext/libxml/ruby_xml_reader.c +900 -896
- data/ext/libxml/ruby_xml_sax_parser.c +485 -485
- data/ext/libxml/ruby_xml_sax_parser.h +1 -1
- data/ext/libxml/ruby_xml_schema.c +146 -142
- data/ext/libxml/ruby_xml_state.c +5 -6
- data/ext/libxml/ruby_xml_state.h +1 -0
- data/ext/libxml/ruby_xml_tree.c +43 -43
- data/ext/libxml/ruby_xml_tree.h +1 -1
- data/ext/libxml/ruby_xml_xinclude.c +20 -20
- data/ext/libxml/ruby_xml_xinclude.h +1 -1
- data/ext/libxml/ruby_xml_xpath.c +243 -252
- data/ext/libxml/ruby_xml_xpath.h +1 -1
- data/ext/libxml/ruby_xml_xpath_context.c +118 -118
- data/ext/libxml/ruby_xml_xpath_context.h +1 -1
- data/ext/libxml/ruby_xml_xpath_object.c +43 -29
- data/ext/libxml/ruby_xml_xpath_object.h +0 -1
- data/ext/libxml/ruby_xml_xpointer.c +100 -100
- data/ext/libxml/ruby_xml_xpointer.h +1 -1
- data/ext/libxml/ruby_xml_xpointer_context.c +21 -21
- data/ext/libxml/ruby_xml_xpointer_context.h +1 -1
- data/ext/libxml/sax_parser_callbacks.inc +213 -213
- data/ext/libxml/version.h +9 -9
- data/lib/libxml.rb +24 -3
- data/mingw/libiconv-2.dll +0 -0
- data/mingw/libxml2-2.dll +0 -0
- data/mingw/libxml_ruby.so +0 -0
- data/mingw/mingw.rake +36 -0
- data/test/dtd-test.rb +24 -24
- data/test/etc_doc_to_s.rb +1 -3
- data/test/ets_copy_bug.rb +21 -21
- data/test/ets_copy_bug2.rb +32 -32
- data/test/ets_copy_bug3.rb +38 -0
- data/test/ets_doc_file.rb +1 -0
- data/test/{model/default_validation_bug.rb → gc.log} +0 -0
- data/test/merge_bug.rb +55 -55
- data/test/schema-test.rb +74 -74
- data/test/tc_well_formed.rb +11 -0
- data/test/tc_xml_document.rb +52 -52
- data/test/tc_xml_document_write.rb +24 -24
- data/test/tc_xml_document_write2.rb +54 -54
- data/test/tc_xml_document_write3.rb +96 -96
- data/test/tc_xml_html_parser.rb +63 -63
- data/test/tc_xml_node.rb +59 -59
- data/test/tc_xml_node2.rb +25 -25
- data/test/tc_xml_node3.rb +27 -27
- data/test/tc_xml_node4.rb +86 -86
- data/test/tc_xml_node5.rb +52 -52
- data/test/tc_xml_node6.rb +27 -27
- data/test/tc_xml_node7.rb +35 -35
- data/test/tc_xml_node8.rb +32 -32
- data/test/tc_xml_node9.rb +32 -32
- data/test/tc_xml_node_set.rb +24 -24
- data/test/tc_xml_node_set2.rb +37 -37
- data/test/tc_xml_node_xlink.rb +28 -28
- data/test/tc_xml_parser.rb +190 -178
- data/test/tc_xml_parser2.rb +16 -17
- data/test/tc_xml_parser3.rb +23 -23
- data/test/tc_xml_parser4.rb +33 -33
- data/test/tc_xml_parser5.rb +27 -27
- data/test/tc_xml_parser6.rb +23 -23
- data/test/tc_xml_parser7.rb +28 -28
- data/test/tc_xml_parser8.rb +32 -32
- data/test/tc_xml_parser9.rb +11 -0
- data/test/tc_xml_parser_context.rb +88 -88
- data/test/tc_xml_reader.rb +112 -109
- data/test/tc_xml_sax_parser.rb +104 -94
- data/test/tc_xml_sax_parser2.rb +51 -0
- data/test/tc_xml_xinclude.rb +30 -30
- data/test/tc_xml_xpath.rb +38 -38
- data/test/tc_xml_xpath2.rb +14 -0
- data/test/tc_xml_xpointer.rb +78 -78
- data/vc/libxml.sln +20 -0
- data/vc/libxml.vcproj +389 -0
- data/work/Rakefile +247 -0
- data/work/task/make +26 -0
- data/work/task/memory +37 -0
- data/work/task/rdoc +39 -0
- data/work/task/setup +1616 -0
- data/work/task/test +29 -0
- data/work/test/ets_runner.rb +33 -0
- data/work/test/libxml_test.rb +3 -0
- data/work/test/runner.rb +0 -0
- data/work/test/runner_ets.rb +33 -0
- data/work/vc/debug/libxml.exp +0 -0
- data/work/vc/debug/libxml.ilk +0 -0
- data/work/vc/debug/libxml.lib +0 -0
- data/work/vc/debug/libxml.pdb +0 -0
- data/work/vc/debug/libxml.so +0 -0
- metadata +158 -189
- data/MANIFEST +0 -138
- data/NOTES +0 -9
- data/Rakefile +0 -38
- data/TODO +0 -75
- data/VERSION +0 -1
- data/log/Changelog-0.txt +0 -426
- data/log/Changelog.txt +0 -435
- data/meta/project.yaml +0 -27
- data/meta/unixname +0 -1
- data/setup.rb +0 -1472
- data/site/css/normal.css +0 -182
- data/site/img/raze-tiny.png +0 -0
- data/site/img/red-cube.jpg +0 -0
- data/site/img/xml-ruby.png +0 -0
- data/site/index.xml +0 -43
- data/site/install.xml +0 -77
- data/site/layout.rhtml +0 -38
- data/site/layout.xsl +0 -67
- data/site/license.xml +0 -32
- data/site/log/changelog.xml +0 -1324
- data/site/log/changelog.xsl +0 -42
- data/test/model/merge_bug_data.xml +0 -58
- data/test/model/rubynet.xml +0 -78
- data/test/model/rubynet_project +0 -13
- data/test/model/saxtest.xml +0 -5
- data/test/model/simple.xml +0 -7
- data/test/model/xinclude.xml +0 -5
data/ext/libxml/ruby_xml_xpath.c
CHANGED
@@ -1,252 +1,243 @@
|
|
1
|
-
/* $Id: ruby_xml_xpath.c
|
2
|
-
|
3
|
-
/* Please see the LICENSE file for copyright and distribution information */
|
4
|
-
|
5
|
-
#include "
|
6
|
-
#include "ruby_xml_xpath.h"
|
7
|
-
|
8
|
-
/*
|
9
|
-
* Document-class: XML::XPath
|
10
|
-
*
|
11
|
-
* Includes Enumerable.
|
12
|
-
*/
|
13
|
-
VALUE cXMLXPath;
|
14
|
-
VALUE eXMLXPathInvalidPath;
|
15
|
-
|
16
|
-
#ifdef LIBXML_XPATH_ENABLED
|
17
|
-
|
18
|
-
/*
|
19
|
-
* call-seq:
|
20
|
-
* xpath.debug => (true|false)
|
21
|
-
*
|
22
|
-
* Dump libxml debugging information to stdout.
|
23
|
-
* Requires Libxml be compiled with debugging enabled.
|
24
|
-
*/
|
25
|
-
VALUE
|
26
|
-
ruby_xml_xpath_debug(VALUE self) {
|
27
|
-
#ifdef LIBXML_DEBUG_ENABLED
|
28
|
-
ruby_xml_xpath *rxxp;
|
29
|
-
Data_Get_Struct(self, ruby_xml_xpath, rxxp);
|
30
|
-
|
31
|
-
if (rxxp->xpop != NULL) {
|
32
|
-
xmlXPathDebugDumpObject(stdout, rxxp->xpop, 0);
|
33
|
-
return(Qtrue);
|
34
|
-
} else {
|
35
|
-
return(Qfalse);
|
36
|
-
}
|
37
|
-
#else
|
38
|
-
rb_warn("libxml does not have debugging turned on");
|
39
|
-
return(Qfalse);
|
40
|
-
#endif
|
41
|
-
}
|
42
|
-
|
43
|
-
///////////////////////////////////////////////////
|
44
|
-
// TODO xpath_find is throwing TypeError:
|
45
|
-
//
|
46
|
-
// TypeError: can't convert nil into String
|
47
|
-
//
|
48
|
-
// When given a namespace when non exist.
|
49
|
-
void
|
50
|
-
ruby_xml_xpath_register_namespaces(VALUE nslist, VALUE xxpc, int level) {
|
51
|
-
char *cp;
|
52
|
-
long i;
|
53
|
-
VALUE rprefix, ruri;
|
54
|
-
ruby_xml_ns *rxns;
|
55
|
-
|
56
|
-
/* Need to loop through the 2nd argument and iterate through the
|
57
|
-
* list of namespaces that we want to allow */
|
58
|
-
switch (TYPE(nslist)) {
|
59
|
-
case T_STRING:
|
60
|
-
cp = strchr(StringValuePtr(nslist), (int)':');
|
61
|
-
if (cp == NULL) {
|
62
|
-
rprefix = nslist;
|
63
|
-
ruri = Qnil;
|
64
|
-
} else {
|
65
|
-
rprefix = rb_str_new(StringValuePtr(nslist), (int)((long)cp - (long)StringValuePtr(nslist)));
|
66
|
-
ruri = rb_str_new2(&cp[1]);
|
67
|
-
}
|
68
|
-
/* Should test the results of this */
|
69
|
-
ruby_xml_xpath_context_register_namespace(xxpc, rprefix, ruri);
|
70
|
-
break;
|
71
|
-
case T_ARRAY:
|
72
|
-
if ( level == 0 ) {
|
73
|
-
for (i = 0; i < RARRAY(nslist)->len; i++) {
|
74
|
-
ruby_xml_xpath_register_namespaces(RARRAY(nslist)->ptr[i],xxpc,1);
|
75
|
-
}
|
76
|
-
}
|
77
|
-
else {
|
78
|
-
// tuples of prefix/uri
|
79
|
-
if (RARRAY(nslist)->len == 2) {
|
80
|
-
rprefix = RARRAY(nslist)->ptr[0];
|
81
|
-
ruri = RARRAY(nslist)->ptr[1];
|
82
|
-
ruby_xml_xpath_context_register_namespace(xxpc, rprefix, ruri);
|
83
|
-
} else {
|
84
|
-
rb_raise(rb_eArgError, "nested array must be an array of strings, prefix and href/uri");
|
85
|
-
}
|
86
|
-
}
|
87
|
-
break;
|
88
|
-
default:
|
89
|
-
if (rb_obj_is_kind_of(nslist, cXMLNS) == Qtrue) {
|
90
|
-
Data_Get_Struct(nslist, ruby_xml_ns, rxns);
|
91
|
-
rprefix = rb_str_new2((const char*)rxns->ns->prefix);
|
92
|
-
ruri = rb_str_new2((const char*)rxns->ns->href);
|
93
|
-
ruby_xml_xpath_context_register_namespace(xxpc, rprefix, ruri);
|
94
|
-
} else
|
95
|
-
rb_raise(rb_eArgError, "Invalid argument type, only accept string, array of strings, or an array of arrays");
|
96
|
-
}
|
97
|
-
}
|
98
|
-
/*
|
99
|
-
* call-seq:
|
100
|
-
* XML::XPath.find(path, namespaces = [any]) => xpath
|
101
|
-
*
|
102
|
-
* Find nodes matching the specified xpath (and optionally any of the
|
103
|
-
* supplied namespaces) and return as an XML::Node::Set.
|
104
|
-
*
|
105
|
-
* The optional namespaces argument may take one of
|
106
|
-
* two forms:
|
107
|
-
*
|
108
|
-
* * A string in the form of: "prefix:uri", or
|
109
|
-
* * An array of:
|
110
|
-
* * strings in the form like above
|
111
|
-
* * arrays in the form of ['prefix','uri']
|
112
|
-
*
|
113
|
-
* If not specified, matching nodes from any namespace
|
114
|
-
* will be included.
|
115
|
-
*/
|
116
|
-
VALUE
|
117
|
-
ruby_xml_xpath_find(VALUE class, VALUE anode, VALUE xpath_expr, VALUE nslist) {
|
118
|
-
#ifdef LIBXML_XPATH_ENABLED
|
119
|
-
xmlXPathCompExprPtr comp;
|
120
|
-
xmlXPathObjectPtr xxpop;
|
121
|
-
ruby_xml_node *node;
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
VALUE
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
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
|
-
ctxt->
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
#ifdef
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
#
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
}
|
207
|
-
|
208
|
-
|
209
|
-
VALUE
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
cXMLXPath
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
rb_define_const(cXMLXPath, "
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
rb_define_singleton_method(cXMLXPath, "find", ruby_xml_xpath_findva, -1);
|
246
|
-
|
247
|
-
rb_define_method(cXMLXPath, "debug", ruby_xml_xpath_debug, 0);
|
248
|
-
|
249
|
-
ruby_init_xml_xpath_object();
|
250
|
-
}
|
251
|
-
|
252
|
-
#endif /* ifdef LIBXML_XPATH_ENABLED */
|
1
|
+
/* $Id: ruby_xml_xpath.c 300 2008-07-01 19:14:15Z cfis $ */
|
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
|
+
|
8
|
+
/*
|
9
|
+
* Document-class: XML::XPath
|
10
|
+
*
|
11
|
+
* Includes Enumerable.
|
12
|
+
*/
|
13
|
+
VALUE cXMLXPath;
|
14
|
+
VALUE eXMLXPathInvalidPath;
|
15
|
+
|
16
|
+
#ifdef LIBXML_XPATH_ENABLED
|
17
|
+
|
18
|
+
/*
|
19
|
+
* call-seq:
|
20
|
+
* xpath.debug => (true|false)
|
21
|
+
*
|
22
|
+
* Dump libxml debugging information to stdout.
|
23
|
+
* Requires Libxml be compiled with debugging enabled.
|
24
|
+
*/
|
25
|
+
VALUE
|
26
|
+
ruby_xml_xpath_debug(VALUE self) {
|
27
|
+
#ifdef LIBXML_DEBUG_ENABLED
|
28
|
+
ruby_xml_xpath *rxxp;
|
29
|
+
Data_Get_Struct(self, ruby_xml_xpath, rxxp);
|
30
|
+
|
31
|
+
if (rxxp->xpop != NULL) {
|
32
|
+
xmlXPathDebugDumpObject(stdout, rxxp->xpop, 0);
|
33
|
+
return(Qtrue);
|
34
|
+
} else {
|
35
|
+
return(Qfalse);
|
36
|
+
}
|
37
|
+
#else
|
38
|
+
rb_warn("libxml does not have debugging turned on");
|
39
|
+
return(Qfalse);
|
40
|
+
#endif
|
41
|
+
}
|
42
|
+
|
43
|
+
///////////////////////////////////////////////////
|
44
|
+
// TODO xpath_find is throwing TypeError:
|
45
|
+
//
|
46
|
+
// TypeError: can't convert nil into String
|
47
|
+
//
|
48
|
+
// When given a namespace when non exist.
|
49
|
+
void
|
50
|
+
ruby_xml_xpath_register_namespaces(VALUE nslist, VALUE xxpc, int level) {
|
51
|
+
char *cp;
|
52
|
+
long i;
|
53
|
+
VALUE rprefix, ruri;
|
54
|
+
ruby_xml_ns *rxns;
|
55
|
+
|
56
|
+
/* Need to loop through the 2nd argument and iterate through the
|
57
|
+
* list of namespaces that we want to allow */
|
58
|
+
switch (TYPE(nslist)) {
|
59
|
+
case T_STRING:
|
60
|
+
cp = strchr(StringValuePtr(nslist), (int)':');
|
61
|
+
if (cp == NULL) {
|
62
|
+
rprefix = nslist;
|
63
|
+
ruri = Qnil;
|
64
|
+
} else {
|
65
|
+
rprefix = rb_str_new(StringValuePtr(nslist), (int)((long)cp - (long)StringValuePtr(nslist)));
|
66
|
+
ruri = rb_str_new2(&cp[1]);
|
67
|
+
}
|
68
|
+
/* Should test the results of this */
|
69
|
+
ruby_xml_xpath_context_register_namespace(xxpc, rprefix, ruri);
|
70
|
+
break;
|
71
|
+
case T_ARRAY:
|
72
|
+
if ( level == 0 ) {
|
73
|
+
for (i = 0; i < RARRAY(nslist)->len; i++) {
|
74
|
+
ruby_xml_xpath_register_namespaces(RARRAY(nslist)->ptr[i],xxpc,1);
|
75
|
+
}
|
76
|
+
}
|
77
|
+
else {
|
78
|
+
// tuples of prefix/uri
|
79
|
+
if (RARRAY(nslist)->len == 2) {
|
80
|
+
rprefix = RARRAY(nslist)->ptr[0];
|
81
|
+
ruri = RARRAY(nslist)->ptr[1];
|
82
|
+
ruby_xml_xpath_context_register_namespace(xxpc, rprefix, ruri);
|
83
|
+
} else {
|
84
|
+
rb_raise(rb_eArgError, "nested array must be an array of strings, prefix and href/uri");
|
85
|
+
}
|
86
|
+
}
|
87
|
+
break;
|
88
|
+
default:
|
89
|
+
if (rb_obj_is_kind_of(nslist, cXMLNS) == Qtrue) {
|
90
|
+
Data_Get_Struct(nslist, ruby_xml_ns, rxns);
|
91
|
+
rprefix = rb_str_new2((const char*)rxns->ns->prefix);
|
92
|
+
ruri = rb_str_new2((const char*)rxns->ns->href);
|
93
|
+
ruby_xml_xpath_context_register_namespace(xxpc, rprefix, ruri);
|
94
|
+
} else
|
95
|
+
rb_raise(rb_eArgError, "Invalid argument type, only accept string, array of strings, or an array of arrays");
|
96
|
+
}
|
97
|
+
}
|
98
|
+
/*
|
99
|
+
* call-seq:
|
100
|
+
* XML::XPath.find(path, namespaces = [any]) => xpath
|
101
|
+
*
|
102
|
+
* Find nodes matching the specified xpath (and optionally any of the
|
103
|
+
* supplied namespaces) and return as an XML::Node::Set.
|
104
|
+
*
|
105
|
+
* The optional namespaces argument may take one of
|
106
|
+
* two forms:
|
107
|
+
*
|
108
|
+
* * A string in the form of: "prefix:uri", or
|
109
|
+
* * An array of:
|
110
|
+
* * strings in the form like above
|
111
|
+
* * arrays in the form of ['prefix','uri']
|
112
|
+
*
|
113
|
+
* If not specified, matching nodes from any namespace
|
114
|
+
* will be included.
|
115
|
+
*/
|
116
|
+
VALUE
|
117
|
+
ruby_xml_xpath_find(VALUE class, VALUE anode, VALUE xpath_expr, VALUE nslist) {
|
118
|
+
#ifdef LIBXML_XPATH_ENABLED
|
119
|
+
xmlXPathCompExprPtr comp;
|
120
|
+
xmlXPathObjectPtr xxpop;
|
121
|
+
ruby_xml_node *node;
|
122
|
+
xmlXPathContextPtr ctxt;
|
123
|
+
ruby_xml_document_t *rdocp;
|
124
|
+
VALUE rnode, xxpc;
|
125
|
+
VALUE rxpop;
|
126
|
+
|
127
|
+
if (rb_obj_is_kind_of(anode, cXMLDocument) == Qtrue) {
|
128
|
+
xxpc = ruby_xml_xpath_context_new(anode);
|
129
|
+
Data_Get_Struct(anode, ruby_xml_document_t, rdocp);
|
130
|
+
#ifdef DEBUG
|
131
|
+
fprintf(stderr,"rdocp=0x%x root=0x%x\n",rdocp,xmlDocGetRootElement(rdocp->doc));
|
132
|
+
#endif
|
133
|
+
rnode=ruby_xml_node2_wrap(cXMLNode,xmlDocGetRootElement(rdocp->doc));
|
134
|
+
#ifdef DEBUG
|
135
|
+
fprintf(stderr,"rnode 0x%x 0x%x\n",rnode,xmlDocGetRootElement(rdocp->doc)->_private);
|
136
|
+
#endif
|
137
|
+
Data_Get_Struct(rnode, ruby_xml_node, node);
|
138
|
+
} else if ( rb_obj_is_kind_of(anode, cXMLNode) == Qtrue) {
|
139
|
+
xxpc = ruby_xml_xpath_context_new(anode);
|
140
|
+
Data_Get_Struct(anode, ruby_xml_node, node);
|
141
|
+
} else
|
142
|
+
rb_raise(rb_eTypeError, "arg 1 must be XML::Document or XML::Node within a document %s", rb_obj_as_string(anode));
|
143
|
+
|
144
|
+
if (NIL_P(xxpc))
|
145
|
+
return(Qnil);
|
146
|
+
|
147
|
+
Data_Get_Struct(xxpc,xmlXPathContext,ctxt);
|
148
|
+
// XXX Is this legal? Set a subtree to apply xpath?
|
149
|
+
ctxt->node = node->node;
|
150
|
+
|
151
|
+
// XXX is setting ->namespaces used?
|
152
|
+
if (node->node->type == XML_DOCUMENT_NODE) {
|
153
|
+
ctxt->namespaces = xmlGetNsList(node->node->doc,
|
154
|
+
xmlDocGetRootElement(node->node->doc));
|
155
|
+
} else {
|
156
|
+
ctxt->namespaces = xmlGetNsList(node->node->doc, node->node);
|
157
|
+
}
|
158
|
+
|
159
|
+
ctxt->nsNr = 0;
|
160
|
+
if (ctxt->namespaces != NULL) {
|
161
|
+
while (ctxt->namespaces[ctxt->nsNr] != NULL)
|
162
|
+
ctxt->nsNr++;
|
163
|
+
}
|
164
|
+
|
165
|
+
if ( ! NIL_P(nslist) )
|
166
|
+
ruby_xml_xpath_register_namespaces(nslist,xxpc,0);
|
167
|
+
|
168
|
+
comp = xmlXPathCompile((xmlChar*)StringValuePtr(xpath_expr));
|
169
|
+
|
170
|
+
if (comp == NULL) {
|
171
|
+
rb_raise(eXMLXPathInvalidPath,
|
172
|
+
"Invalid XPath expression (expr does not compile)");
|
173
|
+
}
|
174
|
+
xxpop=xmlXPathCompiledEval(comp, ctxt);
|
175
|
+
if ( xxpop == NULL )
|
176
|
+
return Qnil;
|
177
|
+
|
178
|
+
rxpop = ruby_xml_xpath_object_wrap(xxpop);
|
179
|
+
|
180
|
+
#ifdef NODE_DEBUG
|
181
|
+
fprintf(stderr,"xpo 0x%x class=%s\n",
|
182
|
+
rxpop,
|
183
|
+
rb_class2name(rb_obj_class(rxpop)));
|
184
|
+
#endif
|
185
|
+
|
186
|
+
xmlXPathFreeCompExpr(comp);
|
187
|
+
|
188
|
+
if (rxpop == Qnil)
|
189
|
+
rb_raise(eXMLXPathInvalidPath,
|
190
|
+
"Invalid XPath expression for this document");
|
191
|
+
|
192
|
+
return rxpop;
|
193
|
+
#else
|
194
|
+
rb_warn("libxml was compiled without XPath support");
|
195
|
+
return(Qfalse);
|
196
|
+
#endif
|
197
|
+
}
|
198
|
+
|
199
|
+
|
200
|
+
VALUE
|
201
|
+
ruby_xml_xpath_findva(int argc, VALUE *argv, VALUE class) {
|
202
|
+
if ( argc < 2 || argc > 3 )
|
203
|
+
rb_raise(rb_eArgError, "wrong number of arguments (1 or 2)");
|
204
|
+
|
205
|
+
return ruby_xml_xpath_find(class,argv[0],argv[1],(argc==3)?argv[2]:Qnil);
|
206
|
+
}
|
207
|
+
|
208
|
+
VALUE
|
209
|
+
ruby_xml_xpath_find2(VALUE anode, VALUE xpath_expr, VALUE nslist) {
|
210
|
+
return ruby_xml_xpath_find(cXMLXPath, anode, xpath_expr, nslist);
|
211
|
+
}
|
212
|
+
|
213
|
+
// Rdoc needs to know
|
214
|
+
#ifdef RDOC_NEVER_DEFINED
|
215
|
+
mXML = rb_define_module("XML");
|
216
|
+
#endif
|
217
|
+
|
218
|
+
void
|
219
|
+
ruby_init_xml_xpath(void) {
|
220
|
+
cXMLXPath = rb_define_class_under(mXML, "XPath", rb_cObject);
|
221
|
+
rb_include_module(cXMLNode, rb_const_get(rb_cObject, rb_intern("Enumerable")));
|
222
|
+
|
223
|
+
eXMLXPathInvalidPath = rb_define_class_under(cXMLXPath, "InvalidPath", eXMLError);
|
224
|
+
|
225
|
+
rb_define_const(cXMLXPath, "UNDEFINED", INT2NUM(XPATH_UNDEFINED));
|
226
|
+
rb_define_const(cXMLXPath, "NODESET", INT2NUM(XPATH_NODESET));
|
227
|
+
rb_define_const(cXMLXPath, "BOOLEAN", INT2NUM(XPATH_BOOLEAN));
|
228
|
+
rb_define_const(cXMLXPath, "NUMBER", INT2NUM(XPATH_NUMBER));
|
229
|
+
rb_define_const(cXMLXPath, "STRING", INT2NUM(XPATH_STRING));
|
230
|
+
rb_define_const(cXMLXPath, "POINT", INT2NUM(XPATH_POINT));
|
231
|
+
rb_define_const(cXMLXPath, "RANGE", INT2NUM(XPATH_RANGE));
|
232
|
+
rb_define_const(cXMLXPath, "LOCATIONSET", INT2NUM(XPATH_LOCATIONSET));
|
233
|
+
rb_define_const(cXMLXPath, "USERS", INT2NUM(XPATH_USERS));
|
234
|
+
rb_define_const(cXMLXPath, "XSLT_TREE", INT2NUM(XPATH_XSLT_TREE));
|
235
|
+
|
236
|
+
rb_define_singleton_method(cXMLXPath, "find", ruby_xml_xpath_findva, -1);
|
237
|
+
|
238
|
+
rb_define_method(cXMLXPath, "debug", ruby_xml_xpath_debug, 0);
|
239
|
+
|
240
|
+
ruby_init_xml_xpath_object();
|
241
|
+
}
|
242
|
+
|
243
|
+
#endif /* ifdef LIBXML_XPATH_ENABLED */
|
data/ext/libxml/ruby_xml_xpath.h
CHANGED