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
@@ -1,23 +1,22 @@
1
- /* $Id: ruby_xml_xpath.h 207 2007-11-14 07:51:46Z danj $ */
2
-
3
- /* Please see the LICENSE file for copyright and distribution information */
4
-
5
- #ifndef __RUBY_XML_XPATH__
6
- #define __RUBY_XML_XPATH__
7
-
8
- extern VALUE cXMLXPath;
9
- extern VALUE eXMLXPathInvalidPath;
10
-
11
- typedef struct ruby_xml_xpath {
12
- VALUE xd;
13
- VALUE ctxt;
14
- xmlXPathObjectPtr xpop;
15
- } ruby_xml_xpath;
16
-
17
- void ruby_xml_xpath_free(ruby_xml_xpath *rxxp);
18
- VALUE ruby_xml_xpath_find(VALUE class, VALUE anode, VALUE xpath_expr, VALUE nslist);
19
- VALUE ruby_xml_xpath_find2(VALUE anode, VALUE xpath_expr, VALUE nslist);
20
-
21
- void ruby_init_xml_xpath(void);
22
-
23
- #endif
1
+ /* $Id: ruby_xml_xpath.h 418 2008-07-14 16:44:59Z cfis $ */
2
+
3
+ /* Please see the LICENSE file for copyright and distribution information */
4
+
5
+ #ifndef __RUBY_XML_XPATH__
6
+ #define __RUBY_XML_XPATH__
7
+
8
+ extern VALUE mXPath;
9
+ extern VALUE eXMLXPathInvalidPath;
10
+
11
+ typedef struct ruby_xml_xpath {
12
+ VALUE xd;
13
+ VALUE ctxt;
14
+ xmlXPathObjectPtr xpop;
15
+ } ruby_xml_xpath;
16
+
17
+ void ruby_xml_xpath_free(ruby_xml_xpath *rxxp);
18
+ VALUE ruby_xml_xpath_find(VALUE class, VALUE anode, VALUE xpath_expr, VALUE nslist);
19
+
20
+ void ruby_init_xml_xpath(void);
21
+
22
+ #endif
@@ -1,92 +1,94 @@
1
- /* $Id: ruby_xml_xpath_context.c 351 2008-07-09 19:55:21Z cfis $ */
1
+ /* $Id: ruby_xml_xpath_context.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_context.h"
7
+ #include <st.h>
7
8
 
8
- VALUE cXMLXPathContext;
9
9
 
10
10
  /*
11
- * call-seq:
12
- * context.doc -> document
11
+ * Document-class: LibXML::XML::XPath::Context
13
12
  *
14
- * Obtain the XML::Document associated with this XPath.
13
+ * The XML::XPath::Context class is used to evaluate XPath
14
+ * expressions. Generally, you should not directly use this class,
15
+ * but instead use the XML::Document#find and XML::Node#find methods.
16
+ *
17
+ * doc = XML::Document.string('<header>content</header>')
18
+ * context = XPath::Context.new(doc)
19
+ * context.node = doc.root
20
+ * context.register_namespaces_from_node(doc.root)
21
+ * nodes = context.find('/header')
15
22
  */
16
- VALUE
17
- ruby_xml_xpath_context_doc_get(VALUE self) {
18
- xmlXPathContextPtr ctxt;
19
- Data_Get_Struct(self, xmlXPathContext, ctxt);
20
-
21
- return ruby_xml_document_wrap(ctxt->doc);
22
- }
23
23
 
24
+ VALUE cXMLXPathContext;
24
25
 
25
26
  void
26
27
  ruby_xml_xpath_context_free(xmlXPathContextPtr ctxt) {
27
- if (ctxt != NULL) {
28
- if (ctxt->namespaces != NULL) {
29
- xmlFree(ctxt->namespaces);
30
- ctxt->namespaces = NULL;
31
- }
32
- xmlXPathFreeContext(ctxt);
33
- ctxt = NULL;
34
- }
35
- }
36
-
37
-
38
- void
39
- ruby_xml_xpath_context_mark(xmlXPathContextPtr ctxt) {
40
- if (ctxt == NULL ) return;
41
- if (ctxt->doc != NULL && ctxt->doc->_private != NULL)
42
- rb_gc_mark((VALUE)ctxt->doc->_private);
28
+ xmlXPathFreeContext(ctxt);
43
29
  }
44
30
 
45
31
 
46
32
  VALUE
47
- ruby_xml_xpath_context_wrap(xmlXPathContextPtr ctxt) {
33
+ ruby_xml_xpath_context_alloc(VALUE klass) {
48
34
  return Data_Wrap_Struct(cXMLXPathContext,
49
- ruby_xml_xpath_context_mark,
35
+ NULL,
50
36
  ruby_xml_xpath_context_free,
51
- ctxt);
37
+ NULL);
52
38
  }
53
39
 
54
-
40
+ /* call-seq:
41
+ * XPath::Context.new(node) -> XPath::Context
42
+ *
43
+ * Creates a new XPath context for the specified document. The
44
+ * context can then be used to evaluate an XPath expression.
45
+ *
46
+ * doc = XML::Document.string('<header><first>hi</first></header>')
47
+ * context = XPath::Context.new(doc)
48
+ * nodes = XPath::Object.new('//first', context)
49
+ * nodes.length == 1
50
+ */
55
51
  VALUE
56
- ruby_xml_xpath_context_new(VALUE anode) {
52
+ ruby_xml_xpath_context_initialize(VALUE self, VALUE node) {
57
53
  ruby_xml_document_t *rxd;
58
- xmlNodePtr xnode;
59
- xmlXPathContextPtr ctxt;
60
-
61
- if (rb_obj_is_kind_of(anode,cXMLDocument) == Qtrue ) {
62
- Data_Get_Struct(anode,ruby_xml_document_t,rxd);
63
- if (rxd->doc == NULL) return(Qnil);
54
+ VALUE document;
55
+ #ifndef LIBXML_XPATH_ENABLED
56
+ rb_raise(rb_eTypeError, "libxml was not compiled with XPath support.");
57
+ #endif
64
58
 
65
- ctxt = xmlXPathNewContext(rxd->doc);
66
- if (ctxt == NULL) return(Qnil);
67
-
68
- } else if (rb_obj_is_kind_of(anode,cXMLNode) == Qtrue ) {
69
- Data_Get_Struct(anode, xmlNode, xnode);
70
- if (xnode->doc == NULL)
71
- rb_raise(rb_eTypeError,"Supplied node must be part of a document");
72
-
73
- ctxt = xmlXPathNewContext(xnode->doc);
74
- if (ctxt == NULL) return(Qnil);
75
-
76
- } else {
77
- rb_raise(rb_eTypeError,"create context requires a document or node. Supplied a %s?",
78
- rb_obj_as_string(anode));
59
+ if (rb_obj_is_kind_of(node, cXMLNode) == Qtrue)
60
+ {
61
+ document = rb_funcall(node, rb_intern("doc"), 0);
62
+ if NIL_P(document)
63
+ rb_raise(rb_eTypeError, "Supplied node must belong to a document.");
64
+ }
65
+ else if (rb_obj_is_kind_of(node, cXMLDocument) == Qtrue)
66
+ {
67
+ document = node;
79
68
  }
69
+ else
70
+ {
71
+ rb_raise(rb_eTypeError, "Supplied argument must be a document or node.");
72
+ }
73
+
74
+ Data_Get_Struct(document, ruby_xml_document_t, rxd);
75
+ DATA_PTR(self) = xmlXPathNewContext(rxd->doc);
76
+
77
+ /* Save the doc as an attribute, this will expose it to Ruby's GC. */
78
+ rb_iv_set(self, "@doc", document);
80
79
 
81
- return ruby_xml_xpath_context_wrap(ctxt);
80
+ return self;
82
81
  }
83
82
 
83
+
84
84
  /*
85
85
  * call-seq:
86
86
  * context.register_namespace(prefix, uri) -> (true|false)
87
87
  *
88
88
  * Register the specified namespace URI with the specified prefix
89
89
  * in this context.
90
+
91
+ * context.register_namespace('xi', 'http://www.w3.org/2001/XInclude')
90
92
  */
91
93
  VALUE
92
94
  ruby_xml_xpath_context_register_namespace(VALUE self, VALUE prefix, VALUE uri) {
@@ -105,18 +107,177 @@ ruby_xml_xpath_context_register_namespace(VALUE self, VALUE prefix, VALUE uri) {
105
107
  }
106
108
  }
107
109
 
110
+ /* call-seq:
111
+ * context.register_namespaces_from_node(node) -> self
112
+ *
113
+ * Helper method to read in namespaces defined on a node.
114
+ *
115
+ * doc = XML::Document.string('<header><first>hi</first></header>')
116
+ * context = XPath::Context.new(doc)
117
+ * context.register_namespaces_from_node(doc.root)
118
+ */
119
+ VALUE
120
+ ruby_xml_xpath_context_register_namespaces_from_node(VALUE self, VALUE node) {
121
+ xmlXPathContextPtr xctxt;
122
+ xmlNodePtr xnode;
123
+ xmlNsPtr *xnsArr;
124
+
125
+ Data_Get_Struct(self, xmlXPathContext, xctxt);
126
+
127
+ if (rb_obj_is_kind_of(node, cXMLDocument) == Qtrue)
128
+ {
129
+ ruby_xml_document_t *rdoc;
130
+ Data_Get_Struct(node, ruby_xml_document_t, rdoc);
131
+ xnode = xmlDocGetRootElement(rdoc->doc);
132
+ }
133
+ else if (rb_obj_is_kind_of(node, cXMLNode) == Qtrue)
134
+ {
135
+ Data_Get_Struct(node, xmlNode, xnode);
136
+ }
137
+ else
138
+ {
139
+ rb_raise(rb_eTypeError, "The first argument must be a document or node.");
140
+ }
141
+
142
+ xnsArr = xmlGetNsList(xnode->doc, xnode);
143
+
144
+ if (xnsArr)
145
+ {
146
+ xmlNsPtr xns = *xnsArr;
147
+
148
+ while (xns) {
149
+ /* If there is no prefix, then this is the default namespace.
150
+ Skip it for now. */
151
+ if (xns->prefix)
152
+ {
153
+ VALUE prefix = rb_str_new2(xns->prefix);
154
+ VALUE uri = rb_str_new2(xns->href);
155
+ ruby_xml_xpath_context_register_namespace(self, prefix, uri);
156
+ }
157
+ xns = xns->next;
158
+ }
159
+ xmlFree(xnsArr);
160
+ }
161
+
162
+ return self;
163
+ }
164
+
165
+ static int
166
+ iterate_ns_hash(st_data_t prefix, st_data_t uri, st_data_t self)
167
+ {
168
+ ruby_xml_xpath_context_register_namespace(self, prefix, uri);
169
+ return ST_CONTINUE;
170
+ }
171
+
172
+
173
+ /*
174
+ * call-seq:
175
+ * context.register_namespaces(["prefix:uri"]) -> self
176
+ *
177
+ * Register the specified namespaces in this context.
178
+ *
179
+ * context.register_namespaces('xi:http://www.w3.org/2001/XInclude')
180
+ * context.register_namespaces(['xlink:http://www.w3.org/1999/xlink',
181
+ * 'xi:http://www.w3.org/2001/XInclude')
182
+ * context.register_namespaces('xlink' => 'http://www.w3.org/1999/xlink',
183
+ * 'xi' => 'http://www.w3.org/2001/XInclude')
184
+ */
185
+ VALUE
186
+ ruby_xml_xpath_context_register_namespaces(VALUE self, VALUE nslist) {
187
+ char *cp;
188
+ long i;
189
+ VALUE rprefix, ruri;
190
+
191
+ /* Need to loop through the 2nd argument and iterate through the
192
+ * list of namespaces that we want to allow */
193
+ switch (TYPE(nslist)) {
194
+ case T_STRING:
195
+ cp = strchr(StringValuePtr(nslist), (int)':');
196
+ if (cp == NULL) {
197
+ rprefix = nslist;
198
+ ruri = Qnil;
199
+ } else {
200
+ rprefix = rb_str_new(StringValuePtr(nslist), (int)((long)cp - (long)StringValuePtr(nslist)));
201
+ ruri = rb_str_new2(&cp[1]);
202
+ }
203
+ /* Should test the results of this */
204
+ ruby_xml_xpath_context_register_namespace(self, rprefix, ruri);
205
+ break;
206
+ case T_ARRAY:
207
+ for (i = 0; i < RARRAY(nslist)->len; i++) {
208
+ ruby_xml_xpath_context_register_namespaces(self, RARRAY(nslist)->ptr[i]);
209
+ }
210
+ break;
211
+ case T_HASH:
212
+ st_foreach(RHASH(nslist)->tbl, iterate_ns_hash, self);
213
+ break;
214
+ default:
215
+ rb_raise(rb_eArgError, "Invalid argument type, only accept string, array of strings, or an array of arrays");
216
+ }
217
+ return self;
218
+ }
219
+
220
+ /*
221
+ * call-seq:
222
+ * context.node = node
223
+ *
224
+ * Set the current node used by the XPath engine
225
+
226
+ * doc = XML::Document.string('<header><first>hi</first></header>')
227
+ * context.node = doc.root.first
228
+ */
229
+ VALUE
230
+ ruby_xml_xpath_context_node_set(VALUE self, VALUE node) {
231
+ xmlXPathContextPtr xctxt;
232
+ xmlNodePtr xnode;
233
+
234
+ Data_Get_Struct(self, xmlXPathContext, xctxt);
235
+ Data_Get_Struct(node, xmlNode, xnode);
236
+ xctxt->node = xnode;
237
+ return node;
238
+ }
239
+
240
+ /*
241
+ * call-seq:
242
+ * context.find("xpath") -> XML::XPath::Object
243
+ *
244
+ * Find nodes matching the specified XPath expression
245
+ */
246
+ VALUE
247
+ ruby_xml_xpath_context_find(VALUE self, VALUE xpath_expr) {
248
+ xmlXPathContextPtr xctxt;
249
+ xmlXPathObjectPtr xobject;
250
+ VALUE result;
251
+
252
+ Data_Get_Struct(self, xmlXPathContext, xctxt);
253
+ xobject = xmlXPathEval((xmlChar*)StringValuePtr(xpath_expr), xctxt);
254
+
255
+ if (xobject == NULL)
256
+ rb_raise(eXMLXPathInvalidPath,
257
+ "Invalid XPath expression (expr could not be evaluated)");
258
+
259
+ result = ruby_xml_xpath_object_wrap(xobject);
260
+ rb_iv_set(result, "@context", self);
261
+ return result;
262
+ }
263
+
264
+
108
265
  // Rdoc needs to know
109
266
  #ifdef RDOC_NEVER_DEFINED
110
- mXML = rb_define_module("XML");
111
- cXMLXPath = rb_define_class_under(mXML, "XPath", rb_cObject);
267
+ mLibXML = rb_define_module("LibXML");
268
+ mXML = rb_define_module_under(mLibXML, "XML");
269
+ mXPath = rb_define_module_under(mXML, "XPath");
112
270
  #endif
113
271
 
114
272
  void
115
273
  ruby_init_xml_xpath_context(void) {
116
- cXMLXPathContext = rb_define_class_under(cXMLXPath, "Context", rb_cObject);
117
-
118
- rb_define_method(cXMLXPathContext, "register_namespace",
119
- ruby_xml_xpath_context_register_namespace, 2);
120
- rb_define_method(cXMLXPathContext, "doc",
121
- ruby_xml_xpath_context_doc_get, 0);
274
+ cXMLXPathContext = rb_define_class_under(mXPath, "Context", rb_cObject);
275
+ rb_define_alloc_func(cXMLXPathContext, ruby_xml_xpath_context_alloc);
276
+ rb_define_method(cXMLXPathContext, "initialize", ruby_xml_xpath_context_initialize, 1);
277
+ rb_define_method(cXMLXPathContext, "register_namespaces", ruby_xml_xpath_context_register_namespaces, 1);
278
+ rb_define_method(cXMLXPathContext, "register_namespaces_from_node", ruby_xml_xpath_context_register_namespaces_from_node, 1);
279
+ rb_define_method(cXMLXPathContext, "register_namespace", ruby_xml_xpath_context_register_namespace, 2);
280
+ rb_define_method(cXMLXPathContext, "node=", ruby_xml_xpath_context_node_set, 1);
281
+ rb_define_method(cXMLXPathContext, "find", ruby_xml_xpath_context_find, 1);
282
+ rb_define_attr(cXMLXPathContext, "doc", 1, 0);
122
283
  }
@@ -1,20 +1,15 @@
1
- /* $Id: ruby_xml_xpath_context.h 207 2007-11-14 07:51:46Z danj $ */
2
-
3
- /* Please see the LICENSE file for copyright and distribution information */
4
-
5
- #ifndef __RUBY_XML_XPATH_CONTEXT__
6
- #define __RUBY_XML_XPATH_CONTEXT__
7
-
8
- extern VALUE cXMLXPathContext;
9
-
10
- typedef struct ruby_xml_xpath_context {
11
- VALUE xd;
12
- xmlXPathContextPtr ctxt;
13
- } ruby_xml_xpath_context;
14
-
15
- VALUE ruby_xml_xpath_context_wrap(xmlXPathContextPtr ctxt);
16
- VALUE ruby_xml_xpath_context_new(VALUE anode);
17
- VALUE ruby_xml_xpath_context_register_namespace(VALUE self, VALUE prefix, VALUE uri);
18
- void ruby_init_xml_xpath_context(void);
19
-
20
- #endif
1
+ /* $Id: ruby_xml_xpath_context.h 412 2008-07-14 08:02:47Z cfis $ */
2
+
3
+ /* Please see the LICENSE file for copyright and distribution information */
4
+
5
+ #ifndef __RUBY_XML_XPATH_CONTEXT__
6
+ #define __RUBY_XML_XPATH_CONTEXT__
7
+
8
+ extern VALUE cXMLXPathContext;
9
+ void ruby_init_xml_xpath_context(void);
10
+
11
+ VALUE ruby_xml_xpath_context_register_namespaces(VALUE self, VALUE nslist);
12
+ VALUE ruby_xml_xpath_context_register_namespaces_from_node(VALUE self, VALUE node);
13
+ VALUE ruby_xml_xpath_context_find(VALUE self, VALUE xpath_expr);
14
+
15
+ #endif
@@ -3,11 +3,10 @@
3
3
  #include "ruby_libxml.h"
4
4
 
5
5
  /*
6
- * Document-class: XML::XPath::Object
6
+ * Document-class: LibXML::XML::XPath::Object
7
7
  *
8
- * All XPath and XPointer evals result in this type.
9
- * nodeset should become entirely virtual and refer back to
10
- * this class/data structure.
8
+ * A collection of nodes returned from the evaluation of an XML::XPath
9
+ * or XML::XPointer expression.
11
10
  *
12
11
  */
13
12
  VALUE cXMLXPathObject;
@@ -24,7 +23,7 @@ ruby_xml_xpath_object_tabref(xmlXPathObjectPtr xpop, int apos) {
24
23
 
25
24
  switch(xpop->nodesetval->nodeTab[apos]->type) {
26
25
  case XML_ATTRIBUTE_NODE:
27
- return Qnil;//ruby_xml_attr_wrap((xmlAttrPtr)xpop->nodesetval->nodeTab[apos]);
26
+ return ruby_xml_attr_wrap((xmlAttrPtr)xpop->nodesetval->nodeTab[apos]);
28
27
  break;
29
28
  default:
30
29
  return ruby_xml_node2_wrap(cXMLNode,
@@ -232,8 +231,27 @@ ruby_xml_xpath_object_length(VALUE self) {
232
231
  return INT2NUM(xpop->nodesetval->nodeNr);
233
232
  }
234
233
 
234
+ /*
235
+ * call-seq:
236
+ * xpath_object.xpath_type -> int
237
+ *
238
+ * Returns the XPath type of the result object.
239
+ * Possible values are defined as constants
240
+ * on the XML::XPath class and include:
241
+ *
242
+ * * XML::XPath::UNDEFINED
243
+ * * XML::XPath::NODESET
244
+ * * XML::XPath::BOOLEAN
245
+ * * XML::XPath::NUMBER
246
+ * * XML::XPath::STRING
247
+ * * XML::XPath::POINT
248
+ * * XML::XPath::RANGE
249
+ * * XML::XPath::LOCATIONSET
250
+ * * XML::XPath::USERS
251
+ * * XML::XPath::XSLT_TREE
252
+ */
235
253
  VALUE
236
- ruby_xml_xpath_object_set_type(VALUE self)
254
+ ruby_xml_xpath_object_get_type(VALUE self)
237
255
  {
238
256
  xmlXPathObjectPtr xpop;
239
257
 
@@ -242,6 +260,13 @@ ruby_xml_xpath_object_set_type(VALUE self)
242
260
  return INT2FIX(xpop->type);
243
261
  }
244
262
 
263
+
264
+ /*
265
+ * call-seq:
266
+ * xpath_object.string -> String
267
+ *
268
+ * Returns the original XPath expression as a string.
269
+ */
245
270
  VALUE
246
271
  ruby_xml_xpath_object_string(VALUE self)
247
272
  {
@@ -255,32 +280,51 @@ ruby_xml_xpath_object_string(VALUE self)
255
280
  return rb_str_new2((const char*) xpop->stringval);
256
281
  }
257
282
 
283
+ /*
284
+ * call-seq:
285
+ * nodes.debug -> (true|false)
286
+ *
287
+ * Dump libxml debugging information to stdout.
288
+ * Requires Libxml be compiled with debugging enabled.
289
+ */
290
+ VALUE
291
+ ruby_xml_xpath_object_debug(VALUE self) {
292
+ xmlXPathObjectPtr xpop;
293
+
294
+ #ifndef LIBXML_DEBUG_ENABLED
295
+ rb_raise(rb_eTypeError, "libxml was not compiled with debug support.");
296
+ #endif
297
+
298
+ Data_Get_Struct(self, xmlXPathObject, xpop);
299
+ xmlXPathDebugDumpObject(stdout, xpop, 0);
300
+ return Qnil;
301
+ }
302
+
303
+
258
304
  // Rdoc needs to know
259
- #ifdef RDOC_NEVER_DEFINED
260
- mXML = rb_define_module("XML");
261
- cXMLXPath = rb_define_class_under(mXML, "XPath", rb_cObject);
262
- #endif
305
+ #ifdef RDOC_NEVER_DEFINED
306
+ mLibXML = rb_define_module("LibXML");
307
+ mXML = rb_define_module_under(mLibXML, "XML");
308
+ mXPath = rb_define_module_under(mXML, "XPath");
309
+ #endif
263
310
 
264
311
  void
265
312
  ruby_init_xml_xpath_object(void) {
266
- cXMLXPathObject = rb_define_class_under(cXMLXPath, "Object", rb_cObject);
267
-
268
- rb_include_module(cXMLXPathObject, rb_const_get(rb_cObject, rb_intern("Enumerable")));
313
+ cXMLXPathObject = rb_define_class_under(mXPath, "Object", rb_cObject);
314
+ rb_include_module(cXMLXPathObject, rb_mEnumerable);
269
315
 
270
316
  rb_define_method(cXMLXPathObject, "each", ruby_xml_xpath_object_each, 0);
271
- rb_define_method(cXMLXPathObject, "set_type", ruby_xml_xpath_object_set_type, 0);
317
+ rb_define_method(cXMLXPathObject, "xpath_type", ruby_xml_xpath_object_get_type, 0);
272
318
  rb_define_method(cXMLXPathObject, "empty?", ruby_xml_xpath_object_empty_q, 0);
273
319
  rb_define_method(cXMLXPathObject, "first", ruby_xml_xpath_object_first, 0);
274
320
  rb_define_method(cXMLXPathObject, "length", ruby_xml_xpath_object_length, 0);
275
321
  rb_define_method(cXMLXPathObject, "size", ruby_xml_xpath_object_length, 0);
276
322
  rb_define_method(cXMLXPathObject, "to_a", ruby_xml_xpath_object_to_a, 0);
277
323
  rb_define_method(cXMLXPathObject, "[]", ruby_xml_xpath_object_aref, 1);
278
-
279
324
  rb_define_method(cXMLXPathObject, "string", ruby_xml_xpath_object_string, 0);
280
-
281
- rb_include_module(cXMLNodeSet, rb_const_get(rb_cObject, rb_intern("Enumerable")));
282
-
325
+ rb_define_attr(cXMLXPathObject, "context", 1, 0);
326
+ rb_define_method(cXMLXPathObject, "debug", ruby_xml_xpath_object_debug, 0);
327
+
283
328
  /* Give the NodeSet type, but it is pointless */
284
329
  rb_define_method(cXMLXPathObject, "set", ruby_xml_xpath_object_set, 0);
285
-
286
330
  }