libxml-ruby 0.7.0-x86-mswin32-60 → 0.8.0-x86-mswin32-60

Sign up to get free protection for your applications and to get access to all the features.
Files changed (188) hide show
  1. data/CHANGES +24 -1
  2. data/README +48 -3
  3. data/benchmark/depixelate.rb +632 -0
  4. data/benchmark/hamlet.xml +9055 -0
  5. data/benchmark/sock_entries.xml +507 -0
  6. data/benchmark/throughput.rb +39 -0
  7. data/benchmark/xml_benchmarks.rb +222 -0
  8. data/doc/classes/LibXML.html +237 -0
  9. data/doc/classes/LibXML/XML.html +178 -0
  10. data/doc/classes/{XML → LibXML/XML}/Attr.html +213 -182
  11. data/doc/classes/{XML → LibXML/XML}/Attributes.html +126 -54
  12. data/doc/classes/{XML → LibXML/XML}/Document.html +299 -297
  13. data/doc/classes/{XML → LibXML/XML}/Dtd.html +10 -10
  14. data/doc/classes/{XML/XInclude → LibXML/XML}/Error.html +4 -4
  15. data/doc/classes/{XML → LibXML/XML}/HTMLParser.html +40 -40
  16. data/doc/classes/{XML → LibXML/XML}/InputCallbacks.html +10 -10
  17. data/doc/classes/{XML → LibXML/XML}/NS.html +46 -46
  18. data/doc/classes/{XML → LibXML/XML}/Node.html +935 -788
  19. data/doc/classes/LibXML/XML/Node/FailedModify.html +111 -0
  20. data/doc/classes/{XML → LibXML/XML}/Node/Set.html +69 -68
  21. data/doc/classes/{XML → LibXML/XML}/Node/SetNamespace.html +4 -4
  22. data/doc/classes/{XML/Node/FailedModify.html → LibXML/XML/Node/UnknownType.html} +4 -4
  23. data/doc/classes/{XML → LibXML/XML}/Parser.html +426 -389
  24. data/doc/classes/{XML → LibXML/XML}/Parser/Context.html +208 -208
  25. data/doc/classes/{XML → LibXML/XML}/Parser/ParseError.html +4 -4
  26. data/doc/classes/{XML → LibXML/XML}/Reader.html +288 -287
  27. data/doc/classes/{XML → LibXML/XML}/SaxParser.html +52 -52
  28. data/doc/classes/{XML/XPath/Context.html → LibXML/XML/Schema.html} +60 -32
  29. data/doc/classes/{XML → LibXML/XML}/State.html +4 -4
  30. data/doc/classes/{XML/Node/UnknownType.html → LibXML/XML/Tree.html} +5 -5
  31. data/doc/classes/{XML → LibXML/XML}/XInclude.html +5 -5
  32. data/doc/classes/{XML → LibXML/XML/XInclude}/Error.html +5 -5
  33. data/doc/classes/{XML → LibXML/XML}/XMLParserOptions.html +5 -5
  34. data/doc/classes/{XML → LibXML/XML}/XPath.html +23 -64
  35. data/doc/classes/LibXML/XML/XPath/Context.html +403 -0
  36. data/doc/classes/{XML/XPointer/Context → LibXML/XML/XPath}/InvalidPath.html +4 -4
  37. data/doc/classes/LibXML/XML/XPath/Object.html +623 -0
  38. data/doc/classes/{XML → LibXML/XML}/XPointer.html +12 -12
  39. data/doc/classes/{XML → LibXML/XML}/XPointer/Context.html +5 -5
  40. data/doc/classes/{XML/XPath → LibXML/XML/XPointer/Context}/InvalidPath.html +5 -5
  41. data/doc/classes/{XML → LibXML/XML}/XPointer/InvalidExpression.html +4 -4
  42. data/doc/classes/XML.html +17 -123
  43. data/doc/created.rid +1 -1
  44. data/doc/files/CHANGES.html +49 -25
  45. data/doc/files/LICENSE.html +1 -1
  46. data/doc/files/README.html +79 -4
  47. data/doc/files/VERSION.html +2 -2
  48. data/doc/files/ext/libxml/cbg_c.html +1 -1
  49. data/doc/files/ext/libxml/libxml_c.html +1 -1
  50. data/doc/files/ext/libxml/ruby_xml_attr_c.html +1 -1
  51. data/doc/files/ext/libxml/ruby_xml_attributes_c.html +1 -1
  52. data/doc/files/ext/libxml/ruby_xml_document_c.html +1 -1
  53. data/doc/files/ext/libxml/ruby_xml_dtd_c.html +1 -1
  54. data/doc/files/ext/libxml/ruby_xml_html_parser_c.html +1 -1
  55. data/doc/files/ext/libxml/ruby_xml_input_cbg_c.html +1 -1
  56. data/doc/files/ext/libxml/ruby_xml_node_c.html +1 -1
  57. data/doc/files/ext/libxml/ruby_xml_node_set_c.html +1 -1
  58. data/doc/files/ext/libxml/ruby_xml_ns_c.html +1 -1
  59. data/doc/files/ext/libxml/ruby_xml_parser_c.html +1 -1
  60. data/doc/files/ext/libxml/ruby_xml_parser_context_c.html +1 -1
  61. data/doc/files/ext/libxml/ruby_xml_reader_c.html +1 -1
  62. data/doc/files/ext/libxml/ruby_xml_sax_parser_c.html +1 -1
  63. data/doc/files/ext/libxml/ruby_xml_schema_c.html +1 -1
  64. data/doc/files/ext/libxml/ruby_xml_state_c.html +1 -1
  65. data/doc/files/ext/libxml/ruby_xml_xinclude_c.html +1 -1
  66. data/doc/files/ext/libxml/ruby_xml_xpath_c.html +1 -1
  67. data/doc/files/ext/libxml/ruby_xml_xpath_context_c.html +1 -1
  68. data/doc/files/ext/libxml/ruby_xml_xpath_object_c.html +1 -1
  69. data/doc/files/ext/libxml/ruby_xml_xpointer_c.html +1 -1
  70. data/doc/files/ext/libxml/ruby_xml_xpointer_context_c.html +1 -1
  71. data/doc/files/lib/libxml/attr_rb.html +108 -0
  72. data/doc/files/lib/libxml/attributes_rb.html +108 -0
  73. data/doc/files/lib/libxml/document_rb.html +108 -0
  74. data/doc/files/lib/libxml/node_rb.html +108 -0
  75. data/doc/files/lib/libxml/node_set_rb.html +108 -0
  76. data/doc/files/lib/libxml/parser_options_rb.html +107 -0
  77. data/doc/files/{ext/libxml/ruby_xml_tree_c.html → lib/libxml/parser_rb.html} +4 -4
  78. data/doc/files/lib/libxml/properties_rb.html +108 -0
  79. data/doc/files/lib/libxml/tree_rb.html +107 -0
  80. data/doc/files/lib/libxml_rb.html +12 -3
  81. data/doc/fr_class_index.html +34 -32
  82. data/doc/fr_file_index.html +9 -1
  83. data/doc/fr_method_index.html +362 -347
  84. data/ext/libxml/cbg.c +76 -76
  85. data/ext/libxml/libxml.c +4 -3
  86. data/ext/libxml/ruby_libxml.h +1 -1
  87. data/ext/libxml/ruby_xml_attr.c +4 -3
  88. data/ext/libxml/ruby_xml_attr.h +16 -16
  89. data/ext/libxml/ruby_xml_attributes.c +267 -266
  90. data/ext/libxml/ruby_xml_attributes.h +17 -17
  91. data/ext/libxml/ruby_xml_document.c +30 -59
  92. data/ext/libxml/ruby_xml_document.h +27 -27
  93. data/ext/libxml/ruby_xml_dtd.c +2 -1
  94. data/ext/libxml/ruby_xml_dtd.h +17 -17
  95. data/ext/libxml/ruby_xml_html_parser.c +3 -2
  96. data/ext/libxml/ruby_xml_html_parser.h +29 -29
  97. data/ext/libxml/ruby_xml_input_cbg.c +2 -1
  98. data/ext/libxml/ruby_xml_input_cbg.h +20 -20
  99. data/ext/libxml/ruby_xml_node.c +127 -470
  100. data/ext/libxml/ruby_xml_node.h +17 -17
  101. data/ext/libxml/ruby_xml_node_set.c +5 -4
  102. data/ext/libxml/ruby_xml_node_set.h +20 -20
  103. data/ext/libxml/ruby_xml_ns.c +3 -2
  104. data/ext/libxml/ruby_xml_ns.h +12 -12
  105. data/ext/libxml/ruby_xml_parser.c +20 -48
  106. data/ext/libxml/ruby_xml_parser.h +31 -31
  107. data/ext/libxml/ruby_xml_parser_context.c +3 -2
  108. data/ext/libxml/ruby_xml_parser_context.h +20 -20
  109. data/ext/libxml/ruby_xml_reader.c +2 -1
  110. data/ext/libxml/ruby_xml_sax_parser.c +3 -2
  111. data/ext/libxml/ruby_xml_sax_parser.h +56 -56
  112. data/ext/libxml/ruby_xml_schema.c +6 -0
  113. data/ext/libxml/ruby_xml_schema.h +16 -16
  114. data/ext/libxml/ruby_xml_state.c +13 -12
  115. data/ext/libxml/ruby_xml_state.h +1 -1
  116. data/ext/libxml/ruby_xml_xinclude.c +3 -2
  117. data/ext/libxml/ruby_xml_xinclude.h +13 -13
  118. data/ext/libxml/ruby_xml_xpath.c +35 -228
  119. data/ext/libxml/ruby_xml_xpath.h +22 -23
  120. data/ext/libxml/ruby_xml_xpath_context.c +223 -62
  121. data/ext/libxml/ruby_xml_xpath_context.h +15 -20
  122. data/ext/libxml/ruby_xml_xpath_object.c +63 -19
  123. data/ext/libxml/ruby_xml_xpointer.c +19 -15
  124. data/ext/libxml/ruby_xml_xpointer.h +27 -27
  125. data/ext/libxml/ruby_xml_xpointer_context.c +3 -2
  126. data/ext/libxml/ruby_xml_xpointer_context.h +18 -18
  127. data/ext/libxml/version.h +9 -9
  128. data/lib/libxml.rb +16 -128
  129. data/lib/libxml/attr.rb +45 -0
  130. data/lib/libxml/attributes.rb +15 -0
  131. data/lib/libxml/document.rb +54 -0
  132. data/lib/libxml/node.rb +132 -0
  133. data/lib/libxml/node_set.rb +27 -0
  134. data/lib/libxml/parser.rb +42 -0
  135. data/lib/libxml/parser_options.rb +25 -0
  136. data/lib/libxml/properties.rb +19 -0
  137. data/lib/libxml/tree.rb +29 -0
  138. data/lib/libxml_ruby.so +0 -0
  139. data/mingw/libxml_ruby.so +0 -0
  140. data/{work/task/setup → setup.rb} +1585 -1616
  141. data/test/gc.log +0 -0
  142. data/test/model/books.xml +147 -0
  143. data/{work/test/runner.rb → test/model/default_validation_bug.rb} +0 -0
  144. data/test/model/merge_bug_data.xml +58 -0
  145. data/test/model/rubynet.xml +78 -0
  146. data/test/model/rubynet_project +1 -0
  147. data/test/model/saxtest.xml +5 -0
  148. data/test/model/shiporder.xml +23 -0
  149. data/test/model/shiporder.xsd +31 -0
  150. data/test/model/simple.xml +7 -0
  151. data/test/model/soap.xml +27 -0
  152. data/test/model/xinclude.xml +5 -0
  153. data/test/tc_deprecated_require.rb +13 -0
  154. data/test/tc_xml_document.rb +57 -16
  155. data/test/tc_xml_document_write.rb +125 -10
  156. data/test/tc_xml_dtd.rb +22 -1
  157. data/test/tc_xml_node.rb +13 -0
  158. data/test/tc_xml_node_edit.rb +1 -1
  159. data/test/tc_xml_node_xlink.rb +1 -1
  160. data/test/tc_xml_parser.rb +64 -7
  161. data/test/tc_xml_properties.rb +42 -0
  162. data/test/tc_xml_reader.rb +4 -4
  163. data/test/tc_xml_sax_parser.rb +50 -50
  164. data/test/tc_xml_schema.rb +2 -2
  165. data/test/tc_xml_traversal.rb +220 -0
  166. data/test/tc_xml_xinclude.rb +12 -15
  167. data/test/tc_xml_xpath.rb +74 -6
  168. data/test/tc_xml_xpath_context.rb +72 -0
  169. data/test/test_suite.rb +6 -4
  170. data/vc/libxml_ruby.vcproj +1 -9
  171. metadata +92 -65
  172. data/doc/classes/XML/SiblingEnum.html +0 -142
  173. data/doc/classes/XML/Tree.html +0 -224
  174. data/doc/classes/XML/XPath/Object.html +0 -439
  175. data/ext/libxml/ruby_xml_tree.c +0 -43
  176. data/ext/libxml/ruby_xml_tree.h +0 -12
  177. data/test/ets_copy_bug2.rb +0 -21
  178. data/test/tc_xml_document_write2.rb +0 -54
  179. data/test/tc_xml_document_write3.rb +0 -96
  180. data/test/tc_xml_sax_parser2.rb +0 -51
  181. data/work/Rakefile +0 -247
  182. data/work/task/make +0 -26
  183. data/work/task/memory +0 -37
  184. data/work/task/rdoc +0 -39
  185. data/work/task/test +0 -29
  186. data/work/test/ets_runner.rb +0 -33
  187. data/work/test/libxml_test.rb +0 -3
  188. data/work/test/runner_ets.rb +0 -33
@@ -3,6 +3,12 @@
3
3
 
4
4
  VALUE cXMLSchema;
5
5
 
6
+ // Rdoc needs to know
7
+ #ifdef RDOC_NEVER_DEFINED
8
+ mLibXML = rb_define_module("LibXML");
9
+ mXML = rb_define_module_under(mLibXML, "XML");
10
+ #endif
11
+
6
12
  static void
7
13
  ruby_xml_schema_mark(ruby_xml_schema *rxschema) {
8
14
  return;
@@ -1,16 +1,16 @@
1
- #ifndef __RUBY_XML_SCHEMA__
2
- #define __RUBY_XML_SCHEMA__
3
-
4
- #include <libxml/schemasInternals.h>
5
- #include <libxml/xmlschemas.h>
6
-
7
- extern VALUE cXMLSchema;
8
-
9
- typedef struct rxp_schema {
10
- xmlSchemaPtr schema; /* Schema interface */
11
- } ruby_xml_schema;
12
-
13
- void ruby_init_xml_schema(void);
14
- void ruby_schema_free(ruby_xml_schema *rxs);
15
- #endif
16
-
1
+ #ifndef __RUBY_XML_SCHEMA__
2
+ #define __RUBY_XML_SCHEMA__
3
+
4
+ #include <libxml/schemasInternals.h>
5
+ #include <libxml/xmlschemas.h>
6
+
7
+ extern VALUE cXMLSchema;
8
+
9
+ typedef struct rxp_schema {
10
+ xmlSchemaPtr schema; /* Schema interface */
11
+ } ruby_xml_schema;
12
+
13
+ void ruby_init_xml_schema(void);
14
+ void ruby_schema_free(ruby_xml_schema *rxs);
15
+ #endif
16
+
@@ -14,21 +14,22 @@ ruby_xml_state_free(int dummy) {
14
14
  }
15
15
 
16
16
  VALUE
17
- ruby_xml_state_alloc() {
17
+ ruby_xml_state_alloc(VALUE klass) {
18
18
  #ifdef DEBUG
19
19
  fprintf(stderr, "Allocating state");
20
20
  #endif
21
21
 
22
- xmlInitParser();
22
+ xmlInitParser();
23
23
 
24
24
  return Data_Wrap_Struct(cXMLState,
25
25
  NULL, ruby_xml_state_free,
26
26
  &dummy);
27
27
  }
28
28
 
29
- // Rdoc needs to know
29
+ // Rdoc needs to know
30
30
  #ifdef RDOC_NEVER_DEFINED
31
- mXML = rb_define_module("XML");
31
+ mLibXML = rb_define_module("LibXML");
32
+ mXML = rb_define_module_under(mLibXML, "XML");
32
33
  #endif
33
34
 
34
35
  void
@@ -37,16 +38,16 @@ ruby_init_state(void) {
37
38
  cXMLState = rb_define_class_under(mXML, "State", rb_cObject);
38
39
 
39
40
  /* Mixin singleton so only one xml state object can be created. */
40
- rb_require("singleton");
41
- rb_mSingleton = rb_const_get(rb_cObject, rb_intern("Singleton"));
42
- rb_include_module(cXMLState, rb_mSingleton);
43
-
44
- rb_define_alloc_func(cXMLState, ruby_xml_state_alloc);
45
-
41
+ rb_require("singleton");
42
+ rb_mSingleton = rb_const_get(rb_cObject, rb_intern("Singleton"));
43
+ rb_include_module(cXMLState, rb_mSingleton);
44
+
45
+ rb_define_alloc_func(cXMLState, ruby_xml_state_alloc);
46
+
46
47
  /* Create one instance of the state object that is used
47
48
  to initalize and cleanup libxml. Then register it with
48
49
  the garbage collector so its not freed until the process
49
50
  exists.*/
50
- LIBXML_STATE = rb_class_new_instance(0, NULL, cXMLState);
51
- rb_global_variable(&LIBXML_STATE);
51
+ LIBXML_STATE = rb_class_new_instance(0, NULL, cXMLState);
52
+ rb_global_variable(&LIBXML_STATE);
52
53
  }
@@ -6,6 +6,6 @@
6
6
  extern VALUE cXMLState;
7
7
  extern VALUE LIBXML_STATE;
8
8
 
9
- void ruby_init_state(void);
9
+ void ruby_init_state(void);
10
10
 
11
11
  #endif
@@ -1,4 +1,4 @@
1
- /* $Id: ruby_xml_xinclude.c 300 2008-07-01 19:14:15Z cfis $ */
1
+ /* $Id: ruby_xml_xinclude.c 461 2008-07-15 21:35:56Z cfis $ */
2
2
 
3
3
  /* Please see the LICENSE file for copyright and distribution information */
4
4
 
@@ -10,7 +10,8 @@ VALUE eXMLXIncludeError;
10
10
 
11
11
  // Rdoc needs to know
12
12
  #ifdef RDOC_NEVER_DEFINED
13
- mXML = rb_define_module("XML");
13
+ mLibXML = rb_define_module("LibXML");
14
+ mXML = rb_define_module_under(mLibXML, "XML");
14
15
  #endif
15
16
 
16
17
  void
@@ -1,13 +1,13 @@
1
- /* $Id: ruby_xml_xinclude.h 39 2006-02-21 20:40:16Z roscopeco $ */
2
-
3
- /* Please see the LICENSE file for copyright and distribution information */
4
-
5
- #ifndef __RUBY_XML_XINCLUDE__
6
- #define __RUBY_XML_XINCLUDE__
7
-
8
- extern VALUE cXMLXInclude;
9
- extern VALUE eXMLXIncludeError;
10
-
11
- void ruby_init_xml_xinclude(void);
12
-
13
- #endif
1
+ /* $Id: ruby_xml_xinclude.h 39 2006-02-21 20:40:16Z roscopeco $ */
2
+
3
+ /* Please see the LICENSE file for copyright and distribution information */
4
+
5
+ #ifndef __RUBY_XML_XINCLUDE__
6
+ #define __RUBY_XML_XINCLUDE__
7
+
8
+ extern VALUE cXMLXInclude;
9
+ extern VALUE eXMLXIncludeError;
10
+
11
+ void ruby_init_xml_xinclude(void);
12
+
13
+ #endif
@@ -1,19 +1,32 @@
1
- /* $Id: ruby_xml_xpath.c 351 2008-07-09 19:55:21Z cfis $ */
1
+ /* $Id: ruby_xml_xpath.c 461 2008-07-15 21:35:56Z cfis $ */
2
2
 
3
3
  /* Please see the LICENSE file for copyright and distribution information */
4
4
 
5
5
  #include "ruby_libxml.h"
6
6
  #include "ruby_xml_xpath.h"
7
+ #include "ruby_xml_xpath_context.h"
7
8
 
8
9
  /*
9
- * Document-class: XML::XPath
10
+ * Document-class: LibXML::XML::XPath
10
11
  *
11
- * The XML::XPath class is used to query XML documents. It is used
12
- * via the XML::Document#find method.
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')
13
26
  *
14
- * document.find('/foo')
15
27
  *
16
28
  * === Working With Namespaces
29
+ *
17
30
  * Finding namespaced elements and attributes can be tricky.
18
31
  * Lets work through some examples using the following xml document:
19
32
  *
@@ -33,7 +46,7 @@
33
46
  * # Since the ns1 namespace is not defined on the root node
34
47
  * # we have to first register it with the xpath engine.
35
48
  * doc.find('//ns1:IdAndName',
36
- 'ns1:http://domain.somewhere.com')
49
+ * 'ns1:http://domain.somewhere.com')
37
50
  *
38
51
  * # Since the getManufacturerNamesResponse element uses a default
39
52
  * # namespace we first have to give it a prefix and register
@@ -47,236 +60,30 @@
47
60
  ['ns0:http://services.somewhere.com', 'ns1:http://domain.somewhere.com'])
48
61
  */
49
62
 
50
- VALUE cXMLXPath;
63
+ VALUE mXPath;
51
64
  VALUE eXMLXPathInvalidPath;
52
65
 
53
- #ifdef LIBXML_XPATH_ENABLED
54
-
55
-
56
- /*
57
- * call-seq:
58
- * xpath.debug -> (true|false)
59
- *
60
- * Dump libxml debugging information to stdout.
61
- * Requires Libxml be compiled with debugging enabled.
62
- */
63
- VALUE
64
- ruby_xml_xpath_debug(VALUE self) {
65
- #ifdef LIBXML_DEBUG_ENABLED
66
- ruby_xml_xpath *rxxp;
67
- Data_Get_Struct(self, ruby_xml_xpath, rxxp);
68
-
69
- if (rxxp->xpop != NULL) {
70
- xmlXPathDebugDumpObject(stdout, rxxp->xpop, 0);
71
- return(Qtrue);
72
- } else {
73
- return(Qfalse);
74
- }
75
- #else
76
- rb_warn("libxml does not have debugging turned on");
77
- return(Qfalse);
78
- #endif
79
- }
80
-
81
- ///////////////////////////////////////////////////
82
- // TODO xpath_find is throwing TypeError:
83
- //
84
- // TypeError: can't convert nil into String
85
- //
86
- // When given a namespace when non exist.
87
- void
88
- ruby_xml_xpath_register_namespaces(VALUE nslist, VALUE xxpc, int level) {
89
- char *cp;
90
- long i;
91
- VALUE rprefix, ruri;
92
- xmlNsPtr xns;
93
-
94
- /* Need to loop through the 2nd argument and iterate through the
95
- * list of namespaces that we want to allow */
96
- switch (TYPE(nslist)) {
97
- case T_STRING:
98
- cp = strchr(StringValuePtr(nslist), (int)':');
99
- if (cp == NULL) {
100
- rprefix = nslist;
101
- ruri = Qnil;
102
- } else {
103
- rprefix = rb_str_new(StringValuePtr(nslist), (int)((long)cp - (long)StringValuePtr(nslist)));
104
- ruri = rb_str_new2(&cp[1]);
105
- }
106
- /* Should test the results of this */
107
- ruby_xml_xpath_context_register_namespace(xxpc, rprefix, ruri);
108
- break;
109
- case T_ARRAY:
110
- if ( level == 0 ) {
111
- for (i = 0; i < RARRAY(nslist)->len; i++) {
112
- ruby_xml_xpath_register_namespaces(RARRAY(nslist)->ptr[i],xxpc,1);
113
- }
114
- }
115
- else {
116
- // tuples of prefix/uri
117
- if (RARRAY(nslist)->len == 2) {
118
- rprefix = RARRAY(nslist)->ptr[0];
119
- ruri = RARRAY(nslist)->ptr[1];
120
- ruby_xml_xpath_context_register_namespace(xxpc, rprefix, ruri);
121
- } else {
122
- rb_raise(rb_eArgError, "nested array must be an array of strings, prefix and href/uri");
123
- }
124
- }
125
- break;
126
- default:
127
- if (rb_obj_is_kind_of(nslist, cXMLNS) == Qtrue) {
128
- Data_Get_Struct(nslist, xmlNs, xns);
129
- rprefix = rb_str_new2((const char*)xns->prefix);
130
- ruri = rb_str_new2((const char*)xns->href);
131
- ruby_xml_xpath_context_register_namespace(xxpc, rprefix, ruri);
132
- } else
133
- rb_raise(rb_eArgError, "Invalid argument type, only accept string, array of strings, or an array of arrays");
134
- }
135
- }
136
- /*
137
- * call-seq:
138
- * XML::XPath.find(path, namespaces = [any]) -> xpath
139
- *
140
- * Find nodes matching the specified xpath (and optionally any of the
141
- * supplied namespaces) and return as an XML::Node::Set.
142
- *
143
- * The optional namespaces argument may take one of
144
- * two forms:
145
- *
146
- * * A string in the form of: "prefix:uri", or
147
- * * An array of:
148
- * * strings in the form like above
149
- * * arrays in the form of ['prefix','uri']
150
- *
151
- * If not specified, matching nodes from any namespace
152
- * will be included.
153
- */
154
- VALUE
155
- ruby_xml_xpath_find(VALUE class, VALUE anode, VALUE xpath_expr, VALUE nslist) {
156
- #ifdef LIBXML_XPATH_ENABLED
157
- xmlXPathCompExprPtr comp;
158
- xmlXPathObjectPtr xxpop;
159
- xmlNodePtr xnode;
160
- xmlXPathContextPtr ctxt;
161
- ruby_xml_document_t *rdocp;
162
- VALUE rnode, xxpc;
163
- VALUE rxpop;
164
-
165
- if (rb_obj_is_kind_of(anode, cXMLDocument) == Qtrue) {
166
- xxpc = ruby_xml_xpath_context_new(anode);
167
- Data_Get_Struct(anode, ruby_xml_document_t, rdocp);
168
- #ifdef DEBUG
169
- fprintf(stderr,"rdocp=0x%x root=0x%x\n",rdocp,xmlDocGetRootElement(rdocp->doc));
170
- #endif
171
- rnode=ruby_xml_node2_wrap(cXMLNode,xmlDocGetRootElement(rdocp->doc));
172
- #ifdef DEBUG
173
- fprintf(stderr,"rnode 0x%x 0x%x\n",rnode,xmlDocGetRootElement(rdocp->doc)->_private);
174
- #endif
175
- Data_Get_Struct(rnode, xmlNode, xnode);
176
- } else if ( rb_obj_is_kind_of(anode, cXMLNode) == Qtrue) {
177
- xxpc = ruby_xml_xpath_context_new(anode);
178
- Data_Get_Struct(anode, xmlNode, xnode);
179
- } else
180
- rb_raise(rb_eTypeError, "arg 1 must be XML::Document or XML::Node within a document %s", rb_obj_as_string(anode));
181
-
182
- if (NIL_P(xxpc))
183
- return(Qnil);
184
-
185
- Data_Get_Struct(xxpc,xmlXPathContext,ctxt);
186
- // XXX Is this legal? Set a subtree to apply xpath?
187
- ctxt->node = xnode;
188
-
189
- // XXX is setting ->namespaces used?
190
- if (xnode->type == XML_DOCUMENT_NODE) {
191
- ctxt->namespaces = xmlGetNsList(xnode->doc,
192
- xmlDocGetRootElement(xnode->doc));
193
- } else {
194
- ctxt->namespaces = xmlGetNsList(xnode->doc, xnode);
195
- }
196
-
197
- ctxt->nsNr = 0;
198
- if (ctxt->namespaces != NULL) {
199
- while (ctxt->namespaces[ctxt->nsNr] != NULL)
200
- ctxt->nsNr++;
201
- }
202
-
203
- if ( ! NIL_P(nslist) )
204
- ruby_xml_xpath_register_namespaces(nslist,xxpc,0);
205
-
206
- comp = xmlXPathCompile((xmlChar*)StringValuePtr(xpath_expr));
207
-
208
- if (comp == NULL) {
209
- rb_raise(eXMLXPathInvalidPath,
210
- "Invalid XPath expression (expr does not compile)");
211
- }
212
- xxpop=xmlXPathCompiledEval(comp, ctxt);
213
- if ( xxpop == NULL )
214
- rb_raise(eXMLXPathInvalidPath,
215
- "Invalid XPath expression (expr could not be evaluated)");
216
-
217
- rxpop = ruby_xml_xpath_object_wrap(xxpop);
218
-
219
- #ifdef NODE_DEBUG
220
- fprintf(stderr,"xpo 0x%x class=%s\n",
221
- rxpop,
222
- rb_class2name(rb_obj_class(rxpop)));
223
- #endif
224
-
225
- xmlXPathFreeCompExpr(comp);
226
-
227
- if (rxpop == Qnil)
228
- rb_raise(eXMLXPathInvalidPath,
229
- "Invalid XPath expression for this document");
230
-
231
- return rxpop;
232
- #else
233
- rb_warn("libxml was compiled without XPath support");
234
- return(Qfalse);
235
- #endif
236
- }
237
-
238
-
239
- VALUE
240
- ruby_xml_xpath_findva(int argc, VALUE *argv, VALUE class) {
241
- if ( argc < 2 || argc > 3 )
242
- rb_raise(rb_eArgError, "wrong number of arguments (1 or 2)");
243
-
244
- return ruby_xml_xpath_find(class,argv[0],argv[1],(argc==3)?argv[2]:Qnil);
245
- }
246
-
247
- VALUE
248
- ruby_xml_xpath_find2(VALUE anode, VALUE xpath_expr, VALUE nslist) {
249
- return ruby_xml_xpath_find(cXMLXPath, anode, xpath_expr, nslist);
250
- }
251
-
252
66
  // Rdoc needs to know
253
67
  #ifdef RDOC_NEVER_DEFINED
254
- mXML = rb_define_module("XML");
68
+ mLibXML = rb_define_module("LibXML");
69
+ mXML = rb_define_module_under(mLibXML, "XML");
255
70
  #endif
256
71
 
257
72
  void
258
73
  ruby_init_xml_xpath(void) {
259
- cXMLXPath = rb_define_class_under(mXML, "XPath", rb_cObject);
260
- rb_include_module(cXMLNode, rb_const_get(rb_cObject, rb_intern("Enumerable")));
261
-
262
- eXMLXPathInvalidPath = rb_define_class_under(cXMLXPath, "InvalidPath", eXMLError);
263
-
264
- rb_define_const(cXMLXPath, "UNDEFINED", INT2NUM(XPATH_UNDEFINED));
265
- rb_define_const(cXMLXPath, "NODESET", INT2NUM(XPATH_NODESET));
266
- rb_define_const(cXMLXPath, "BOOLEAN", INT2NUM(XPATH_BOOLEAN));
267
- rb_define_const(cXMLXPath, "NUMBER", INT2NUM(XPATH_NUMBER));
268
- rb_define_const(cXMLXPath, "STRING", INT2NUM(XPATH_STRING));
269
- rb_define_const(cXMLXPath, "POINT", INT2NUM(XPATH_POINT));
270
- rb_define_const(cXMLXPath, "RANGE", INT2NUM(XPATH_RANGE));
271
- rb_define_const(cXMLXPath, "LOCATIONSET", INT2NUM(XPATH_LOCATIONSET));
272
- rb_define_const(cXMLXPath, "USERS", INT2NUM(XPATH_USERS));
273
- rb_define_const(cXMLXPath, "XSLT_TREE", INT2NUM(XPATH_XSLT_TREE));
274
-
275
- rb_define_singleton_method(cXMLXPath, "find", ruby_xml_xpath_findva, -1);
276
-
277
- rb_define_method(cXMLXPath, "debug", ruby_xml_xpath_debug, 0);
74
+ mXPath = rb_define_module_under(mXML, "XPath");
75
+ eXMLXPathInvalidPath = rb_define_class_under(mXPath, "InvalidPath", eXMLError);
76
+
77
+ rb_define_const(mXPath, "UNDEFINED", INT2NUM(XPATH_UNDEFINED));
78
+ rb_define_const(mXPath, "NODESET", INT2NUM(XPATH_NODESET));
79
+ rb_define_const(mXPath, "BOOLEAN", INT2NUM(XPATH_BOOLEAN));
80
+ rb_define_const(mXPath, "NUMBER", INT2NUM(XPATH_NUMBER));
81
+ rb_define_const(mXPath, "STRING", INT2NUM(XPATH_STRING));
82
+ rb_define_const(mXPath, "POINT", INT2NUM(XPATH_POINT));
83
+ rb_define_const(mXPath, "RANGE", INT2NUM(XPATH_RANGE));
84
+ rb_define_const(mXPath, "LOCATIONSET", INT2NUM(XPATH_LOCATIONSET));
85
+ rb_define_const(mXPath, "USERS", INT2NUM(XPATH_USERS));
86
+ rb_define_const(mXPath, "XSLT_TREE", INT2NUM(XPATH_XSLT_TREE));
278
87
 
279
88
  ruby_init_xml_xpath_object();
280
89
  }
281
-
282
- #endif /* ifdef LIBXML_XPATH_ENABLED */