libxml-ruby 0.9.5-x86-mswin32-60 → 0.9.6-x86-mswin32-60

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. data/CHANGES +28 -0
  2. data/README +8 -12
  3. data/ext/libxml/cbg.c +86 -86
  4. data/ext/libxml/libxml.c +875 -899
  5. data/ext/libxml/ruby_libxml.h +91 -65
  6. data/ext/libxml/ruby_xml_attr.c +485 -485
  7. data/ext/libxml/ruby_xml_attr.h +3 -3
  8. data/ext/libxml/ruby_xml_attributes.h +2 -2
  9. data/ext/libxml/ruby_xml_document.c +124 -307
  10. data/ext/libxml/ruby_xml_document.h +3 -3
  11. data/ext/libxml/ruby_xml_dtd.c +119 -119
  12. data/ext/libxml/ruby_xml_dtd.h +2 -2
  13. data/ext/libxml/ruby_xml_error.c +1 -1
  14. data/ext/libxml/ruby_xml_error.h +2 -2
  15. data/ext/libxml/ruby_xml_html_parser.c +119 -119
  16. data/ext/libxml/ruby_xml_html_parser.h +3 -3
  17. data/ext/libxml/ruby_xml_input.c +13 -11
  18. data/ext/libxml/ruby_xml_input.h +3 -3
  19. data/ext/libxml/ruby_xml_input_cbg.c +197 -197
  20. data/ext/libxml/ruby_xml_namespace.c +158 -0
  21. data/ext/libxml/ruby_xml_namespace.h +12 -0
  22. data/ext/libxml/ruby_xml_namespaces.c +303 -0
  23. data/ext/libxml/{ruby_xml_ns.h → ruby_xml_namespaces.h} +4 -5
  24. data/ext/libxml/ruby_xml_node.c +88 -293
  25. data/ext/libxml/ruby_xml_node.h +4 -4
  26. data/ext/libxml/ruby_xml_parser.c +152 -152
  27. data/ext/libxml/ruby_xml_parser.h +3 -3
  28. data/ext/libxml/ruby_xml_parser_context.c +630 -657
  29. data/ext/libxml/ruby_xml_parser_context.h +3 -3
  30. data/ext/libxml/ruby_xml_reader.c +899 -904
  31. data/ext/libxml/ruby_xml_reader.h +2 -2
  32. data/ext/libxml/ruby_xml_relaxng.h +2 -2
  33. data/ext/libxml/ruby_xml_sax_parser.c +175 -175
  34. data/ext/libxml/ruby_xml_sax_parser.h +3 -3
  35. data/ext/libxml/ruby_xml_schema.c +165 -165
  36. data/ext/libxml/ruby_xml_schema.h +2 -2
  37. data/ext/libxml/ruby_xml_state.h +2 -2
  38. data/ext/libxml/ruby_xml_xinclude.c +24 -24
  39. data/ext/libxml/ruby_xml_xinclude.h +3 -3
  40. data/ext/libxml/ruby_xml_xpath.c +108 -108
  41. data/ext/libxml/ruby_xml_xpath.h +3 -3
  42. data/ext/libxml/ruby_xml_xpath_context.c +84 -35
  43. data/ext/libxml/ruby_xml_xpath_context.h +3 -3
  44. data/ext/libxml/ruby_xml_xpath_expression.c +5 -7
  45. data/ext/libxml/ruby_xml_xpath_expression.h +2 -2
  46. data/ext/libxml/ruby_xml_xpath_object.c +7 -7
  47. data/ext/libxml/ruby_xml_xpath_object.h +2 -2
  48. data/ext/libxml/ruby_xml_xpointer.c +107 -107
  49. data/ext/libxml/ruby_xml_xpointer.h +3 -3
  50. data/ext/libxml/version.h +2 -2
  51. data/ext/mingw/libxml_ruby.dll.a +0 -0
  52. data/ext/mingw/libxml_ruby.so +0 -0
  53. data/ext/vc/libxml_ruby.vcproj +13 -5
  54. data/lib/libxml.rb +4 -1
  55. data/lib/libxml/document.rb +40 -6
  56. data/lib/libxml/hpricot.rb +76 -76
  57. data/lib/libxml/namespace.rb +60 -0
  58. data/lib/libxml/namespaces.rb +36 -0
  59. data/lib/libxml/node.rb +90 -26
  60. data/lib/libxml/ns.rb +20 -0
  61. data/test/model/bands.xml +5 -0
  62. data/test/tc_attributes.rb +1 -1
  63. data/test/tc_document.rb +24 -41
  64. data/test/tc_document_write.rb +87 -115
  65. data/test/tc_namespace.rb +59 -0
  66. data/test/tc_namespaces.rb +174 -0
  67. data/test/tc_node.rb +41 -33
  68. data/test/tc_node_copy.rb +1 -1
  69. data/test/tc_node_edit.rb +6 -0
  70. data/test/tc_node_write.rb +76 -0
  71. data/test/tc_xinclude.rb +2 -9
  72. data/test/tc_xpath.rb +38 -11
  73. data/test/test_suite.rb +3 -1
  74. metadata +16 -9
  75. data/ext/libxml/ruby_xml_ns.c +0 -150
  76. data/test/ets_copy_bug.rb +0 -21
  77. data/test/ets_copy_bug3.rb +0 -38
  78. data/test/model/default_validation_bug.rb +0 -0
  79. data/test/tc_ns.rb +0 -18
@@ -1,5 +1,5 @@
1
- #ifndef __rxml_SCHEMA__
2
- #define __rxml_SCHEMA__
1
+ #ifndef __RXML_SCHEMA__
2
+ #define __RXML_SCHEMA__
3
3
 
4
4
  #include <libxml/schemasInternals.h>
5
5
  #include <libxml/xmlschemas.h>
@@ -1,7 +1,7 @@
1
1
  /* $Id$ */
2
2
 
3
- #ifndef __rxml_STATE__
4
- #define __rxml_STATE__
3
+ #ifndef __RXML_STATE__
4
+ #define __RXML_STATE__
5
5
 
6
6
  extern VALUE cXMLState;
7
7
  extern VALUE LIBXML_STATE;
@@ -1,24 +1,24 @@
1
- /* $Id: ruby_xml_xinclude.c 650 2008-11-30 03:40:22Z cfis $ */
2
-
3
- #include "ruby_libxml.h"
4
- #include "ruby_xml_xinclude.h"
5
-
6
- VALUE cXMLXInclude;
7
-
8
- /*
9
- * Document-class: LibXML::XML::XInclude
10
- *
11
- * The ruby bindings do not currently expose libxml's
12
- * XInclude fuctionality.
13
- */
14
-
15
- // Rdoc needs to know
16
- #ifdef RDOC_NEVER_DEFINED
17
- mLibXML = rb_define_module("LibXML");
18
- mXML = rb_define_module_under(mLibXML, "XML");
19
- #endif
20
-
21
- void ruby_init_xml_xinclude(void)
22
- {
23
- cXMLXInclude = rb_define_class_under(mXML, "XInclude", rb_cObject);
24
- }
1
+ /* $Id: ruby_xml_xinclude.c 650 2008-11-30 03:40:22Z cfis $ */
2
+
3
+ #include "ruby_libxml.h"
4
+ #include "ruby_xml_xinclude.h"
5
+
6
+ VALUE cXMLXInclude;
7
+
8
+ /*
9
+ * Document-class: LibXML::XML::XInclude
10
+ *
11
+ * The ruby bindings do not currently expose libxml's
12
+ * XInclude fuctionality.
13
+ */
14
+
15
+ // Rdoc needs to know
16
+ #ifdef RDOC_NEVER_DEFINED
17
+ mLibXML = rb_define_module("LibXML");
18
+ mXML = rb_define_module_under(mLibXML, "XML");
19
+ #endif
20
+
21
+ void ruby_init_xml_xinclude(void)
22
+ {
23
+ cXMLXInclude = rb_define_class_under(mXML, "XInclude", rb_cObject);
24
+ }
@@ -1,9 +1,9 @@
1
- /* $Id: ruby_xml_xinclude.h 612 2008-11-21 08:01:29Z cfis $ */
1
+ /* $Id: ruby_xml_xinclude.h 666 2008-12-07 00:16:50Z cfis $ */
2
2
 
3
3
  /* Please see the LICENSE file for copyright and distribution information */
4
4
 
5
- #ifndef __rxml_XINCLUDE__
6
- #define __rxml_XINCLUDE__
5
+ #ifndef __RXML_XINCLUDE__
6
+ #define __RXML_XINCLUDE__
7
7
 
8
8
  extern VALUE cXMLXInclude;
9
9
  extern VALUE eXMLXIncludeError;
@@ -1,108 +1,108 @@
1
- /* $Id: ruby_xml_xpath.c 650 2008-11-30 03:40:22Z 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
- #include "ruby_xml_xpath_context.h"
8
-
9
- /*
10
- * Document-class: LibXML::XML::XPath
11
- *
12
- * The XML::XPath module is used to query XML documents. It is
13
- * usually accessed via the XML::Document#find or
14
- * XML::Node#find methods. For example:
15
- *
16
- * document.find('/foo', namespaces) -> XML::XPath::Object
17
- *
18
- * The optional namespaces parameter can be a string, array or
19
- * hash table.
20
- *
21
- * document.find('/foo', 'xlink:http://www.w3.org/1999/xlink')
22
- * document.find('/foo', ['xlink:http://www.w3.org/1999/xlink',
23
- * 'xi:http://www.w3.org/2001/XInclude')
24
- * document.find('/foo', 'xlink' => 'http://www.w3.org/1999/xlink',
25
- * 'xi' => 'http://www.w3.org/2001/XInclude')
26
- *
27
- *
28
- * === Working With Default Namespaces
29
- *
30
- * Finding namespaced elements and attributes can be tricky.
31
- * Lets work through an example of a document with a default
32
- * namespace:
33
- *
34
- * <?xml version="1.0" encoding="utf-8"?>
35
- * <feed xmlns="http://www.w3.org/2005/Atom">
36
- * <title type="text">Phil Bogle's Contacts</title>
37
- * </feed>
38
- *
39
- * To find nodes you must define the atom namespace for
40
- * libxml. One way to do this is:
41
- *
42
- * node = doc.find('atom:title', 'atom:http://www.w3.org/2005/Atom')
43
- *
44
- * Alternatively, you can register the default namespace like this:
45
- *
46
- * doc.root.register_default_namespace('atom')
47
- * node = doc.find('atom:title')
48
- *
49
- * === More Complex Namespace Examples
50
- *
51
- * Lets work through some more complex examples using the
52
- * following xml document:
53
- *
54
- * <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
55
- * <soap:Body>
56
- * <getManufacturerNamesResponse xmlns="http://services.somewhere.com">
57
- * <IDAndNameList xmlns="http://services.somewhere.com">
58
- * <ns1:IdAndName xmlns:ns1="http://domain.somewhere.com"/>
59
- * </IDAndNameList>
60
- * </getManufacturerNamesResponse>
61
- * </soap:Envelope>
62
- *
63
- * # Since the soap namespace is defined on the root
64
- * # node we can directly use it.
65
- * doc.find('/soap:Envelope')
66
- *
67
- * # Since the ns1 namespace is not defined on the root node
68
- * # we have to first register it with the xpath engine.
69
- * doc.find('//ns1:IdAndName',
70
- * 'ns1:http://domain.somewhere.com')
71
- *
72
- * # Since the getManufacturerNamesResponse element uses a default
73
- * # namespace we first have to give it a prefix and register
74
- * # it with the xpath engine.
75
- * doc.find('//ns:getManufacturerNamesResponse',
76
- * 'ns:http://services.somewhere.com')
77
- *
78
- * # Here is an example showing a complex namespace aware
79
- * # xpath expression.
80
- * doc.find('/soap:Envelope/soap:Body/ns0:getManufacturerNamesResponse/ns0:IDAndNameList/ns1:IdAndName',
81
- ['ns0:http://services.somewhere.com', 'ns1:http://domain.somewhere.com'])
82
- */
83
-
84
- VALUE mXPath;
85
-
86
- // Rdoc needs to know
87
- #ifdef RDOC_NEVER_DEFINED
88
- mLibXML = rb_define_module("LibXML");
89
- mXML = rb_define_module_under(mLibXML, "XML");
90
- #endif
91
-
92
- void ruby_init_xml_xpath(void)
93
- {
94
- mXPath = rb_define_module_under(mXML, "XPath");
95
-
96
- rb_define_const(mXPath, "UNDEFINED", INT2NUM(XPATH_UNDEFINED));
97
- rb_define_const(mXPath, "NODESET", INT2NUM(XPATH_NODESET));
98
- rb_define_const(mXPath, "BOOLEAN", INT2NUM(XPATH_BOOLEAN));
99
- rb_define_const(mXPath, "NUMBER", INT2NUM(XPATH_NUMBER));
100
- rb_define_const(mXPath, "STRING", INT2NUM(XPATH_STRING));
101
- rb_define_const(mXPath, "POINT", INT2NUM(XPATH_POINT));
102
- rb_define_const(mXPath, "RANGE", INT2NUM(XPATH_RANGE));
103
- rb_define_const(mXPath, "LOCATIONSET", INT2NUM(XPATH_LOCATIONSET));
104
- rb_define_const(mXPath, "USERS", INT2NUM(XPATH_USERS));
105
- rb_define_const(mXPath, "XSLT_TREE", INT2NUM(XPATH_XSLT_TREE));
106
-
107
- ruby_init_xml_xpath_object();
108
- }
1
+ /* $Id: ruby_xml_xpath.c 666 2008-12-07 00:16:50Z 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
+ #include "ruby_xml_xpath_context.h"
8
+
9
+ /*
10
+ * Document-class: LibXML::XML::XPath
11
+ *
12
+ * The XML::XPath module is used to query XML documents. It is
13
+ * usually accessed via the XML::Document#find or
14
+ * XML::Node#find methods. For example:
15
+ *
16
+ * document.find('/foo', namespaces) -> XML::XPath::Object
17
+ *
18
+ * The optional namespaces parameter can be a string, array or
19
+ * hash table.
20
+ *
21
+ * document.find('/foo', 'xlink:http://www.w3.org/1999/xlink')
22
+ * document.find('/foo', ['xlink:http://www.w3.org/1999/xlink',
23
+ * 'xi:http://www.w3.org/2001/XInclude')
24
+ * document.find('/foo', 'xlink' => 'http://www.w3.org/1999/xlink',
25
+ * 'xi' => 'http://www.w3.org/2001/XInclude')
26
+ *
27
+ *
28
+ * === Working With Default Namespaces
29
+ *
30
+ * Finding namespaced elements and attributes can be tricky.
31
+ * Lets work through an example of a document with a default
32
+ * namespace:
33
+ *
34
+ * <?xml version="1.0" encoding="utf-8"?>
35
+ * <feed xmlns="http://www.w3.org/2005/Atom">
36
+ * <title type="text">Phil Bogle's Contacts</title>
37
+ * </feed>
38
+ *
39
+ * To find nodes you must define the atom namespace for
40
+ * libxml. One way to do this is:
41
+ *
42
+ * node = doc.find('atom:title', 'atom:http://www.w3.org/2005/Atom')
43
+ *
44
+ * Alternatively, you can register the default namespace like this:
45
+ *
46
+ * doc.root.namespaces.default_prefix = 'atom'
47
+ * node = doc.find('atom:title')
48
+ *
49
+ * === More Complex Namespace Examples
50
+ *
51
+ * Lets work through some more complex examples using the
52
+ * following xml document:
53
+ *
54
+ * <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
55
+ * <soap:Body>
56
+ * <getManufacturerNamesResponse xmlns="http://services.somewhere.com">
57
+ * <IDAndNameList xmlns="http://services.somewhere.com">
58
+ * <ns1:IdAndName xmlns:ns1="http://domain.somewhere.com"/>
59
+ * </IDAndNameList>
60
+ * </getManufacturerNamesResponse>
61
+ * </soap:Envelope>
62
+ *
63
+ * # Since the soap namespace is defined on the root
64
+ * # node we can directly use it.
65
+ * doc.find('/soap:Envelope')
66
+ *
67
+ * # Since the ns1 namespace is not defined on the root node
68
+ * # we have to first register it with the xpath engine.
69
+ * doc.find('//ns1:IdAndName',
70
+ * 'ns1:http://domain.somewhere.com')
71
+ *
72
+ * # Since the getManufacturerNamesResponse element uses a default
73
+ * # namespace we first have to give it a prefix and register
74
+ * # it with the xpath engine.
75
+ * doc.find('//ns:getManufacturerNamesResponse',
76
+ * 'ns:http://services.somewhere.com')
77
+ *
78
+ * # Here is an example showing a complex namespace aware
79
+ * # xpath expression.
80
+ * doc.find('/soap:Envelope/soap:Body/ns0:getManufacturerNamesResponse/ns0:IDAndNameList/ns1:IdAndName',
81
+ ['ns0:http://services.somewhere.com', 'ns1:http://domain.somewhere.com'])
82
+ */
83
+
84
+ VALUE mXPath;
85
+
86
+ // Rdoc needs to know
87
+ #ifdef RDOC_NEVER_DEFINED
88
+ mLibXML = rb_define_module("LibXML");
89
+ mXML = rb_define_module_under(mLibXML, "XML");
90
+ #endif
91
+
92
+ void ruby_init_xml_xpath(void)
93
+ {
94
+ mXPath = rb_define_module_under(mXML, "XPath");
95
+
96
+ rb_define_const(mXPath, "UNDEFINED", INT2NUM(XPATH_UNDEFINED));
97
+ rb_define_const(mXPath, "NODESET", INT2NUM(XPATH_NODESET));
98
+ rb_define_const(mXPath, "BOOLEAN", INT2NUM(XPATH_BOOLEAN));
99
+ rb_define_const(mXPath, "NUMBER", INT2NUM(XPATH_NUMBER));
100
+ rb_define_const(mXPath, "STRING", INT2NUM(XPATH_STRING));
101
+ rb_define_const(mXPath, "POINT", INT2NUM(XPATH_POINT));
102
+ rb_define_const(mXPath, "RANGE", INT2NUM(XPATH_RANGE));
103
+ rb_define_const(mXPath, "LOCATIONSET", INT2NUM(XPATH_LOCATIONSET));
104
+ rb_define_const(mXPath, "USERS", INT2NUM(XPATH_USERS));
105
+ rb_define_const(mXPath, "XSLT_TREE", INT2NUM(XPATH_XSLT_TREE));
106
+
107
+ ruby_init_xml_xpath_object();
108
+ }
@@ -1,9 +1,9 @@
1
- /* $Id: ruby_xml_xpath.h 614 2008-11-22 08:04:39Z cfis $ */
1
+ /* $Id: ruby_xml_xpath.h 666 2008-12-07 00:16:50Z cfis $ */
2
2
 
3
3
  /* Please see the LICENSE file for copyright and distribution information */
4
4
 
5
- #ifndef __rxml_XPATH__
6
- #define __rxml_XPATH__
5
+ #ifndef __RXML_XPATH__
6
+ #define __RXML_XPATH__
7
7
 
8
8
  extern VALUE mXPath;
9
9
 
@@ -1,4 +1,4 @@
1
- /* $Id: ruby_xml_xpath_context.c 650 2008-11-30 03:40:22Z cfis $ */
1
+ /* $Id: ruby_xml_xpath_context.c 673 2008-12-08 06:33:23Z cfis $ */
2
2
 
3
3
  /* Please see the LICENSE file for copyright and distribution information */
4
4
 
@@ -48,32 +48,29 @@ static VALUE rxml_xpath_context_initialize(VALUE self, VALUE node)
48
48
  {
49
49
  xmlDocPtr xdoc;
50
50
  VALUE document;
51
- #ifndef LIBXML_XPATH_ENABLED
52
- rb_raise(rb_eTypeError, "libxml was not compiled with XPath support.");
53
- #endif
54
51
 
55
52
  if (rb_obj_is_kind_of(node, cXMLNode) == Qtrue)
56
53
  {
57
54
  document = rb_funcall(node, rb_intern("doc"), 0);
58
- if NIL_P(document)
59
- rb_raise(rb_eTypeError, "Supplied node must belong to a document.");
60
- }
61
- else if (rb_obj_is_kind_of(node, cXMLDocument) == Qtrue)
62
- {
63
- document = node;
64
- }
65
- else
66
- {
67
- rb_raise(rb_eTypeError, "Supplied argument must be a document or node.");
68
- }
55
+ if (NIL_P(document))
56
+ rb_raise(rb_eTypeError, "Supplied node must belong to a document.");
57
+ }
58
+ else if (rb_obj_is_kind_of(node, cXMLDocument) == Qtrue)
59
+ {
60
+ document = node;
61
+ }
62
+ else
63
+ {
64
+ rb_raise(rb_eTypeError, "Supplied argument must be a document or node.");
65
+ }
69
66
 
70
- Data_Get_Struct(document, xmlDoc, xdoc);
71
- DATA_PTR(self) = xmlXPathNewContext(xdoc);
67
+ Data_Get_Struct(document, xmlDoc, xdoc);
68
+ DATA_PTR(self) = xmlXPathNewContext(xdoc);
72
69
 
73
- /* Save the doc as an attribute, this will expose it to Ruby's GC. */
74
- rb_iv_set(self, "@doc", document);
70
+ /* Save the doc as an attribute, this will expose it to Ruby's GC. */
71
+ rb_iv_set(self, "@doc", document);
75
72
 
76
- return self;
73
+ return self;
77
74
  }
78
75
 
79
76
  /*
@@ -85,12 +82,14 @@ return self;
85
82
 
86
83
  * context.register_namespace('xi', 'http://www.w3.org/2001/XInclude')
87
84
  */
88
- static VALUE rxml_xpath_context_register_namespace(VALUE self, VALUE prefix,
89
- VALUE uri)
85
+ static VALUE rxml_xpath_context_register_namespace(VALUE self, VALUE prefix, VALUE uri)
90
86
  {
91
87
  xmlXPathContextPtr ctxt;
92
-
93
88
  Data_Get_Struct(self, xmlXPathContext, ctxt);
89
+
90
+ /* Prefix could be a symbol. */
91
+ prefix = rb_obj_as_string(prefix);
92
+
94
93
  if (xmlXPathRegisterNs(ctxt, (xmlChar*) StringValuePtr(prefix),
95
94
  (xmlChar*) StringValuePtr(uri)) == 0)
96
95
  {
@@ -149,8 +148,8 @@ static VALUE rxml_xpath_context_register_namespaces_from_node(VALUE self,
149
148
  Skip it for now. */
150
149
  if (xns->prefix)
151
150
  {
152
- VALUE prefix = rb_str_new2(xns->prefix);
153
- VALUE uri = rb_str_new2(xns->href);
151
+ VALUE prefix = rb_str_new2((const char*)xns->prefix);
152
+ VALUE uri = rb_str_new2((const char*)xns->href);
154
153
  rxml_xpath_context_register_namespace(self, prefix, uri);
155
154
  }
156
155
  xns = xns->next;
@@ -171,7 +170,9 @@ static int iterate_ns_hash(st_data_t prefix, st_data_t uri, st_data_t self)
171
170
  * call-seq:
172
171
  * context.register_namespaces(["prefix:uri"]) -> self
173
172
  *
174
- * Register the specified namespaces in this context.
173
+ * Register the specified namespaces in this context. There are
174
+ * three different forms that libxml accepts. These include
175
+ * a string, an array of strings, or a hash table:
175
176
  *
176
177
  * context.register_namespaces('xi:http://www.w3.org/2001/XInclude')
177
178
  * context.register_namespaces(['xlink:http://www.w3.org/1999/xlink',
@@ -212,7 +213,7 @@ static VALUE rxml_xpath_context_register_namespaces(VALUE self, VALUE nslist)
212
213
  }
213
214
  break;
214
215
  case T_HASH:
215
- st_foreach(RHASH(nslist)->tbl, iterate_ns_hash, self);
216
+ st_foreach(RHASH_TBL(nslist), iterate_ns_hash, self);
216
217
  break;
217
218
  default:
218
219
  rb_raise(
@@ -287,19 +288,67 @@ static VALUE rxml_xpath_context_find(VALUE self, VALUE xpath_expr)
287
288
  return result;
288
289
  }
289
290
 
291
+
292
+ /*
293
+ * call-seq:
294
+ * context.enable_cache(size = nil)
295
+ *
296
+ * Enables an XPath::Context's built-in cache. If the cache is
297
+ * enabled then XPath objects will be cached internally for reuse.
298
+ * The size parameter controls sets the maximum number of XPath objects
299
+ * that will be cached per XPath object type (node-set, string, number,
300
+ * boolean, and misc objects). Set size to nil to use the default
301
+ * cache size of 100.
302
+ */
303
+ static VALUE
304
+ rxml_xpath_context_enable_cache(int argc, VALUE *argv, VALUE self)
305
+ {
306
+ xmlXPathContextPtr xctxt;
307
+ VALUE size;
308
+ int value = -1;
309
+
310
+ Data_Get_Struct(self, xmlXPathContext, xctxt);
311
+
312
+ if (rb_scan_args(argc, argv, "01", &size) == 1)
313
+ {
314
+ value = NUM2INT(size);
315
+ }
316
+
317
+ if (xmlXPathContextSetCache(xctxt, 1, value, 0) == -1)
318
+ rxml_raise(&xmlLastError);
319
+
320
+ return self;
321
+ }
322
+
323
+ /*
324
+ * call-seq:
325
+ * context.disable_cache
326
+ *
327
+ * Disables an XPath::Context's built-in cache.
328
+ */
329
+ static VALUE
330
+ rxml_xpath_context_disable_cache(VALUE self) {
331
+ xmlXPathContextPtr xctxt;
332
+ Data_Get_Struct(self, xmlXPathContext, xctxt);
333
+
334
+ if (xmlXPathContextSetCache(xctxt, 0, 0, 0) == -1)
335
+ rxml_raise(&xmlLastError);
336
+
337
+ return self;
338
+ }
339
+
340
+
290
341
  void ruby_init_xml_xpath_context(void)
291
342
  {
292
343
  cXMLXPathContext = rb_define_class_under(mXPath, "Context", rb_cObject);
293
344
  rb_define_alloc_func(cXMLXPathContext, rxml_xpath_context_alloc);
294
345
  rb_define_attr(cXMLXPathContext, "doc", 1, 0);
295
- rb_define_method(cXMLXPathContext, "initialize",
296
- rxml_xpath_context_initialize, 1);
297
- rb_define_method(cXMLXPathContext, "register_namespaces",
298
- rxml_xpath_context_register_namespaces, 1);
299
- rb_define_method(cXMLXPathContext, "register_namespaces_from_node",
300
- rxml_xpath_context_register_namespaces_from_node, 1);
301
- rb_define_method(cXMLXPathContext, "register_namespace",
302
- rxml_xpath_context_register_namespace, 2);
346
+ rb_define_method(cXMLXPathContext, "initialize", rxml_xpath_context_initialize, 1);
347
+ rb_define_method(cXMLXPathContext, "register_namespaces", rxml_xpath_context_register_namespaces, 1);
348
+ rb_define_method(cXMLXPathContext, "register_namespaces_from_node", rxml_xpath_context_register_namespaces_from_node, 1);
349
+ rb_define_method(cXMLXPathContext, "register_namespace", rxml_xpath_context_register_namespace, 2);
303
350
  rb_define_method(cXMLXPathContext, "node=", rxml_xpath_context_node_set, 1);
304
351
  rb_define_method(cXMLXPathContext, "find", rxml_xpath_context_find, 1);
352
+ rb_define_method(cXMLXPathContext, "enable_cache", rxml_xpath_context_enable_cache, -1);
353
+ rb_define_method(cXMLXPathContext, "disable_cache", rxml_xpath_context_disable_cache, 0);
305
354
  }