coupa-libxml-ruby 1.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (280) hide show
  1. data/CHANGES +488 -0
  2. data/LICENSE +22 -0
  3. data/README +161 -0
  4. data/Rakefile +188 -0
  5. data/doc/css/normal.css +182 -0
  6. data/doc/img/raze-tiny.png +0 -0
  7. data/doc/img/red-cube.jpg +0 -0
  8. data/doc/img/xml-ruby.png +0 -0
  9. data/doc/index.xml +43 -0
  10. data/doc/install.xml +77 -0
  11. data/doc/layout.rhtml +38 -0
  12. data/doc/layout.xsl +67 -0
  13. data/doc/license.xml +32 -0
  14. data/doc/log/changelog.xml +1324 -0
  15. data/doc/log/changelog.xsl +42 -0
  16. data/doc/rdoc/classes/LibXML.html +207 -0
  17. data/doc/rdoc/classes/LibXML/XML.html +407 -0
  18. data/doc/rdoc/classes/LibXML/XML/Attr.html +521 -0
  19. data/doc/rdoc/classes/LibXML/XML/AttrDecl.html +360 -0
  20. data/doc/rdoc/classes/LibXML/XML/Attributes.html +149 -0
  21. data/doc/rdoc/classes/LibXML/XML/Document.html +460 -0
  22. data/doc/rdoc/classes/LibXML/XML/Error.html +129 -0
  23. data/doc/rdoc/classes/LibXML/XML/HTMLParser.html +263 -0
  24. data/doc/rdoc/classes/LibXML/XML/Namespace.html +248 -0
  25. data/doc/rdoc/classes/LibXML/XML/Namespaces.html +200 -0
  26. data/doc/rdoc/classes/LibXML/XML/Node.html +1351 -0
  27. data/doc/rdoc/classes/LibXML/XML/Parser.html +328 -0
  28. data/doc/rdoc/classes/LibXML/XML/Reader.html +172 -0
  29. data/doc/rdoc/classes/LibXML/XML/SaxParser.html +232 -0
  30. data/doc/rdoc/classes/LibXML/XML/SaxParser/Callbacks.html +506 -0
  31. data/doc/rdoc/classes/LibXML/XML/SaxParser/VerboseCallbacks.html +555 -0
  32. data/doc/rdoc/classes/LibXML/XML/XPath.html +111 -0
  33. data/doc/rdoc/classes/LibXML/XML/XPath/Object.html +162 -0
  34. data/doc/rdoc/classes/cXMLDtd.html +114 -0
  35. data/doc/rdoc/classes/cXMLNode.html +114 -0
  36. data/doc/rdoc/created.rid +1 -0
  37. data/doc/rdoc/files/CHANGES.html +794 -0
  38. data/doc/rdoc/files/LICENSE.html +131 -0
  39. data/doc/rdoc/files/README.html +343 -0
  40. data/doc/rdoc/files/ext/libxml/libxml_c.html +101 -0
  41. data/doc/rdoc/files/ext/libxml/ruby_xml_attr_c.html +101 -0
  42. data/doc/rdoc/files/ext/libxml/ruby_xml_attr_decl_c.html +101 -0
  43. data/doc/rdoc/files/ext/libxml/ruby_xml_attributes_c.html +101 -0
  44. data/doc/rdoc/files/ext/libxml/ruby_xml_c.html +101 -0
  45. data/doc/rdoc/files/ext/libxml/ruby_xml_cbg_c.html +101 -0
  46. data/doc/rdoc/files/ext/libxml/ruby_xml_document_c.html +101 -0
  47. data/doc/rdoc/files/ext/libxml/ruby_xml_dtd_c.html +101 -0
  48. data/doc/rdoc/files/ext/libxml/ruby_xml_encoding_c.html +101 -0
  49. data/doc/rdoc/files/ext/libxml/ruby_xml_error_c.html +101 -0
  50. data/doc/rdoc/files/ext/libxml/ruby_xml_html_parser_c.html +101 -0
  51. data/doc/rdoc/files/ext/libxml/ruby_xml_html_parser_context_c.html +101 -0
  52. data/doc/rdoc/files/ext/libxml/ruby_xml_html_parser_options_c.html +101 -0
  53. data/doc/rdoc/files/ext/libxml/ruby_xml_input_cbg_c.html +101 -0
  54. data/doc/rdoc/files/ext/libxml/ruby_xml_io_c.html +101 -0
  55. data/doc/rdoc/files/ext/libxml/ruby_xml_namespace_c.html +101 -0
  56. data/doc/rdoc/files/ext/libxml/ruby_xml_namespaces_c.html +101 -0
  57. data/doc/rdoc/files/ext/libxml/ruby_xml_node_c.html +101 -0
  58. data/doc/rdoc/files/ext/libxml/ruby_xml_parser_c.html +101 -0
  59. data/doc/rdoc/files/ext/libxml/ruby_xml_parser_context_c.html +101 -0
  60. data/doc/rdoc/files/ext/libxml/ruby_xml_parser_options_c.html +101 -0
  61. data/doc/rdoc/files/ext/libxml/ruby_xml_reader_c.html +101 -0
  62. data/doc/rdoc/files/ext/libxml/ruby_xml_relaxng_c.html +101 -0
  63. data/doc/rdoc/files/ext/libxml/ruby_xml_sax2_handler_c.html +101 -0
  64. data/doc/rdoc/files/ext/libxml/ruby_xml_sax_parser_c.html +101 -0
  65. data/doc/rdoc/files/ext/libxml/ruby_xml_schema_c.html +101 -0
  66. data/doc/rdoc/files/ext/libxml/ruby_xml_xinclude_c.html +101 -0
  67. data/doc/rdoc/files/ext/libxml/ruby_xml_xpath_c.html +101 -0
  68. data/doc/rdoc/files/ext/libxml/ruby_xml_xpath_context_c.html +101 -0
  69. data/doc/rdoc/files/ext/libxml/ruby_xml_xpath_expression_c.html +101 -0
  70. data/doc/rdoc/files/ext/libxml/ruby_xml_xpath_object_c.html +101 -0
  71. data/doc/rdoc/files/ext/libxml/ruby_xml_xpointer_c.html +101 -0
  72. data/doc/rdoc/files/lib/libxml/attr_decl_rb.html +101 -0
  73. data/doc/rdoc/files/lib/libxml/attr_rb.html +101 -0
  74. data/doc/rdoc/files/lib/libxml/attributes_rb.html +101 -0
  75. data/doc/rdoc/files/lib/libxml/document_rb.html +101 -0
  76. data/doc/rdoc/files/lib/libxml/error_rb.html +101 -0
  77. data/doc/rdoc/files/lib/libxml/hpricot_rb.html +192 -0
  78. data/doc/rdoc/files/lib/libxml/html_parser_rb.html +101 -0
  79. data/doc/rdoc/files/lib/libxml/namespace_rb.html +101 -0
  80. data/doc/rdoc/files/lib/libxml/namespaces_rb.html +101 -0
  81. data/doc/rdoc/files/lib/libxml/node_rb.html +108 -0
  82. data/doc/rdoc/files/lib/libxml/ns_rb.html +101 -0
  83. data/doc/rdoc/files/lib/libxml/parser_rb.html +101 -0
  84. data/doc/rdoc/files/lib/libxml/properties_rb.html +101 -0
  85. data/doc/rdoc/files/lib/libxml/reader_rb.html +101 -0
  86. data/doc/rdoc/files/lib/libxml/sax_callbacks_rb.html +101 -0
  87. data/doc/rdoc/files/lib/libxml/sax_parser_rb.html +101 -0
  88. data/doc/rdoc/files/lib/libxml/tree_rb.html +101 -0
  89. data/doc/rdoc/files/lib/libxml/xpath_object_rb.html +101 -0
  90. data/doc/rdoc/files/lib/libxml_rb.html +133 -0
  91. data/doc/rdoc/files/lib/xml/libxml_rb.html +124 -0
  92. data/doc/rdoc/files/lib/xml_rb.html +134 -0
  93. data/doc/rdoc/fr_class_index.html +46 -0
  94. data/doc/rdoc/fr_file_index.html +84 -0
  95. data/doc/rdoc/fr_method_index.html +155 -0
  96. data/doc/rdoc/index.html +24 -0
  97. data/doc/rdoc/rdoc-style.css +208 -0
  98. data/ext/libxml/Makefile +157 -0
  99. data/ext/libxml/build.log +4 -0
  100. data/ext/libxml/extconf.h +5 -0
  101. data/ext/libxml/extconf.rb +278 -0
  102. data/ext/libxml/libxml.c +77 -0
  103. data/ext/libxml/libxml.o +0 -0
  104. data/ext/libxml/libxml_ruby.bundle +0 -0
  105. data/ext/libxml/mkmf.log +228 -0
  106. data/ext/libxml/ruby_libxml.h +93 -0
  107. data/ext/libxml/ruby_xml.c +893 -0
  108. data/ext/libxml/ruby_xml.h +10 -0
  109. data/ext/libxml/ruby_xml.o +0 -0
  110. data/ext/libxml/ruby_xml_attr.c +352 -0
  111. data/ext/libxml/ruby_xml_attr.h +14 -0
  112. data/ext/libxml/ruby_xml_attr.o +0 -0
  113. data/ext/libxml/ruby_xml_attr_decl.c +171 -0
  114. data/ext/libxml/ruby_xml_attr_decl.h +13 -0
  115. data/ext/libxml/ruby_xml_attr_decl.o +0 -0
  116. data/ext/libxml/ruby_xml_attributes.c +277 -0
  117. data/ext/libxml/ruby_xml_attributes.h +17 -0
  118. data/ext/libxml/ruby_xml_attributes.o +0 -0
  119. data/ext/libxml/ruby_xml_cbg.c +86 -0
  120. data/ext/libxml/ruby_xml_cbg.o +0 -0
  121. data/ext/libxml/ruby_xml_document.c +1006 -0
  122. data/ext/libxml/ruby_xml_document.c.old +936 -0
  123. data/ext/libxml/ruby_xml_document.h +17 -0
  124. data/ext/libxml/ruby_xml_document.o +0 -0
  125. data/ext/libxml/ruby_xml_dtd.c +257 -0
  126. data/ext/libxml/ruby_xml_dtd.h +9 -0
  127. data/ext/libxml/ruby_xml_dtd.o +0 -0
  128. data/ext/libxml/ruby_xml_encoding.c +134 -0
  129. data/ext/libxml/ruby_xml_encoding.h +12 -0
  130. data/ext/libxml/ruby_xml_encoding.o +0 -0
  131. data/ext/libxml/ruby_xml_error.c +1004 -0
  132. data/ext/libxml/ruby_xml_error.h +14 -0
  133. data/ext/libxml/ruby_xml_error.o +0 -0
  134. data/ext/libxml/ruby_xml_html_parser.c +92 -0
  135. data/ext/libxml/ruby_xml_html_parser.h +12 -0
  136. data/ext/libxml/ruby_xml_html_parser.o +0 -0
  137. data/ext/libxml/ruby_xml_html_parser_context.c +308 -0
  138. data/ext/libxml/ruby_xml_html_parser_context.h +12 -0
  139. data/ext/libxml/ruby_xml_html_parser_context.o +0 -0
  140. data/ext/libxml/ruby_xml_html_parser_options.c +40 -0
  141. data/ext/libxml/ruby_xml_html_parser_options.h +12 -0
  142. data/ext/libxml/ruby_xml_html_parser_options.o +0 -0
  143. data/ext/libxml/ruby_xml_input_cbg.c +191 -0
  144. data/ext/libxml/ruby_xml_input_cbg.h +20 -0
  145. data/ext/libxml/ruby_xml_input_cbg.o +0 -0
  146. data/ext/libxml/ruby_xml_io.c +30 -0
  147. data/ext/libxml/ruby_xml_io.h +9 -0
  148. data/ext/libxml/ruby_xml_io.o +0 -0
  149. data/ext/libxml/ruby_xml_namespace.c +170 -0
  150. data/ext/libxml/ruby_xml_namespace.h +12 -0
  151. data/ext/libxml/ruby_xml_namespace.o +0 -0
  152. data/ext/libxml/ruby_xml_namespaces.c +295 -0
  153. data/ext/libxml/ruby_xml_namespaces.h +11 -0
  154. data/ext/libxml/ruby_xml_namespaces.o +0 -0
  155. data/ext/libxml/ruby_xml_node.c +1386 -0
  156. data/ext/libxml/ruby_xml_node.h +13 -0
  157. data/ext/libxml/ruby_xml_node.o +0 -0
  158. data/ext/libxml/ruby_xml_parser.c +94 -0
  159. data/ext/libxml/ruby_xml_parser.h +14 -0
  160. data/ext/libxml/ruby_xml_parser.o +0 -0
  161. data/ext/libxml/ruby_xml_parser_context.c +982 -0
  162. data/ext/libxml/ruby_xml_parser_context.h +12 -0
  163. data/ext/libxml/ruby_xml_parser_context.o +0 -0
  164. data/ext/libxml/ruby_xml_parser_options.c +68 -0
  165. data/ext/libxml/ruby_xml_parser_options.h +14 -0
  166. data/ext/libxml/ruby_xml_parser_options.o +0 -0
  167. data/ext/libxml/ruby_xml_reader.c +1002 -0
  168. data/ext/libxml/ruby_xml_reader.h +14 -0
  169. data/ext/libxml/ruby_xml_reader.o +0 -0
  170. data/ext/libxml/ruby_xml_relaxng.c +111 -0
  171. data/ext/libxml/ruby_xml_relaxng.h +10 -0
  172. data/ext/libxml/ruby_xml_relaxng.o +0 -0
  173. data/ext/libxml/ruby_xml_sax2_handler.c +322 -0
  174. data/ext/libxml/ruby_xml_sax2_handler.h +12 -0
  175. data/ext/libxml/ruby_xml_sax2_handler.o +0 -0
  176. data/ext/libxml/ruby_xml_sax_parser.c +137 -0
  177. data/ext/libxml/ruby_xml_sax_parser.h +12 -0
  178. data/ext/libxml/ruby_xml_sax_parser.o +0 -0
  179. data/ext/libxml/ruby_xml_schema.c +159 -0
  180. data/ext/libxml/ruby_xml_schema.h +11 -0
  181. data/ext/libxml/ruby_xml_schema.o +0 -0
  182. data/ext/libxml/ruby_xml_version.h +9 -0
  183. data/ext/libxml/ruby_xml_xinclude.c +18 -0
  184. data/ext/libxml/ruby_xml_xinclude.h +13 -0
  185. data/ext/libxml/ruby_xml_xinclude.o +0 -0
  186. data/ext/libxml/ruby_xml_xpath.c +107 -0
  187. data/ext/libxml/ruby_xml_xpath.h +12 -0
  188. data/ext/libxml/ruby_xml_xpath.o +0 -0
  189. data/ext/libxml/ruby_xml_xpath_context.c +387 -0
  190. data/ext/libxml/ruby_xml_xpath_context.h +11 -0
  191. data/ext/libxml/ruby_xml_xpath_context.o +0 -0
  192. data/ext/libxml/ruby_xml_xpath_expression.c +83 -0
  193. data/ext/libxml/ruby_xml_xpath_expression.h +12 -0
  194. data/ext/libxml/ruby_xml_xpath_expression.o +0 -0
  195. data/ext/libxml/ruby_xml_xpath_object.c +336 -0
  196. data/ext/libxml/ruby_xml_xpath_object.h +19 -0
  197. data/ext/libxml/ruby_xml_xpath_object.o +0 -0
  198. data/ext/libxml/ruby_xml_xpointer.c +101 -0
  199. data/ext/libxml/ruby_xml_xpointer.h +13 -0
  200. data/ext/libxml/ruby_xml_xpointer.o +0 -0
  201. data/ext/mingw/Rakefile +34 -0
  202. data/ext/mingw/build.rake +41 -0
  203. data/ext/vc/libxml_ruby.sln +26 -0
  204. data/lib/libxml.rb +30 -0
  205. data/lib/libxml/attr.rb +111 -0
  206. data/lib/libxml/attr_decl.rb +78 -0
  207. data/lib/libxml/attributes.rb +12 -0
  208. data/lib/libxml/document.rb +190 -0
  209. data/lib/libxml/error.rb +88 -0
  210. data/lib/libxml/hpricot.rb +76 -0
  211. data/lib/libxml/html_parser.rb +94 -0
  212. data/lib/libxml/namespace.rb +60 -0
  213. data/lib/libxml/namespaces.rb +36 -0
  214. data/lib/libxml/node.rb +385 -0
  215. data/lib/libxml/ns.rb +20 -0
  216. data/lib/libxml/parser.rb +365 -0
  217. data/lib/libxml/properties.rb +21 -0
  218. data/lib/libxml/reader.rb +27 -0
  219. data/lib/libxml/sax_callbacks.rb +178 -0
  220. data/lib/libxml/sax_parser.rb +56 -0
  221. data/lib/libxml/tree.rb +27 -0
  222. data/lib/libxml/xpath_object.rb +14 -0
  223. data/lib/xml.rb +14 -0
  224. data/lib/xml/libxml.rb +8 -0
  225. data/setup.rb +1585 -0
  226. data/test/etc_doc_to_s.rb +19 -0
  227. data/test/ets_doc_file.rb +15 -0
  228. data/test/ets_doc_to_s.rb +21 -0
  229. data/test/ets_gpx.rb +26 -0
  230. data/test/ets_node_gc.rb +21 -0
  231. data/test/ets_test.xml +2 -0
  232. data/test/ets_tsr.rb +9 -0
  233. data/test/model/atom.xml +13 -0
  234. data/test/model/bands.xml +5 -0
  235. data/test/model/books.xml +146 -0
  236. data/test/model/merge_bug_data.xml +58 -0
  237. data/test/model/ruby-lang.html +238 -0
  238. data/test/model/rubynet.xml +79 -0
  239. data/test/model/rubynet_project +1 -0
  240. data/test/model/shiporder.rnc +28 -0
  241. data/test/model/shiporder.rng +86 -0
  242. data/test/model/shiporder.xml +23 -0
  243. data/test/model/shiporder.xsd +31 -0
  244. data/test/model/soap.xml +27 -0
  245. data/test/model/xinclude.xml +5 -0
  246. data/test/tc_attr.rb +170 -0
  247. data/test/tc_attr_decl.rb +131 -0
  248. data/test/tc_attributes.rb +133 -0
  249. data/test/tc_deprecated_require.rb +11 -0
  250. data/test/tc_document.rb +113 -0
  251. data/test/tc_document_write.rb +118 -0
  252. data/test/tc_dtd.rb +123 -0
  253. data/test/tc_error.rb +136 -0
  254. data/test/tc_html_parser.rb +138 -0
  255. data/test/tc_namespace.rb +59 -0
  256. data/test/tc_namespaces.rb +174 -0
  257. data/test/tc_node.rb +181 -0
  258. data/test/tc_node_cdata.rb +49 -0
  259. data/test/tc_node_comment.rb +30 -0
  260. data/test/tc_node_copy.rb +40 -0
  261. data/test/tc_node_edit.rb +158 -0
  262. data/test/tc_node_text.rb +69 -0
  263. data/test/tc_node_write.rb +83 -0
  264. data/test/tc_node_xlink.rb +26 -0
  265. data/test/tc_parser.rb +330 -0
  266. data/test/tc_parser_context.rb +186 -0
  267. data/test/tc_properties.rb +36 -0
  268. data/test/tc_reader.rb +284 -0
  269. data/test/tc_relaxng.rb +51 -0
  270. data/test/tc_sax_parser.rb +274 -0
  271. data/test/tc_schema.rb +51 -0
  272. data/test/tc_traversal.rb +220 -0
  273. data/test/tc_xinclude.rb +19 -0
  274. data/test/tc_xml.rb +224 -0
  275. data/test/tc_xpath.rb +193 -0
  276. data/test/tc_xpath_context.rb +78 -0
  277. data/test/tc_xpath_expression.rb +35 -0
  278. data/test/tc_xpointer.rb +72 -0
  279. data/test/test_suite.rb +33 -0
  280. metadata +376 -0
@@ -0,0 +1,12 @@
1
+ /* $Id$ */
2
+
3
+ /* Please see the LICENSE file for copyright and distribution information */
4
+
5
+ #ifndef __RXML_XPATH_EXPRESSION__
6
+ #define __RXML_XPATH_EXPRESSION__
7
+
8
+ extern VALUE cXMLXPathExpression;
9
+
10
+ void rxml_init_xpath_expression(void);
11
+
12
+ #endif
@@ -0,0 +1,336 @@
1
+ /* $Id: $ */
2
+
3
+ #include "ruby_libxml.h"
4
+
5
+ /*
6
+ * Document-class: LibXML::XML::XPath::Object
7
+ *
8
+ * A collection of nodes returned from the evaluation of an XML::XPath
9
+ * or XML::XPointer expression.
10
+ */
11
+
12
+ VALUE cXMLXPathObject;
13
+
14
+
15
+ /* Memory management of xpath results is tricky. If a nodeset is
16
+ returned, it generally consists of pointers to nodes in the
17
+ original document. However, namespace nodes are handled differently -
18
+ libxml creates copies of them instead. Thus, when an xmlXPathObjectPtr
19
+ is freed, libxml iterates over the results to find the copied namespace
20
+ nodes to free them.
21
+
22
+ This causes problems for the bindings because the underlying document
23
+ may be freed before the xmlXPathObjectPtr instance. This might seem
24
+ counterintuitive since the xmlXPathObjectPtr marks the document.
25
+ However, once both objects go out of scope, the order of their
26
+ destruction is random.
27
+
28
+ To deal with this, the wrapper code searches for the namespace nodes
29
+ and wraps them in Ruby objects. When the Ruby objects go out of scope
30
+ then the namespace nodes are freed. */
31
+
32
+ static void rxml_xpath_object_free(rxml_xpath_object *rxpop)
33
+ {
34
+ /* We positively, absolutely cannot let libxml iterate over
35
+ the nodeTab since if the underlying document has been
36
+ freed the majority of entries are invalid, resulting in
37
+ segmentation faults.*/
38
+ if (rxpop->xpop->nodesetval && rxpop->xpop->nodesetval->nodeTab)
39
+ {
40
+ xmlFree(rxpop->xpop->nodesetval->nodeTab);
41
+ rxpop->xpop->nodesetval->nodeTab = NULL;
42
+ }
43
+ xmlXPathFreeObject(rxpop->xpop);
44
+ xfree(rxpop);
45
+ }
46
+
47
+ /* Custom free function for copied namespace nodes */
48
+ static void rxml_namespace_xpath_free(xmlNsPtr xns)
49
+ {
50
+ xns->_private = NULL;
51
+ xmlFreeNs(xns);
52
+ }
53
+
54
+ static void rxml_xpath_object_mark(rxml_xpath_object *rxpop)
55
+ {
56
+ rb_gc_mark(rxpop->nsnodes);
57
+ if (rxpop->xdoc->_private)
58
+ rb_gc_mark((VALUE)rxpop->xdoc->_private);
59
+ }
60
+
61
+ VALUE rxml_xpath_object_wrap(xmlDocPtr xdoc, xmlXPathObjectPtr xpop)
62
+ {
63
+ int i;
64
+ rxml_xpath_object *rxpop = ALLOC(rxml_xpath_object);
65
+ rxpop->xdoc =xdoc;
66
+ rxpop->xpop = xpop;
67
+ rxpop->nsnodes = rb_ary_new();
68
+
69
+ /* Find all the extra namespace nodes and wrap them. */
70
+ if (xpop->nodesetval && xpop->nodesetval->nodeNr)
71
+ {
72
+ for (i = 0;i < xpop->nodesetval->nodeNr; i++)
73
+ {
74
+ xmlNodePtr xnode = xpop->nodesetval->nodeTab[i];
75
+ if (xnode!= NULL && xnode->type == XML_NAMESPACE_DECL)
76
+ {
77
+ VALUE ns = Qnil;
78
+ xmlNsPtr xns = (xmlNsPtr)xnode;
79
+
80
+ /* Get rid of libxml's -> next hack. The issue here is
81
+ the rxml_namespace code assumes that ns->next refers
82
+ to another namespace. */
83
+ xns->next = NULL;
84
+
85
+ /* Specify a custom free function here since by default
86
+ namespace nodes will not be freed */
87
+ ns = rxml_namespace_wrap((xmlNsPtr)xnode, (RUBY_DATA_FUNC)rxml_namespace_xpath_free);
88
+ rb_ary_push(rxpop->nsnodes, ns);
89
+ }
90
+ }
91
+ }
92
+
93
+ return Data_Wrap_Struct(cXMLXPathObject, rxml_xpath_object_mark, rxml_xpath_object_free, rxpop);
94
+ }
95
+
96
+ static VALUE rxml_xpath_object_tabref(xmlXPathObjectPtr xpop, int apos)
97
+ {
98
+
99
+ if (apos < 0)
100
+ apos = xpop->nodesetval->nodeNr + apos;
101
+
102
+ if (apos < 0 || apos + 1 > xpop->nodesetval->nodeNr)
103
+ return Qnil;
104
+
105
+ switch (xpop->nodesetval->nodeTab[apos]->type)
106
+ {
107
+ case XML_ATTRIBUTE_NODE:
108
+ return rxml_attr_wrap((xmlAttrPtr) xpop->nodesetval->nodeTab[apos]);
109
+ break;
110
+ case XML_NAMESPACE_DECL:
111
+ return rxml_namespace_wrap((xmlNsPtr)xpop->nodesetval->nodeTab[apos], NULL);
112
+ break;
113
+ default:
114
+ return rxml_node_wrap(xpop->nodesetval->nodeTab[apos]);
115
+ }
116
+ }
117
+
118
+ /*
119
+ * call-seq:
120
+ * xpath_object.to_a -> [node, ..., node]
121
+ *
122
+ * Obtain an array of the nodes in this set.
123
+ */
124
+ static VALUE rxml_xpath_object_to_a(VALUE self)
125
+ {
126
+ VALUE set_ary, nodeobj;
127
+ rxml_xpath_object *rxpop;
128
+ xmlXPathObjectPtr xpop;
129
+ int i;
130
+
131
+ Data_Get_Struct(self, rxml_xpath_object, rxpop);
132
+ xpop = rxpop->xpop;
133
+
134
+ set_ary = rb_ary_new();
135
+
136
+ if (!((xpop->nodesetval == NULL) || (xpop->nodesetval->nodeNr == 0)))
137
+ {
138
+ for (i = 0; i < xpop->nodesetval->nodeNr; i++)
139
+ {
140
+ nodeobj = rxml_xpath_object_tabref(xpop, i);
141
+ rb_ary_push(set_ary, nodeobj);
142
+ }
143
+ }
144
+
145
+ return (set_ary);
146
+ }
147
+
148
+ /*
149
+ * call-seq:
150
+ * xpath_object.empty? -> (true|false)
151
+ *
152
+ * Determine whether this nodeset is empty (contains no nodes).
153
+ */
154
+ static VALUE rxml_xpath_object_empty_q(VALUE self)
155
+ {
156
+ rxml_xpath_object *rxpop;
157
+ Data_Get_Struct(self, rxml_xpath_object, rxpop);
158
+
159
+ if (rxpop->xpop->type != XPATH_NODESET)
160
+ return Qnil;
161
+
162
+ return (rxpop->xpop->nodesetval == NULL || rxpop->xpop->nodesetval->nodeNr <= 0) ? Qtrue
163
+ : Qfalse;
164
+ }
165
+
166
+ /*
167
+ * call-seq:
168
+ * xpath_object.each { |node| ... } -> self
169
+ *
170
+ * Call the supplied block for each node in this set.
171
+ */
172
+ static VALUE rxml_xpath_object_each(VALUE self)
173
+ {
174
+ rxml_xpath_object *rxpop;
175
+ int i;
176
+
177
+ if (rxml_xpath_object_empty_q(self) == Qtrue)
178
+ return Qnil;
179
+
180
+ Data_Get_Struct(self, rxml_xpath_object, rxpop);
181
+
182
+ for (i = 0; i < rxpop->xpop->nodesetval->nodeNr; i++)
183
+ {
184
+ rb_yield(rxml_xpath_object_tabref(rxpop->xpop, i));
185
+ }
186
+ return (self);
187
+ }
188
+
189
+ /*
190
+ * call-seq:
191
+ * xpath_object.first -> node
192
+ *
193
+ * Returns the first node in this node set, or nil if none exist.
194
+ */
195
+ static VALUE rxml_xpath_object_first(VALUE self)
196
+ {
197
+ rxml_xpath_object *rxpop;
198
+
199
+ if (rxml_xpath_object_empty_q(self) == Qtrue)
200
+ return Qnil;
201
+
202
+ Data_Get_Struct(self, rxml_xpath_object, rxpop);
203
+ return rxml_xpath_object_tabref(rxpop->xpop, 0);
204
+ }
205
+
206
+ /*
207
+ * call-seq:
208
+ * xpath_object.last -> node
209
+ *
210
+ * Returns the last node in this node set, or nil if none exist.
211
+ */
212
+ static VALUE rxml_xpath_object_last(VALUE self)
213
+ {
214
+ rxml_xpath_object *rxpop;
215
+
216
+ if (rxml_xpath_object_empty_q(self) == Qtrue)
217
+ return Qnil;
218
+
219
+ Data_Get_Struct(self, rxml_xpath_object, rxpop);
220
+ return rxml_xpath_object_tabref(rxpop->xpop, -1);
221
+ }
222
+
223
+ /*
224
+ * call-seq:
225
+ * xpath_object[i] -> node
226
+ *
227
+ * array index into set of nodes
228
+ */
229
+ static VALUE rxml_xpath_object_aref(VALUE self, VALUE aref)
230
+ {
231
+ rxml_xpath_object *rxpop;
232
+
233
+ if (rxml_xpath_object_empty_q(self) == Qtrue)
234
+ return Qnil;
235
+
236
+ Data_Get_Struct(self, rxml_xpath_object, rxpop);
237
+ return rxml_xpath_object_tabref(rxpop->xpop, NUM2INT(aref));
238
+ }
239
+
240
+ /*
241
+ * call-seq:
242
+ * xpath_object.length -> num
243
+ *
244
+ * Obtain the length of the nodesetval node list.
245
+ */
246
+ static VALUE rxml_xpath_object_length(VALUE self)
247
+ {
248
+ rxml_xpath_object *rxpop;
249
+
250
+ if (rxml_xpath_object_empty_q(self) == Qtrue)
251
+ return INT2FIX(0);
252
+
253
+ Data_Get_Struct(self, rxml_xpath_object, rxpop);
254
+ return INT2NUM(rxpop->xpop->nodesetval->nodeNr);
255
+ }
256
+
257
+ /*
258
+ * call-seq:
259
+ * xpath_object.xpath_type -> int
260
+ *
261
+ * Returns the XPath type of the result object.
262
+ * Possible values are defined as constants
263
+ * on the XML::XPath class and include:
264
+ *
265
+ * * XML::XPath::UNDEFINED
266
+ * * XML::XPath::NODESET
267
+ * * XML::XPath::BOOLEAN
268
+ * * XML::XPath::NUMBER
269
+ * * XML::XPath::STRING
270
+ * * XML::XPath::POINT
271
+ * * XML::XPath::RANGE
272
+ * * XML::XPath::LOCATIONSET
273
+ * * XML::XPath::USERS
274
+ * * XML::XPath::XSLT_TREE
275
+ */
276
+ static VALUE rxml_xpath_object_get_type(VALUE self)
277
+ {
278
+ rxml_xpath_object *rxpop;
279
+ Data_Get_Struct(self, rxml_xpath_object, rxpop);
280
+ return INT2FIX(rxpop->xpop->type);
281
+ }
282
+
283
+ /*
284
+ * call-seq:
285
+ * xpath_object.string -> String
286
+ *
287
+ * Returns the original XPath expression as a string.
288
+ */
289
+ static VALUE rxml_xpath_object_string(VALUE self)
290
+ {
291
+ rxml_xpath_object *rxpop;
292
+
293
+ Data_Get_Struct(self, rxml_xpath_object, rxpop);
294
+
295
+ if (rxpop->xpop->stringval == NULL)
296
+ return Qnil;
297
+
298
+ return rb_str_new2((const char*) rxpop->xpop->stringval);
299
+ }
300
+
301
+ /*
302
+ * call-seq:
303
+ * nodes.debug -> (true|false)
304
+ *
305
+ * Dump libxml debugging information to stdout.
306
+ * Requires Libxml be compiled with debugging enabled.
307
+ */
308
+ static VALUE rxml_xpath_object_debug(VALUE self)
309
+ {
310
+ #ifdef LIBXML_DEBUG_ENABLED
311
+ rxml_xpath_object *rxpop;
312
+ Data_Get_Struct(self, rxml_xpath_object, rxpop);
313
+ xmlXPathDebugDumpObject(stdout, rxpop->xpop, 0);
314
+ return Qtrue;
315
+ #else
316
+ rb_warn("libxml was compiled without debugging support.")
317
+ return Qfalse;
318
+ #endif
319
+ }
320
+
321
+ void rxml_init_xpath_object(void)
322
+ {
323
+ cXMLXPathObject = rb_define_class_under(mXPath, "Object", rb_cObject);
324
+ rb_include_module(cXMLXPathObject, rb_mEnumerable);
325
+ rb_define_attr(cXMLXPathObject, "context", 1, 0);
326
+ rb_define_method(cXMLXPathObject, "each", rxml_xpath_object_each, 0);
327
+ rb_define_method(cXMLXPathObject, "xpath_type", rxml_xpath_object_get_type, 0);
328
+ rb_define_method(cXMLXPathObject, "empty?", rxml_xpath_object_empty_q, 0);
329
+ rb_define_method(cXMLXPathObject, "first", rxml_xpath_object_first, 0);
330
+ rb_define_method(cXMLXPathObject, "last", rxml_xpath_object_last, 0);
331
+ rb_define_method(cXMLXPathObject, "length", rxml_xpath_object_length, 0);
332
+ rb_define_method(cXMLXPathObject, "to_a", rxml_xpath_object_to_a, 0);
333
+ rb_define_method(cXMLXPathObject, "[]", rxml_xpath_object_aref, 1);
334
+ rb_define_method(cXMLXPathObject, "string", rxml_xpath_object_string, 0);
335
+ rb_define_method(cXMLXPathObject, "debug", rxml_xpath_object_debug, 0);
336
+ }
@@ -0,0 +1,19 @@
1
+ /* $Id $ */
2
+
3
+ #ifndef __RXML_XPATH_OBJECT__
4
+ #define __RXML_XPATH_OBJECT__
5
+
6
+ extern VALUE cXMLXPathObject;
7
+
8
+ typedef struct rxml_xpath_object
9
+ {
10
+ xmlDocPtr xdoc;
11
+ xmlXPathObjectPtr xpop;
12
+ VALUE nsnodes;
13
+ } rxml_xpath_object;
14
+
15
+
16
+ void rxml_init_xpath_object(void);
17
+ VALUE rxml_xpath_object_wrap(xmlDocPtr xdoc, xmlXPathObjectPtr xpop);
18
+
19
+ #endif
@@ -0,0 +1,101 @@
1
+ /* $Id: ruby_xml_xpointer.c 758 2009-01-25 20:36:03Z cfis $ */
2
+
3
+ /* Please see the LICENSE file for copyright and distribution information */
4
+
5
+ #include "ruby_libxml.h"
6
+ #include "ruby_xml_xpointer.h"
7
+
8
+ VALUE cXMLXPointer;
9
+
10
+ /*
11
+ * Document-class: LibXML::XML::XPointer
12
+ *
13
+ * The XML::Pointer class provides a standards based API for searching an xml document.
14
+ * XPointer is based on the XML Path Language (XML::XPath) and is documented
15
+ * at http://www.w3.org/TR/WD-xptr.
16
+ */
17
+
18
+ static VALUE rxml_xpointer_point(VALUE class, VALUE rnode, VALUE xptr_str)
19
+ {
20
+ #ifdef LIBXML_XPTR_ENABLED
21
+ xmlNodePtr xnode;
22
+ xmlXPathContextPtr xctxt;
23
+ xmlXPathObjectPtr xpop;
24
+
25
+ VALUE context;
26
+ VALUE result;
27
+ VALUE argv[1];
28
+
29
+ Check_Type(xptr_str, T_STRING);
30
+ if (rb_obj_is_kind_of(rnode, cXMLNode) == Qfalse)
31
+ rb_raise(rb_eTypeError, "require an XML::Node object");
32
+
33
+ Data_Get_Struct(rnode, xmlNode, xnode);
34
+
35
+ argv[0] = rb_funcall(rnode, rb_intern("doc"), 0);
36
+ context = rb_class_new_instance(1, argv, cXMLXPathContext);
37
+ Data_Get_Struct(context, xmlXPathContext, xctxt);
38
+
39
+ xpop = xmlXPtrEval((xmlChar*)StringValuePtr(xptr_str), xctxt);
40
+ if (!xpop)
41
+ rxml_raise(&xmlLastError);
42
+
43
+ result = rxml_xpath_object_wrap(xnode->doc, xpop);
44
+ rb_iv_set(result, "@context", context);
45
+
46
+ return(result);
47
+ #else
48
+ rb_warn("libxml was compiled without XPointer support");
49
+ return (Qfalse);
50
+ #endif
51
+ }
52
+
53
+ VALUE rxml_xpointer_point2(VALUE node, VALUE xptr_str)
54
+ {
55
+ return (rxml_xpointer_point(cXMLXPointer, node, xptr_str));
56
+ }
57
+
58
+ /*
59
+ * call-seq:
60
+ * XML::XPointer.range(start_node, end_node) -> xpath
61
+ *
62
+ * Create an xpath representing the range between the supplied
63
+ * start and end node.
64
+ */
65
+ static VALUE rxml_xpointer_range(VALUE class, VALUE rstart, VALUE rend)
66
+ {
67
+ #ifdef LIBXML_XPTR_ENABLED
68
+ xmlNodePtr start, end;
69
+ VALUE rxxp;
70
+ xmlXPathObjectPtr xpath;
71
+
72
+ if (rb_obj_is_kind_of(rstart, cXMLNode) == Qfalse)
73
+ rb_raise(rb_eTypeError, "require an XML::Node object as a starting point");
74
+ if (rb_obj_is_kind_of(rend, cXMLNode) == Qfalse)
75
+ rb_raise(rb_eTypeError, "require an XML::Node object as an ending point");
76
+
77
+ Data_Get_Struct(rstart, xmlNode, start);
78
+ if (start == NULL)
79
+ return(Qnil);
80
+
81
+ Data_Get_Struct(rend, xmlNode, end);
82
+ if (end == NULL)
83
+ return(Qnil);
84
+
85
+ xpath = xmlXPtrNewRangeNodes(start, end);
86
+ if (xpath == NULL)
87
+ rb_fatal("You shouldn't be able to have this happen");
88
+
89
+ rxxp = rxml_xpath_object_wrap(start->doc, xpath);
90
+ return(rxxp);
91
+ #else
92
+ rb_warn("libxml was compiled without XPointer support");
93
+ return (Qfalse);
94
+ #endif
95
+ }
96
+
97
+ void rxml_init_xpointer(void)
98
+ {
99
+ cXMLXPointer = rb_define_class_under(mXML, "XPointer", rb_cObject);
100
+ rb_define_singleton_method(cXMLXPointer, "range", rxml_xpointer_range, 2);
101
+ }