libxml-ruby 3.2.2-x64-mingw-ucrt

Sign up to get free protection for your applications and to get access to all the features.
Files changed (205) hide show
  1. checksums.yaml +7 -0
  2. data/HISTORY +848 -0
  3. data/LICENSE +21 -0
  4. data/MANIFEST +166 -0
  5. data/README.rdoc +217 -0
  6. data/Rakefile +99 -0
  7. data/ext/libxml/extconf.rb +61 -0
  8. data/ext/libxml/libxml.c +80 -0
  9. data/ext/libxml/libxml_ruby.def +35 -0
  10. data/ext/libxml/ruby_libxml.h +67 -0
  11. data/ext/libxml/ruby_xml.c +933 -0
  12. data/ext/libxml/ruby_xml.h +10 -0
  13. data/ext/libxml/ruby_xml_attr.c +333 -0
  14. data/ext/libxml/ruby_xml_attr.h +12 -0
  15. data/ext/libxml/ruby_xml_attr_decl.c +153 -0
  16. data/ext/libxml/ruby_xml_attr_decl.h +11 -0
  17. data/ext/libxml/ruby_xml_attributes.c +275 -0
  18. data/ext/libxml/ruby_xml_attributes.h +15 -0
  19. data/ext/libxml/ruby_xml_cbg.c +85 -0
  20. data/ext/libxml/ruby_xml_document.c +1123 -0
  21. data/ext/libxml/ruby_xml_document.h +11 -0
  22. data/ext/libxml/ruby_xml_dtd.c +248 -0
  23. data/ext/libxml/ruby_xml_dtd.h +9 -0
  24. data/ext/libxml/ruby_xml_encoding.c +250 -0
  25. data/ext/libxml/ruby_xml_encoding.h +16 -0
  26. data/ext/libxml/ruby_xml_error.c +996 -0
  27. data/ext/libxml/ruby_xml_error.h +12 -0
  28. data/ext/libxml/ruby_xml_html_parser.c +89 -0
  29. data/ext/libxml/ruby_xml_html_parser.h +10 -0
  30. data/ext/libxml/ruby_xml_html_parser_context.c +337 -0
  31. data/ext/libxml/ruby_xml_html_parser_context.h +10 -0
  32. data/ext/libxml/ruby_xml_html_parser_options.c +46 -0
  33. data/ext/libxml/ruby_xml_html_parser_options.h +10 -0
  34. data/ext/libxml/ruby_xml_input_cbg.c +191 -0
  35. data/ext/libxml/ruby_xml_input_cbg.h +20 -0
  36. data/ext/libxml/ruby_xml_io.c +47 -0
  37. data/ext/libxml/ruby_xml_io.h +10 -0
  38. data/ext/libxml/ruby_xml_namespace.c +153 -0
  39. data/ext/libxml/ruby_xml_namespace.h +10 -0
  40. data/ext/libxml/ruby_xml_namespaces.c +293 -0
  41. data/ext/libxml/ruby_xml_namespaces.h +9 -0
  42. data/ext/libxml/ruby_xml_node.c +1402 -0
  43. data/ext/libxml/ruby_xml_node.h +13 -0
  44. data/ext/libxml/ruby_xml_parser.c +91 -0
  45. data/ext/libxml/ruby_xml_parser.h +12 -0
  46. data/ext/libxml/ruby_xml_parser_context.c +999 -0
  47. data/ext/libxml/ruby_xml_parser_context.h +10 -0
  48. data/ext/libxml/ruby_xml_parser_options.c +66 -0
  49. data/ext/libxml/ruby_xml_parser_options.h +12 -0
  50. data/ext/libxml/ruby_xml_reader.c +1239 -0
  51. data/ext/libxml/ruby_xml_reader.h +17 -0
  52. data/ext/libxml/ruby_xml_relaxng.c +110 -0
  53. data/ext/libxml/ruby_xml_relaxng.h +10 -0
  54. data/ext/libxml/ruby_xml_sax2_handler.c +326 -0
  55. data/ext/libxml/ruby_xml_sax2_handler.h +10 -0
  56. data/ext/libxml/ruby_xml_sax_parser.c +116 -0
  57. data/ext/libxml/ruby_xml_sax_parser.h +10 -0
  58. data/ext/libxml/ruby_xml_schema.c +278 -0
  59. data/ext/libxml/ruby_xml_schema.h +809 -0
  60. data/ext/libxml/ruby_xml_schema_attribute.c +109 -0
  61. data/ext/libxml/ruby_xml_schema_attribute.h +15 -0
  62. data/ext/libxml/ruby_xml_schema_element.c +95 -0
  63. data/ext/libxml/ruby_xml_schema_element.h +14 -0
  64. data/ext/libxml/ruby_xml_schema_facet.c +52 -0
  65. data/ext/libxml/ruby_xml_schema_facet.h +13 -0
  66. data/ext/libxml/ruby_xml_schema_type.c +232 -0
  67. data/ext/libxml/ruby_xml_schema_type.h +9 -0
  68. data/ext/libxml/ruby_xml_version.h +9 -0
  69. data/ext/libxml/ruby_xml_writer.c +1133 -0
  70. data/ext/libxml/ruby_xml_writer.h +10 -0
  71. data/ext/libxml/ruby_xml_xinclude.c +16 -0
  72. data/ext/libxml/ruby_xml_xinclude.h +11 -0
  73. data/ext/libxml/ruby_xml_xpath.c +194 -0
  74. data/ext/libxml/ruby_xml_xpath.h +13 -0
  75. data/ext/libxml/ruby_xml_xpath_context.c +360 -0
  76. data/ext/libxml/ruby_xml_xpath_context.h +9 -0
  77. data/ext/libxml/ruby_xml_xpath_expression.c +81 -0
  78. data/ext/libxml/ruby_xml_xpath_expression.h +10 -0
  79. data/ext/libxml/ruby_xml_xpath_object.c +338 -0
  80. data/ext/libxml/ruby_xml_xpath_object.h +17 -0
  81. data/ext/libxml/ruby_xml_xpointer.c +99 -0
  82. data/ext/libxml/ruby_xml_xpointer.h +11 -0
  83. data/ext/vc/libxml_ruby.sln +28 -0
  84. data/lib/3.1/libxml_ruby.so +0 -0
  85. data/lib/libxml/attr.rb +123 -0
  86. data/lib/libxml/attr_decl.rb +80 -0
  87. data/lib/libxml/attributes.rb +14 -0
  88. data/lib/libxml/document.rb +194 -0
  89. data/lib/libxml/error.rb +95 -0
  90. data/lib/libxml/hpricot.rb +78 -0
  91. data/lib/libxml/html_parser.rb +96 -0
  92. data/lib/libxml/namespace.rb +62 -0
  93. data/lib/libxml/namespaces.rb +38 -0
  94. data/lib/libxml/node.rb +323 -0
  95. data/lib/libxml/parser.rb +101 -0
  96. data/lib/libxml/sax_callbacks.rb +180 -0
  97. data/lib/libxml/sax_parser.rb +41 -0
  98. data/lib/libxml/schema/attribute.rb +19 -0
  99. data/lib/libxml/schema/element.rb +19 -0
  100. data/lib/libxml/schema/type.rb +21 -0
  101. data/lib/libxml/schema.rb +48 -0
  102. data/lib/libxml/tree.rb +29 -0
  103. data/lib/libxml-ruby.rb +30 -0
  104. data/lib/libxml.rb +5 -0
  105. data/lib/xml/libxml.rb +10 -0
  106. data/lib/xml.rb +14 -0
  107. data/libxml-ruby.gemspec +48 -0
  108. data/script/benchmark/depixelate +634 -0
  109. data/script/benchmark/hamlet.xml +9055 -0
  110. data/script/benchmark/parsecount +170 -0
  111. data/script/benchmark/sock_entries.xml +507 -0
  112. data/script/benchmark/throughput +41 -0
  113. data/script/test +6 -0
  114. data/setup.rb +1584 -0
  115. data/test/c14n/given/doc.dtd +1 -0
  116. data/test/c14n/given/example-1.xml +14 -0
  117. data/test/c14n/given/example-2.xml +11 -0
  118. data/test/c14n/given/example-3.xml +18 -0
  119. data/test/c14n/given/example-4.xml +9 -0
  120. data/test/c14n/given/example-5.xml +12 -0
  121. data/test/c14n/given/example-6.xml +2 -0
  122. data/test/c14n/given/example-7.xml +11 -0
  123. data/test/c14n/given/example-8.xml +11 -0
  124. data/test/c14n/given/example-8.xpath +10 -0
  125. data/test/c14n/given/world.txt +1 -0
  126. data/test/c14n/result/1-1-without-comments/example-1 +4 -0
  127. data/test/c14n/result/1-1-without-comments/example-2 +11 -0
  128. data/test/c14n/result/1-1-without-comments/example-3 +14 -0
  129. data/test/c14n/result/1-1-without-comments/example-4 +9 -0
  130. data/test/c14n/result/1-1-without-comments/example-5 +3 -0
  131. data/test/c14n/result/1-1-without-comments/example-6 +1 -0
  132. data/test/c14n/result/1-1-without-comments/example-7 +1 -0
  133. data/test/c14n/result/1-1-without-comments/example-8 +1 -0
  134. data/test/c14n/result/with-comments/example-1 +6 -0
  135. data/test/c14n/result/with-comments/example-2 +11 -0
  136. data/test/c14n/result/with-comments/example-3 +14 -0
  137. data/test/c14n/result/with-comments/example-4 +9 -0
  138. data/test/c14n/result/with-comments/example-5 +4 -0
  139. data/test/c14n/result/with-comments/example-6 +1 -0
  140. data/test/c14n/result/with-comments/example-7 +1 -0
  141. data/test/c14n/result/without-comments/example-1 +4 -0
  142. data/test/c14n/result/without-comments/example-2 +11 -0
  143. data/test/c14n/result/without-comments/example-3 +14 -0
  144. data/test/c14n/result/without-comments/example-4 +9 -0
  145. data/test/c14n/result/without-comments/example-5 +3 -0
  146. data/test/c14n/result/without-comments/example-6 +1 -0
  147. data/test/c14n/result/without-comments/example-7 +1 -0
  148. data/test/model/atom.xml +13 -0
  149. data/test/model/bands.iso-8859-1.xml +5 -0
  150. data/test/model/bands.utf-8.xml +5 -0
  151. data/test/model/bands.xml +5 -0
  152. data/test/model/books.xml +154 -0
  153. data/test/model/cwm_1_0.xml +11336 -0
  154. data/test/model/merge_bug_data.xml +58 -0
  155. data/test/model/ruby-lang.html +238 -0
  156. data/test/model/rubynet.xml +79 -0
  157. data/test/model/rubynet_project +1 -0
  158. data/test/model/shiporder.rnc +28 -0
  159. data/test/model/shiporder.rng +86 -0
  160. data/test/model/shiporder.xml +23 -0
  161. data/test/model/shiporder.xsd +40 -0
  162. data/test/model/soap.xml +27 -0
  163. data/test/model/xinclude.xml +5 -0
  164. data/test/test_attr.rb +181 -0
  165. data/test/test_attr_decl.rb +132 -0
  166. data/test/test_attributes.rb +136 -0
  167. data/test/test_canonicalize.rb +120 -0
  168. data/test/test_deprecated_require.rb +12 -0
  169. data/test/test_document.rb +132 -0
  170. data/test/test_document_write.rb +146 -0
  171. data/test/test_dtd.rb +129 -0
  172. data/test/test_encoding.rb +129 -0
  173. data/test/test_encoding_sax.rb +115 -0
  174. data/test/test_error.rb +178 -0
  175. data/test/test_helper.rb +9 -0
  176. data/test/test_html_parser.rb +162 -0
  177. data/test/test_html_parser_context.rb +23 -0
  178. data/test/test_namespace.rb +60 -0
  179. data/test/test_namespaces.rb +200 -0
  180. data/test/test_node.rb +237 -0
  181. data/test/test_node_cdata.rb +50 -0
  182. data/test/test_node_comment.rb +32 -0
  183. data/test/test_node_copy.rb +40 -0
  184. data/test/test_node_edit.rb +158 -0
  185. data/test/test_node_pi.rb +37 -0
  186. data/test/test_node_text.rb +69 -0
  187. data/test/test_node_write.rb +97 -0
  188. data/test/test_node_xlink.rb +28 -0
  189. data/test/test_parser.rb +324 -0
  190. data/test/test_parser_context.rb +198 -0
  191. data/test/test_properties.rb +38 -0
  192. data/test/test_reader.rb +364 -0
  193. data/test/test_relaxng.rb +53 -0
  194. data/test/test_sax_parser.rb +326 -0
  195. data/test/test_schema.rb +168 -0
  196. data/test/test_suite.rb +48 -0
  197. data/test/test_traversal.rb +152 -0
  198. data/test/test_writer.rb +468 -0
  199. data/test/test_xinclude.rb +20 -0
  200. data/test/test_xml.rb +263 -0
  201. data/test/test_xpath.rb +244 -0
  202. data/test/test_xpath_context.rb +88 -0
  203. data/test/test_xpath_expression.rb +37 -0
  204. data/test/test_xpointer.rb +72 -0
  205. metadata +325 -0
@@ -0,0 +1,10 @@
1
+ /* Please see the LICENSE file for copyright and distribution information */
2
+
3
+ #ifndef __RXML_XPATH_EXPRESSION__
4
+ #define __RXML_XPATH_EXPRESSION__
5
+
6
+ extern VALUE cXMLXPathExpression;
7
+
8
+ void rxml_init_xpath_expression(void);
9
+
10
+ #endif
@@ -0,0 +1,338 @@
1
+ #include "ruby_libxml.h"
2
+
3
+ /*
4
+ * Document-class: LibXML::XML::XPath::Object
5
+ *
6
+ * A collection of nodes returned from the evaluation of an XML::XPath
7
+ * or XML::XPointer expression.
8
+ */
9
+
10
+ VALUE cXMLXPathObject;
11
+
12
+
13
+ /* Memory management of xpath results is tricky. If a nodeset is
14
+ returned, it generally consists of pointers to nodes in the
15
+ original document. However, namespace nodes are handled differently -
16
+ libxml creates copies of them instead. Thus, when an xmlXPathObjectPtr
17
+ is freed, libxml iterates over the results to find the copied namespace
18
+ nodes to free them.
19
+
20
+ This causes problems for the bindings because the underlying document
21
+ may be freed before the xmlXPathObjectPtr instance. This might seem
22
+ counterintuitive since the xmlXPathObjectPtr marks the document.
23
+ However, once both objects go out of scope, the order of their
24
+ destruction is random.
25
+
26
+ To deal with this, the wrapper code searches for the namespace nodes
27
+ and wraps them in Ruby objects. When the Ruby objects go out of scope
28
+ then the namespace nodes are freed. */
29
+
30
+ static void rxml_xpath_object_free(rxml_xpath_object *rxpop)
31
+ {
32
+ /* We positively, absolutely cannot let libxml iterate over
33
+ the nodeTab since if the underlying document has been
34
+ freed the majority of entries are invalid, resulting in
35
+ segmentation faults.*/
36
+ if (rxpop->xpop->nodesetval && rxpop->xpop->nodesetval->nodeTab)
37
+ {
38
+ xmlFree(rxpop->xpop->nodesetval->nodeTab);
39
+ rxpop->xpop->nodesetval->nodeTab = NULL;
40
+ }
41
+ xmlXPathFreeObject(rxpop->xpop);
42
+ xfree(rxpop);
43
+ }
44
+
45
+ /* Custom free function for copied namespace nodes */
46
+ static void rxml_xpath_namespace_free(xmlNsPtr xns)
47
+ {
48
+ xmlFreeNs(xns);
49
+ }
50
+
51
+ static void rxml_xpath_object_mark(rxml_xpath_object *rxpop)
52
+ {
53
+ VALUE doc = (VALUE)rxpop->xdoc->_private;
54
+ rb_gc_mark(doc);
55
+ rb_gc_mark(rxpop->nsnodes);
56
+ }
57
+
58
+ VALUE rxml_xpath_object_wrap(xmlDocPtr xdoc, xmlXPathObjectPtr xpop)
59
+ {
60
+ int i;
61
+ rxml_xpath_object *rxpop = ALLOC(rxml_xpath_object);
62
+
63
+ /* Make sure Ruby's GC can find the array in the stack */
64
+ VALUE nsnodes = rb_ary_new();
65
+ rxpop->xdoc =xdoc;
66
+ rxpop->xpop = xpop;
67
+
68
+ /* Find all the extra namespace nodes and wrap them. */
69
+ if (xpop->nodesetval && xpop->nodesetval->nodeNr)
70
+ {
71
+ for (i = 0; i < xpop->nodesetval->nodeNr; i++)
72
+ {
73
+ xmlNodePtr xnode = xpop->nodesetval->nodeTab[i];
74
+ if (xnode != NULL && xnode->type == XML_NAMESPACE_DECL)
75
+ {
76
+ VALUE ns = Qnil;
77
+ xmlNsPtr xns = (xmlNsPtr)xnode;
78
+
79
+ /* Get rid of libxml's -> next hack. The issue here is
80
+ the rxml_namespace code assumes that ns->next refers
81
+ to another namespace. */
82
+ xns->next = NULL;
83
+
84
+ /* Specify a custom free function here since by default
85
+ namespace nodes will not be freed */
86
+ ns = rxml_namespace_wrap((xmlNsPtr)xnode);
87
+ RDATA(ns)->dfree = (RUBY_DATA_FUNC)rxml_xpath_namespace_free;
88
+ rb_ary_push(nsnodes, ns);
89
+ }
90
+ }
91
+ }
92
+
93
+ rxpop->nsnodes = nsnodes;
94
+ return Data_Wrap_Struct(cXMLXPathObject, rxml_xpath_object_mark, rxml_xpath_object_free, rxpop);
95
+ }
96
+
97
+ static VALUE rxml_xpath_object_tabref(xmlXPathObjectPtr xpop, int index)
98
+ {
99
+ if (index < 0)
100
+ index = xpop->nodesetval->nodeNr + index;
101
+
102
+ if (index < 0 || index + 1 > xpop->nodesetval->nodeNr)
103
+ return Qnil;
104
+
105
+ switch (xpop->nodesetval->nodeTab[index]->type)
106
+ {
107
+ case XML_ATTRIBUTE_NODE:
108
+ return rxml_attr_wrap((xmlAttrPtr) xpop->nodesetval->nodeTab[index]);
109
+ break;
110
+ case XML_NAMESPACE_DECL:
111
+ return rxml_namespace_wrap((xmlNsPtr)xpop->nodesetval->nodeTab[index]);
112
+ break;
113
+ default:
114
+ return rxml_node_wrap(xpop->nodesetval->nodeTab[index]);
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 rxml_new_cstr( rxpop->xpop->stringval, rxpop->xdoc->encoding);
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
+ rb_define_alias(cXMLXPathObject, "size", "length");
337
+
338
+ }
@@ -0,0 +1,17 @@
1
+ #ifndef __RXML_XPATH_OBJECT__
2
+ #define __RXML_XPATH_OBJECT__
3
+
4
+ extern VALUE cXMLXPathObject;
5
+
6
+ typedef struct rxml_xpath_object
7
+ {
8
+ xmlDocPtr xdoc;
9
+ xmlXPathObjectPtr xpop;
10
+ VALUE nsnodes;
11
+ } rxml_xpath_object;
12
+
13
+
14
+ void rxml_init_xpath_object(void);
15
+ VALUE rxml_xpath_object_wrap(xmlDocPtr xdoc, xmlXPathObjectPtr xpop);
16
+
17
+ #endif
@@ -0,0 +1,99 @@
1
+ /* Please see the LICENSE file for copyright and distribution information */
2
+
3
+ #include "ruby_libxml.h"
4
+ #include "ruby_xml_xpointer.h"
5
+
6
+ VALUE cXMLXPointer;
7
+
8
+ /*
9
+ * Document-class: LibXML::XML::XPointer
10
+ *
11
+ * The XML::Pointer class provides a standards based API for searching an xml document.
12
+ * XPointer is based on the XML Path Language (XML::XPath) and is documented
13
+ * at http://www.w3.org/TR/WD-xptr.
14
+ */
15
+
16
+ static VALUE rxml_xpointer_point(VALUE class, VALUE rnode, VALUE xptr_str)
17
+ {
18
+ #ifdef LIBXML_XPTR_ENABLED
19
+ xmlNodePtr xnode;
20
+ xmlXPathContextPtr xctxt;
21
+ xmlXPathObjectPtr xpop;
22
+
23
+ VALUE context;
24
+ VALUE result;
25
+ VALUE argv[1];
26
+
27
+ Check_Type(xptr_str, T_STRING);
28
+ if (rb_obj_is_kind_of(rnode, cXMLNode) == Qfalse)
29
+ rb_raise(rb_eTypeError, "require an XML::Node object");
30
+
31
+ Data_Get_Struct(rnode, xmlNode, xnode);
32
+
33
+ argv[0] = rb_funcall(rnode, rb_intern("doc"), 0);
34
+ context = rb_class_new_instance(1, argv, cXMLXPathContext);
35
+ Data_Get_Struct(context, xmlXPathContext, xctxt);
36
+
37
+ xpop = xmlXPtrEval((xmlChar*)StringValuePtr(xptr_str), xctxt);
38
+ if (!xpop)
39
+ rxml_raise(&xmlLastError);
40
+
41
+ result = rxml_xpath_object_wrap(xnode->doc, xpop);
42
+ rb_iv_set(result, "@context", context);
43
+
44
+ return(result);
45
+ #else
46
+ rb_warn("libxml was compiled without XPointer support");
47
+ return (Qfalse);
48
+ #endif
49
+ }
50
+
51
+ VALUE rxml_xpointer_point2(VALUE node, VALUE xptr_str)
52
+ {
53
+ return (rxml_xpointer_point(cXMLXPointer, node, xptr_str));
54
+ }
55
+
56
+ /*
57
+ * call-seq:
58
+ * XML::XPointer.range(start_node, end_node) -> xpath
59
+ *
60
+ * Create an xpath representing the range between the supplied
61
+ * start and end node.
62
+ */
63
+ static VALUE rxml_xpointer_range(VALUE class, VALUE rstart, VALUE rend)
64
+ {
65
+ #ifdef LIBXML_XPTR_ENABLED
66
+ xmlNodePtr start, end;
67
+ VALUE rxxp;
68
+ xmlXPathObjectPtr xpath;
69
+
70
+ if (rb_obj_is_kind_of(rstart, cXMLNode) == Qfalse)
71
+ rb_raise(rb_eTypeError, "require an XML::Node object as a starting point");
72
+ if (rb_obj_is_kind_of(rend, cXMLNode) == Qfalse)
73
+ rb_raise(rb_eTypeError, "require an XML::Node object as an ending point");
74
+
75
+ Data_Get_Struct(rstart, xmlNode, start);
76
+ if (start == NULL)
77
+ return(Qnil);
78
+
79
+ Data_Get_Struct(rend, xmlNode, end);
80
+ if (end == NULL)
81
+ return(Qnil);
82
+
83
+ xpath = xmlXPtrNewRangeNodes(start, end);
84
+ if (xpath == NULL)
85
+ rb_fatal("You shouldn't be able to have this happen");
86
+
87
+ rxxp = rxml_xpath_object_wrap(start->doc, xpath);
88
+ return(rxxp);
89
+ #else
90
+ rb_warn("libxml was compiled without XPointer support");
91
+ return (Qfalse);
92
+ #endif
93
+ }
94
+
95
+ void rxml_init_xpointer(void)
96
+ {
97
+ cXMLXPointer = rb_define_class_under(mXML, "XPointer", rb_cObject);
98
+ rb_define_singleton_method(cXMLXPointer, "range", rxml_xpointer_range, 2);
99
+ }
@@ -0,0 +1,11 @@
1
+ /* Please see the LICENSE file for copyright and distribution information */
2
+
3
+ #ifndef __RXML_XPOINTER__
4
+ #define __RXML_XPOINTER__
5
+
6
+ extern VALUE cXMLXPointer;
7
+
8
+ void rxml_init_xpointer(void);
9
+ VALUE rxml_xpointer_point2(VALUE node, VALUE xptr_str);
10
+
11
+ #endif
@@ -0,0 +1,28 @@
1
+ 
2
+ Microsoft Visual Studio Solution File, Format Version 12.00
3
+ # Visual Studio 14
4
+ VisualStudioVersion = 14.0.25420.1
5
+ MinimumVisualStudioVersion = 10.0.40219.1
6
+ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libxml_ruby", "libxml_ruby\libxml_ruby.vcxproj", "{0B65CD1D-EEB9-41AE-93BB-75496E504152}"
7
+ EndProject
8
+ Global
9
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
10
+ Debug|x64 = Debug|x64
11
+ Debug|x86 = Debug|x86
12
+ Release|x64 = Release|x64
13
+ Release|x86 = Release|x86
14
+ EndGlobalSection
15
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
16
+ {0B65CD1D-EEB9-41AE-93BB-75496E504152}.Debug|x64.ActiveCfg = Debug|x64
17
+ {0B65CD1D-EEB9-41AE-93BB-75496E504152}.Debug|x64.Build.0 = Debug|x64
18
+ {0B65CD1D-EEB9-41AE-93BB-75496E504152}.Debug|x86.ActiveCfg = Debug|x64
19
+ {0B65CD1D-EEB9-41AE-93BB-75496E504152}.Debug|x86.Build.0 = Debug|x64
20
+ {0B65CD1D-EEB9-41AE-93BB-75496E504152}.Release|x64.ActiveCfg = Release|x64
21
+ {0B65CD1D-EEB9-41AE-93BB-75496E504152}.Release|x64.Build.0 = Release|x64
22
+ {0B65CD1D-EEB9-41AE-93BB-75496E504152}.Release|x86.ActiveCfg = Release|Win32
23
+ {0B65CD1D-EEB9-41AE-93BB-75496E504152}.Release|x86.Build.0 = Release|Win32
24
+ EndGlobalSection
25
+ GlobalSection(SolutionProperties) = preSolution
26
+ HideSolutionNode = FALSE
27
+ EndGlobalSection
28
+ EndGlobal
Binary file
@@ -0,0 +1,123 @@
1
+ # encoding: UTF-8
2
+
3
+ module LibXML
4
+ module XML
5
+ class Attr
6
+ include Enumerable
7
+
8
+ # call-seq:
9
+ # attr.child? -> (true|false)
10
+ #
11
+ # Returns whether this attribute has child attributes.
12
+ #
13
+ def child?
14
+ not self.children.nil?
15
+ end
16
+
17
+ # call-seq:
18
+ # attr.doc? -> (true|false)
19
+ #
20
+ # Determine whether this attribute is associated with an
21
+ # XML::Document.
22
+ def doc?
23
+ not self.doc.nil?
24
+ end
25
+
26
+ # call-seq:
27
+ # attr.last? -> (true|false)
28
+ #
29
+ # Determine whether this is the last attribute.
30
+ def last?
31
+ self.last.nil?
32
+ end
33
+
34
+ # call-seq:
35
+ # attr.next? -> (true|false)
36
+ #
37
+ # Determine whether there is a next attribute.
38
+ def next?
39
+ not self.next.nil?
40
+ end
41
+
42
+ # call-seq:
43
+ # attr.ns? -> (true|false)
44
+ #
45
+ # Determine whether this attribute has an associated
46
+ # namespace.
47
+ def ns?
48
+ not self.ns.nil?
49
+ end
50
+
51
+ # call-seq:
52
+ # attr.namespacess -> XML::Namespaces
53
+ #
54
+ # Returns this node's XML::Namespaces object,
55
+ # which is used to access the namespaces
56
+ # associated with this node.
57
+ def namespaces
58
+ @namespaces ||= XML::Namespaces.new(self)
59
+ end
60
+
61
+ #
62
+ # call-seq:
63
+ # attr.parent? -> (true|false)
64
+ #
65
+ # Determine whether this attribute has a parent.
66
+ def parent?
67
+ not self.parent.nil?
68
+ end
69
+
70
+ # call-seq:
71
+ # attr.prev? -> (true|false)
72
+ #
73
+ # Determine whether there is a previous attribute.
74
+ def prev?
75
+ not self.prev.nil?
76
+ end
77
+
78
+ # Returns this node's type name
79
+ def node_type_name
80
+ if node_type == Node::ATTRIBUTE_NODE
81
+ 'attribute'
82
+ else
83
+ raise(UnknownType, "Unknown node type: %n", node.node_type);
84
+ end
85
+ end
86
+
87
+ # Iterates nodes and attributes
88
+ def siblings(node, &blk)
89
+ if n = node
90
+ loop do
91
+ blk.call(n)
92
+ break unless n = n.next
93
+ end
94
+ end
95
+ end
96
+
97
+ def each_sibling(&blk)
98
+ siblings(self,&blk)
99
+ end
100
+
101
+ alias :each_attr :each_sibling
102
+ alias :each :each_sibling
103
+
104
+ def to_h
105
+ inject({}) do |h,a|
106
+ h[a.name] = a.value
107
+ h
108
+ end
109
+ end
110
+
111
+ def to_a
112
+ inject([]) do |ary,a|
113
+ ary << [a.name, a.value]
114
+ ary
115
+ end
116
+ end
117
+
118
+ def to_s
119
+ "#{name} = #{value}"
120
+ end
121
+ end
122
+ end
123
+ end
@@ -0,0 +1,80 @@
1
+ # encoding: UTF-8
2
+
3
+ module LibXML
4
+ module XML
5
+ class AttrDecl
6
+ include Enumerable
7
+
8
+ # call-seq:
9
+ # attr_decl.child -> nil
10
+ #
11
+ # Obtain this attribute declaration's child attribute(s).
12
+ # It will always be nil.
13
+ def child
14
+ nil
15
+ end
16
+
17
+ # call-seq:
18
+ # attr_decl.child? -> (true|false)
19
+ #
20
+ # Returns whether this attribute declaration has child attributes.
21
+ #
22
+ def child?
23
+ not self.children.nil?
24
+ end
25
+
26
+ # call-seq:
27
+ # attr_decl.doc? -> (true|false)
28
+ #
29
+ # Determine whether this attribute declaration is associated with an
30
+ # XML::Document.
31
+ def doc?
32
+ not self.doc.nil?
33
+ end
34
+
35
+ # call-seq:
36
+ # attr_decl.next? -> (true|false)
37
+ #
38
+ # Determine whether there is a next attribute declaration.
39
+ def next?
40
+ not self.next.nil?
41
+ end
42
+
43
+ # call-seq:
44
+ # attr_decl.parent? -> (true|false)
45
+ #
46
+ # Determine whether this attribute declaration has a parent .
47
+ def parent?
48
+ not self.parent.nil?
49
+ end
50
+
51
+ # call-seq:
52
+ # attr_decl.prev? -> (true|false)
53
+ #
54
+ # Determine whether there is a previous attribute declaration.
55
+ def prev?
56
+ not self.prev.nil?
57
+ end
58
+
59
+ # call-seq:
60
+ # attr_decl.node_type_name -> 'attribute declaration'
61
+ #
62
+ # Returns this attribute declaration's node type name.
63
+ def node_type_name
64
+ if node_type == Node::ATTRIBUTE_DECL
65
+ 'attribute declaration'
66
+ else
67
+ raise(UnknownType, "Unknown node type: %n", node.node_type);
68
+ end
69
+ end
70
+
71
+ # call-seq:
72
+ # attr_decl.to_s -> string
73
+ #
74
+ # Returns a string representation of this attribute declaration.
75
+ def to_s
76
+ "#{name} = #{value}"
77
+ end
78
+ end
79
+ end
80
+ end