libxml-ruby 0.5.4 → 0.6.0

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.
Files changed (139) hide show
  1. data/LICENSE +23 -23
  2. data/README +144 -144
  3. data/ext/libxml/extconf.rb +26 -27
  4. data/ext/libxml/libxml.c +7 -37
  5. data/ext/libxml/{libxml.h → ruby_libxml.h} +93 -98
  6. data/ext/libxml/ruby_xml_attr.c +405 -387
  7. data/ext/libxml/ruby_xml_attr.h +19 -18
  8. data/ext/libxml/ruby_xml_document.c +1111 -1115
  9. data/ext/libxml/ruby_xml_document.h +27 -24
  10. data/ext/libxml/ruby_xml_dtd.c +168 -168
  11. data/ext/libxml/ruby_xml_html_parser.c +449 -450
  12. data/ext/libxml/ruby_xml_html_parser.h +1 -1
  13. data/ext/libxml/ruby_xml_input_cbg.c +158 -158
  14. data/ext/libxml/ruby_xml_node.c +2410 -2395
  15. data/ext/libxml/ruby_xml_node.h +1 -1
  16. data/ext/libxml/ruby_xml_node_set.c +170 -170
  17. data/ext/libxml/ruby_xml_node_set.h +1 -1
  18. data/ext/libxml/ruby_xml_ns.c +153 -153
  19. data/ext/libxml/ruby_xml_ns.h +1 -1
  20. data/ext/libxml/ruby_xml_parser.c +1425 -1422
  21. data/ext/libxml/ruby_xml_parser.h +1 -1
  22. data/ext/libxml/ruby_xml_parser_context.c +750 -716
  23. data/ext/libxml/ruby_xml_parser_context.h +1 -1
  24. data/ext/libxml/ruby_xml_reader.c +900 -896
  25. data/ext/libxml/ruby_xml_sax_parser.c +485 -485
  26. data/ext/libxml/ruby_xml_sax_parser.h +1 -1
  27. data/ext/libxml/ruby_xml_schema.c +146 -142
  28. data/ext/libxml/ruby_xml_state.c +5 -6
  29. data/ext/libxml/ruby_xml_state.h +1 -0
  30. data/ext/libxml/ruby_xml_tree.c +43 -43
  31. data/ext/libxml/ruby_xml_tree.h +1 -1
  32. data/ext/libxml/ruby_xml_xinclude.c +20 -20
  33. data/ext/libxml/ruby_xml_xinclude.h +1 -1
  34. data/ext/libxml/ruby_xml_xpath.c +243 -252
  35. data/ext/libxml/ruby_xml_xpath.h +1 -1
  36. data/ext/libxml/ruby_xml_xpath_context.c +118 -118
  37. data/ext/libxml/ruby_xml_xpath_context.h +1 -1
  38. data/ext/libxml/ruby_xml_xpath_object.c +43 -29
  39. data/ext/libxml/ruby_xml_xpath_object.h +0 -1
  40. data/ext/libxml/ruby_xml_xpointer.c +100 -100
  41. data/ext/libxml/ruby_xml_xpointer.h +1 -1
  42. data/ext/libxml/ruby_xml_xpointer_context.c +21 -21
  43. data/ext/libxml/ruby_xml_xpointer_context.h +1 -1
  44. data/ext/libxml/sax_parser_callbacks.inc +213 -213
  45. data/ext/libxml/version.h +9 -9
  46. data/lib/libxml.rb +24 -3
  47. data/mingw/libiconv-2.dll +0 -0
  48. data/mingw/libxml2-2.dll +0 -0
  49. data/mingw/libxml_ruby.so +0 -0
  50. data/mingw/mingw.rake +36 -0
  51. data/test/dtd-test.rb +24 -24
  52. data/test/etc_doc_to_s.rb +1 -3
  53. data/test/ets_copy_bug.rb +21 -21
  54. data/test/ets_copy_bug2.rb +32 -32
  55. data/test/ets_copy_bug3.rb +38 -0
  56. data/test/ets_doc_file.rb +1 -0
  57. data/test/{model/default_validation_bug.rb → gc.log} +0 -0
  58. data/test/merge_bug.rb +55 -55
  59. data/test/schema-test.rb +74 -74
  60. data/test/tc_well_formed.rb +11 -0
  61. data/test/tc_xml_document.rb +52 -52
  62. data/test/tc_xml_document_write.rb +24 -24
  63. data/test/tc_xml_document_write2.rb +54 -54
  64. data/test/tc_xml_document_write3.rb +96 -96
  65. data/test/tc_xml_html_parser.rb +63 -63
  66. data/test/tc_xml_node.rb +59 -59
  67. data/test/tc_xml_node2.rb +25 -25
  68. data/test/tc_xml_node3.rb +27 -27
  69. data/test/tc_xml_node4.rb +86 -86
  70. data/test/tc_xml_node5.rb +52 -52
  71. data/test/tc_xml_node6.rb +27 -27
  72. data/test/tc_xml_node7.rb +35 -35
  73. data/test/tc_xml_node8.rb +32 -32
  74. data/test/tc_xml_node9.rb +32 -32
  75. data/test/tc_xml_node_set.rb +24 -24
  76. data/test/tc_xml_node_set2.rb +37 -37
  77. data/test/tc_xml_node_xlink.rb +28 -28
  78. data/test/tc_xml_parser.rb +190 -178
  79. data/test/tc_xml_parser2.rb +16 -17
  80. data/test/tc_xml_parser3.rb +23 -23
  81. data/test/tc_xml_parser4.rb +33 -33
  82. data/test/tc_xml_parser5.rb +27 -27
  83. data/test/tc_xml_parser6.rb +23 -23
  84. data/test/tc_xml_parser7.rb +28 -28
  85. data/test/tc_xml_parser8.rb +32 -32
  86. data/test/tc_xml_parser9.rb +11 -0
  87. data/test/tc_xml_parser_context.rb +88 -88
  88. data/test/tc_xml_reader.rb +112 -109
  89. data/test/tc_xml_sax_parser.rb +104 -94
  90. data/test/tc_xml_sax_parser2.rb +51 -0
  91. data/test/tc_xml_xinclude.rb +30 -30
  92. data/test/tc_xml_xpath.rb +38 -38
  93. data/test/tc_xml_xpath2.rb +14 -0
  94. data/test/tc_xml_xpointer.rb +78 -78
  95. data/vc/libxml.sln +20 -0
  96. data/vc/libxml.vcproj +389 -0
  97. data/work/Rakefile +247 -0
  98. data/work/task/make +26 -0
  99. data/work/task/memory +37 -0
  100. data/work/task/rdoc +39 -0
  101. data/work/task/setup +1616 -0
  102. data/work/task/test +29 -0
  103. data/work/test/ets_runner.rb +33 -0
  104. data/work/test/libxml_test.rb +3 -0
  105. data/work/test/runner.rb +0 -0
  106. data/work/test/runner_ets.rb +33 -0
  107. data/work/vc/debug/libxml.exp +0 -0
  108. data/work/vc/debug/libxml.ilk +0 -0
  109. data/work/vc/debug/libxml.lib +0 -0
  110. data/work/vc/debug/libxml.pdb +0 -0
  111. data/work/vc/debug/libxml.so +0 -0
  112. metadata +158 -189
  113. data/MANIFEST +0 -138
  114. data/NOTES +0 -9
  115. data/Rakefile +0 -38
  116. data/TODO +0 -75
  117. data/VERSION +0 -1
  118. data/log/Changelog-0.txt +0 -426
  119. data/log/Changelog.txt +0 -435
  120. data/meta/project.yaml +0 -27
  121. data/meta/unixname +0 -1
  122. data/setup.rb +0 -1472
  123. data/site/css/normal.css +0 -182
  124. data/site/img/raze-tiny.png +0 -0
  125. data/site/img/red-cube.jpg +0 -0
  126. data/site/img/xml-ruby.png +0 -0
  127. data/site/index.xml +0 -43
  128. data/site/install.xml +0 -77
  129. data/site/layout.rhtml +0 -38
  130. data/site/layout.xsl +0 -67
  131. data/site/license.xml +0 -32
  132. data/site/log/changelog.xml +0 -1324
  133. data/site/log/changelog.xsl +0 -42
  134. data/test/model/merge_bug_data.xml +0 -58
  135. data/test/model/rubynet.xml +0 -78
  136. data/test/model/rubynet_project +0 -13
  137. data/test/model/saxtest.xml +0 -5
  138. data/test/model/simple.xml +0 -7
  139. data/test/model/xinclude.xml +0 -5
@@ -1,252 +1,243 @@
1
- /* $Id: ruby_xml_xpath.c 225 2007-12-07 04:58:09Z transami $ */
2
-
3
- /* Please see the LICENSE file for copyright and distribution information */
4
-
5
- #include "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
- ruby_xml_xpath *rxxp;
123
- xmlXPathContextPtr ctxt;
124
- ruby_xml_document_t *rdocp;
125
- VALUE rnode, xxpc;
126
- VALUE rxpop;
127
-
128
- if (rb_obj_is_kind_of(anode, cXMLDocument) == Qtrue) {
129
- xxpc = ruby_xml_xpath_context_new(anode);
130
- Data_Get_Struct(anode, ruby_xml_document_t, rdocp);
131
- #ifdef DEBUG
132
- fprintf(stderr,"rdocp=0x%x root=0x%x\n",rdocp,xmlDocGetRootElement(rdocp->doc));
133
- #endif
134
- rnode=ruby_xml_node2_wrap(cXMLNode,xmlDocGetRootElement(rdocp->doc));
135
- #ifdef DEBUG
136
- fprintf(stderr,"rnode 0x%x 0x%x\n",rnode,xmlDocGetRootElement(rdocp->doc)->_private);
137
- #endif
138
- Data_Get_Struct(rnode, ruby_xml_node, node);
139
- } else if ( rb_obj_is_kind_of(anode, cXMLNode) == Qtrue) {
140
- xxpc = ruby_xml_xpath_context_new(anode);
141
- Data_Get_Struct(anode, ruby_xml_node, node);
142
- } else
143
- rb_raise(rb_eTypeError, "arg 1 must be XML::Document or XML::Node within a document %s", rb_obj_as_string(anode));
144
-
145
- if (NIL_P(xxpc))
146
- return(Qnil);
147
-
148
- Data_Get_Struct(xxpc,xmlXPathContext,ctxt);
149
- // XXX Is this legal? Set a subtree to apply xpath?
150
- ctxt->node = node->node;
151
-
152
- // XXX is setting ->namespaces used?
153
- if (node->node->type == XML_DOCUMENT_NODE) {
154
- ctxt->namespaces = xmlGetNsList(node->node->doc,
155
- xmlDocGetRootElement(node->node->doc));
156
- } else {
157
- ctxt->namespaces = xmlGetNsList(node->node->doc, node->node);
158
- }
159
-
160
- ctxt->nsNr = 0;
161
- if (ctxt->namespaces != NULL) {
162
- while (ctxt->namespaces[ctxt->nsNr] != NULL)
163
- ctxt->nsNr++;
164
- }
165
-
166
- if ( ! NIL_P(nslist) )
167
- ruby_xml_xpath_register_namespaces(nslist,xxpc,0);
168
-
169
- comp = xmlXPathCompile((xmlChar*)StringValuePtr(xpath_expr));
170
-
171
- if (comp == NULL) {
172
- rb_raise(eXMLXPathInvalidPath,
173
- "Invalid XPath expression (expr does not compile)");
174
- }
175
- xxpop=xmlXPathCompiledEval(comp, ctxt);
176
- if ( xxpop == NULL )
177
- return Qnil;
178
-
179
- #define ALT
180
- #ifdef ALT
181
- rxpop = ruby_xml_xpath_object_wrap(xxpop);
182
- #else
183
- rxpop = Data_Wrap_Struct(cXMLXPathObject,
184
- ruby_xml_xpath_object_mark,
185
- ruby_xml_xpath_object_free,
186
- xxpop);
187
- #endif
188
-
189
- #ifdef NODE_DEBUG
190
- fprintf(stderr,"xpo 0x%x class=%s\n",
191
- rxpop,
192
- rb_class2name(rb_obj_class(rxpop)));
193
- #endif
194
-
195
- xmlXPathFreeCompExpr(comp);
196
-
197
- if (rxpop == Qnil)
198
- rb_raise(eXMLXPathInvalidPath,
199
- "Invalid XPath expression for this document");
200
-
201
- return rxpop;
202
- #else
203
- rb_warn("libxml was compiled without XPath support");
204
- return(Qfalse);
205
- #endif
206
- }
207
-
208
-
209
- VALUE
210
- ruby_xml_xpath_findva(int argc, VALUE *argv, VALUE class) {
211
- if ( argc < 2 || argc > 3 )
212
- rb_raise(rb_eArgError, "wrong number of arguments (1 or 2)");
213
-
214
- return ruby_xml_xpath_find(class,argv[0],argv[1],(argc==3)?argv[2]:Qnil);
215
- }
216
-
217
- VALUE
218
- ruby_xml_xpath_find2(VALUE anode, VALUE xpath_expr, VALUE nslist) {
219
- return ruby_xml_xpath_find(cXMLXPath, anode, xpath_expr, nslist);
220
- }
221
-
222
- // Rdoc needs to know
223
- #ifdef RDOC_NEVER_DEFINED
224
- mXML = rb_define_module("XML");
225
- #endif
226
-
227
- void
228
- ruby_init_xml_xpath(void) {
229
- cXMLXPath = rb_define_class_under(mXML, "XPath", rb_cObject);
230
- rb_include_module(cXMLNode, rb_const_get(rb_cObject, rb_intern("Enumerable")));
231
-
232
- eXMLXPathInvalidPath = rb_define_class_under(cXMLXPath, "InvalidPath", eXMLError);
233
-
234
- rb_define_const(cXMLXPath, "UNDEFINED", INT2NUM(XPATH_UNDEFINED));
235
- rb_define_const(cXMLXPath, "NODESET", INT2NUM(XPATH_NODESET));
236
- rb_define_const(cXMLXPath, "BOOLEAN", INT2NUM(XPATH_BOOLEAN));
237
- rb_define_const(cXMLXPath, "NUMBER", INT2NUM(XPATH_NUMBER));
238
- rb_define_const(cXMLXPath, "STRING", INT2NUM(XPATH_STRING));
239
- rb_define_const(cXMLXPath, "POINT", INT2NUM(XPATH_POINT));
240
- rb_define_const(cXMLXPath, "RANGE", INT2NUM(XPATH_RANGE));
241
- rb_define_const(cXMLXPath, "LOCATIONSET", INT2NUM(XPATH_LOCATIONSET));
242
- rb_define_const(cXMLXPath, "USERS", INT2NUM(XPATH_USERS));
243
- rb_define_const(cXMLXPath, "XSLT_TREE", INT2NUM(XPATH_XSLT_TREE));
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 */
@@ -1,4 +1,4 @@
1
- /* $Id: ruby_xml_xpath.h 225 2007-12-07 04:58:09Z transami $ */
1
+ /* $Id: ruby_xml_xpath.h 207 2007-11-14 07:51:46Z danj $ */
2
2
 
3
3
  /* Please see the LICENSE file for copyright and distribution information */
4
4