libxml-ruby 0.8.1 → 0.8.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (161) hide show
  1. data/CHANGES +21 -0
  2. data/RAKEFILE +213 -0
  3. data/README +32 -11
  4. data/doc/rdoc/classes/LibXML.html +4 -0
  5. data/doc/rdoc/classes/LibXML/XML.html +7 -0
  6. data/doc/rdoc/classes/LibXML/XML/Attr.html +187 -177
  7. data/doc/rdoc/classes/LibXML/XML/Attributes.html +62 -61
  8. data/doc/rdoc/classes/LibXML/XML/Document.html +318 -254
  9. data/doc/rdoc/classes/LibXML/XML/Dtd.html +62 -8
  10. data/doc/rdoc/classes/LibXML/XML/Error.html +6 -0
  11. data/doc/rdoc/classes/LibXML/XML/HTMLParser.html +59 -41
  12. data/doc/rdoc/classes/LibXML/XML/InputCallbacks.html +12 -6
  13. data/doc/rdoc/classes/LibXML/XML/NS.html +65 -50
  14. data/doc/rdoc/classes/LibXML/XML/Node.html +671 -630
  15. data/doc/rdoc/classes/LibXML/XML/Node/FailedModify.html +12 -0
  16. data/doc/rdoc/classes/LibXML/XML/Node/Set.html +64 -60
  17. data/doc/rdoc/classes/LibXML/XML/Node/SetNamespace.html +12 -0
  18. data/doc/rdoc/classes/LibXML/XML/Node/UnknownType.html +12 -0
  19. data/doc/rdoc/classes/LibXML/XML/Parser.html +407 -383
  20. data/doc/rdoc/classes/LibXML/XML/Parser/Context.html +241 -219
  21. data/doc/rdoc/classes/LibXML/XML/Parser/ParseError.html +12 -0
  22. data/doc/rdoc/classes/LibXML/XML/Reader.html +421 -331
  23. data/doc/rdoc/classes/LibXML/XML/RelaxNG.html +237 -0
  24. data/doc/rdoc/classes/LibXML/XML/SaxParser.html +79 -60
  25. data/doc/rdoc/classes/LibXML/XML/Schema.html +109 -22
  26. data/doc/rdoc/classes/LibXML/XML/State.html +6 -0
  27. data/doc/rdoc/classes/LibXML/XML/XInclude.html +6 -0
  28. data/doc/rdoc/classes/LibXML/XML/XInclude/Error.html +6 -0
  29. data/doc/rdoc/classes/LibXML/XML/XPath.html +4 -48
  30. data/doc/rdoc/classes/LibXML/XML/XPath/Context.html +6 -5
  31. data/doc/rdoc/classes/LibXML/XML/XPath/InvalidPath.html +61 -0
  32. data/doc/rdoc/classes/LibXML/XML/XPath/Object.html +12 -8
  33. data/doc/rdoc/classes/LibXML/XML/XPointer.html +14 -8
  34. data/doc/rdoc/classes/LibXML/XML/XPointer/Context.html +6 -0
  35. data/doc/rdoc/classes/LibXML/XML/XPointer/Context/InvalidPath.html +6 -0
  36. data/doc/rdoc/classes/LibXML/XML/XPointer/InvalidExpression.html +13 -0
  37. data/doc/rdoc/created.rid +1 -1
  38. data/doc/rdoc/files/CHANGES.html +38 -10
  39. data/doc/rdoc/files/LICENSE.html +1 -1
  40. data/doc/rdoc/files/README.html +57 -23
  41. data/doc/rdoc/files/VERSION.html +1 -1
  42. data/doc/rdoc/files/ext/libxml/cbg_c.html +1 -1
  43. data/doc/rdoc/files/ext/libxml/libxml_c.html +1 -1
  44. data/doc/rdoc/files/ext/libxml/ruby_xml_attr_c.html +1 -1
  45. data/doc/rdoc/files/ext/libxml/ruby_xml_attributes_c.html +1 -1
  46. data/doc/rdoc/files/ext/libxml/ruby_xml_document_c.html +1 -1
  47. data/doc/rdoc/files/ext/libxml/ruby_xml_dtd_c.html +1 -1
  48. data/doc/rdoc/files/ext/libxml/ruby_xml_html_parser_c.html +1 -1
  49. data/doc/rdoc/files/ext/libxml/ruby_xml_input_cbg_c.html +1 -1
  50. data/doc/rdoc/files/ext/libxml/ruby_xml_node_c.html +1 -1
  51. data/doc/rdoc/files/ext/libxml/ruby_xml_node_set_c.html +1 -1
  52. data/doc/rdoc/files/ext/libxml/ruby_xml_ns_c.html +1 -1
  53. data/doc/rdoc/files/ext/libxml/ruby_xml_parser_c.html +1 -1
  54. data/doc/rdoc/files/ext/libxml/ruby_xml_parser_context_c.html +1 -1
  55. data/doc/rdoc/files/ext/libxml/ruby_xml_reader_c.html +1 -1
  56. data/doc/rdoc/{classes/XML.html → files/ext/libxml/ruby_xml_relaxng_c.html} +16 -35
  57. data/doc/rdoc/files/ext/libxml/ruby_xml_sax_parser_c.html +1 -1
  58. data/doc/rdoc/files/ext/libxml/ruby_xml_schema_c.html +1 -1
  59. data/doc/rdoc/files/ext/libxml/ruby_xml_state_c.html +1 -1
  60. data/doc/rdoc/files/ext/libxml/ruby_xml_xinclude_c.html +1 -1
  61. data/doc/rdoc/files/ext/libxml/ruby_xml_xpath_c.html +1 -1
  62. data/doc/rdoc/files/ext/libxml/ruby_xml_xpath_context_c.html +1 -1
  63. data/doc/rdoc/files/ext/libxml/ruby_xml_xpath_object_c.html +1 -1
  64. data/doc/rdoc/files/ext/libxml/ruby_xml_xpointer_c.html +1 -1
  65. data/doc/rdoc/files/ext/libxml/ruby_xml_xpointer_context_c.html +1 -1
  66. data/doc/rdoc/files/lib/libxml/attr_rb.html +1 -1
  67. data/doc/rdoc/files/lib/libxml/attributes_rb.html +1 -1
  68. data/doc/rdoc/files/lib/libxml/document_rb.html +1 -1
  69. data/doc/rdoc/files/lib/libxml/node_rb.html +1 -1
  70. data/doc/rdoc/files/lib/libxml/node_set_rb.html +1 -1
  71. data/doc/rdoc/files/lib/libxml/parser_options_rb.html +1 -1
  72. data/doc/rdoc/files/lib/libxml/parser_rb.html +1 -1
  73. data/doc/rdoc/files/lib/libxml/properties_rb.html +1 -1
  74. data/doc/rdoc/files/lib/libxml/tree_rb.html +1 -1
  75. data/doc/rdoc/files/lib/libxml_rb.html +2 -2
  76. data/doc/rdoc/files/lib/xml/libxml_rb.html +12 -2
  77. data/doc/rdoc/files/lib/xml_rb.html +134 -0
  78. data/doc/rdoc/fr_class_index.html +1 -1
  79. data/doc/rdoc/fr_file_index.html +2 -0
  80. data/doc/rdoc/fr_method_index.html +349 -344
  81. data/ext/libxml/libxml.c +2 -1
  82. data/ext/libxml/ruby_libxml.h +1 -0
  83. data/ext/libxml/ruby_xml_attr.c +8 -2
  84. data/ext/libxml/ruby_xml_attributes.c +5 -5
  85. data/ext/libxml/ruby_xml_document.c +41 -2
  86. data/ext/libxml/ruby_xml_dtd.c +169 -169
  87. data/ext/libxml/ruby_xml_html_parser.c +449 -449
  88. data/ext/libxml/ruby_xml_input_cbg.c +165 -165
  89. data/ext/libxml/ruby_xml_node.c +1 -1
  90. data/ext/libxml/ruby_xml_node_set.c +172 -172
  91. data/ext/libxml/ruby_xml_ns.c +145 -145
  92. data/ext/libxml/ruby_xml_parser.c +1398 -1398
  93. data/ext/libxml/ruby_xml_parser_context.c +697 -697
  94. data/ext/libxml/ruby_xml_reader.c +44 -0
  95. data/ext/libxml/ruby_xml_reader.h +14 -14
  96. data/ext/libxml/ruby_xml_relaxng.c +97 -0
  97. data/ext/libxml/ruby_xml_relaxng.h +15 -0
  98. data/ext/libxml/ruby_xml_sax_parser.c +486 -486
  99. data/ext/libxml/ruby_xml_schema.c +1 -1
  100. data/ext/libxml/ruby_xml_state.c +4 -4
  101. data/ext/libxml/ruby_xml_xinclude.c +21 -21
  102. data/ext/libxml/ruby_xml_xpath.c +89 -89
  103. data/ext/libxml/ruby_xml_xpath_context.c +283 -283
  104. data/ext/libxml/ruby_xml_xpath_object.c +5 -5
  105. data/ext/libxml/ruby_xml_xpointer.c +104 -104
  106. data/ext/libxml/ruby_xml_xpointer_context.c +22 -22
  107. data/ext/libxml/version.h +2 -2
  108. data/ext/libxml/version.h.rej +17 -0
  109. data/ext/mingw/Rakefile +41 -0
  110. data/lib/libxml.rb +15 -4
  111. data/lib/xml.rb +14 -0
  112. data/lib/xml/libxml.rb +4 -1
  113. data/test/etc_doc_to_s.rb +1 -1
  114. data/test/ets_copy_bug.rb +1 -1
  115. data/test/ets_copy_bug3.rb +1 -1
  116. data/test/ets_doc_file.rb +1 -1
  117. data/test/ets_doc_to_s.rb +1 -1
  118. data/test/ets_node_gc.rb +1 -1
  119. data/test/ets_tsr.rb +1 -1
  120. data/test/model/shiporder.rnc +28 -0
  121. data/test/model/shiporder.rng +86 -0
  122. data/test/{tc_xml_attributes.rb → tc_attributes.rb} +1 -10
  123. data/test/{tc_xml_document.rb → tc_document.rb} +1 -1
  124. data/test/{tc_xml_document_write.rb → tc_document_write.rb} +1 -1
  125. data/test/{tc_xml_dtd.rb → tc_dtd.rb} +1 -1
  126. data/test/{tc_xml_html_parser.rb → tc_html_parser.rb} +1 -1
  127. data/test/{tc_xml_node.rb → tc_node.rb} +1 -1
  128. data/test/{tc_xml_node_attr.rb → tc_node_attr.rb} +1 -1
  129. data/test/{tc_xml_node_cdata.rb → tc_node_cdata.rb} +24 -5
  130. data/test/{tc_xml_node_comment.rb → tc_node_comment.rb} +1 -1
  131. data/test/{tc_xml_node_copy.rb → tc_node_copy.rb} +1 -1
  132. data/test/{tc_xml_node_edit.rb → tc_node_edit.rb} +1 -1
  133. data/test/{tc_xml_node_set.rb → tc_node_set.rb} +1 -1
  134. data/test/{tc_xml_node_set2.rb → tc_node_set2.rb} +1 -1
  135. data/test/{tc_xml_node_text.rb → tc_node_text.rb} +1 -1
  136. data/test/{tc_xml_node_xlink.rb → tc_node_xlink.rb} +2 -2
  137. data/test/{tc_xml_parser.rb → tc_parser.rb} +1 -1
  138. data/test/{tc_xml_parser_context.rb → tc_parser_context.rb} +1 -1
  139. data/test/{tc_xml_properties.rb → tc_properties.rb} +1 -7
  140. data/test/{tc_xml_reader.rb → tc_reader.rb} +1 -1
  141. data/test/tc_relaxng.rb +39 -0
  142. data/test/{tc_xml_sax_parser.rb → tc_sax_parser.rb} +1 -1
  143. data/test/{tc_xml_schema.rb → tc_schema.rb} +1 -1
  144. data/test/{tc_xml_traversal.rb → tc_traversal.rb} +1 -1
  145. data/test/{tc_xml_xinclude.rb → tc_xinclude.rb} +1 -1
  146. data/test/{tc_xml_xpath.rb → tc_xpath.rb} +1 -1
  147. data/test/{tc_xml_xpath_context.rb → tc_xpath_context.rb} +1 -1
  148. data/test/{tc_xml_xpointer.rb → tc_xpointer.rb} +1 -1
  149. data/test/test_suite.rb +26 -25
  150. metadata +100 -100
  151. data/benchmark/depixelate.rb +0 -632
  152. data/benchmark/hamlet.xml +0 -9055
  153. data/benchmark/sock_entries.xml +0 -507
  154. data/benchmark/throughput.rb +0 -39
  155. data/benchmark/xml_benchmarks.rb +0 -227
  156. data/mingw/libiconv-2.dll +0 -0
  157. data/mingw/libxml2-2.dll +0 -0
  158. data/mingw/libxml_ruby.so +0 -0
  159. data/test/gc.log +0 -0
  160. data/vc/libxml_ruby.sln +0 -20
  161. data/vc/libxml_ruby.vcproj +0 -389
@@ -49,7 +49,7 @@ ruby_xml_schema_init_from_uri(VALUE class, VALUE uri) {
49
49
  * call-seq:
50
50
  * XML::Schema.document(document) -> schema
51
51
  *
52
- * Create a new schema from the specified URI.
52
+ * Create a new schema from the specified document.
53
53
  */
54
54
  VALUE
55
55
  ruby_xml_schema_init_from_document(VALUE class, VALUE document) {
@@ -27,10 +27,10 @@ ruby_xml_state_alloc(VALUE klass) {
27
27
  }
28
28
 
29
29
  // Rdoc needs to know
30
- #ifdef RDOC_NEVER_DEFINED
31
- mLibXML = rb_define_module("LibXML");
32
- mXML = rb_define_module_under(mLibXML, "XML");
33
- #endif
30
+ #ifdef RDOC_NEVER_DEFINED
31
+ mLibXML = rb_define_module("LibXML");
32
+ mXML = rb_define_module_under(mLibXML, "XML");
33
+ #endif
34
34
 
35
35
  void
36
36
  ruby_init_state(void) {
@@ -1,21 +1,21 @@
1
- /* $Id: ruby_xml_xinclude.c 461 2008-07-15 21:35:56Z cfis $ */
2
-
3
- /* Please see the LICENSE file for copyright and distribution information */
4
-
5
- #include "ruby_libxml.h"
6
- #include "ruby_xml_xinclude.h"
7
-
8
- VALUE cXMLXInclude;
9
- VALUE eXMLXIncludeError;
10
-
11
- // Rdoc needs to know
12
- #ifdef RDOC_NEVER_DEFINED
13
- mLibXML = rb_define_module("LibXML");
14
- mXML = rb_define_module_under(mLibXML, "XML");
15
- #endif
16
-
17
- void
18
- ruby_init_xml_xinclude(void) {
19
- cXMLXInclude = rb_define_class_under(mXML, "XInclude", rb_cObject);
20
- eXMLXIncludeError = rb_define_class_under(cXMLXInclude, "Error", rb_eRuntimeError);
21
- }
1
+ /* $Id: ruby_xml_xinclude.c 461 2008-07-15 21:35:56Z cfis $ */
2
+
3
+ /* Please see the LICENSE file for copyright and distribution information */
4
+
5
+ #include "ruby_libxml.h"
6
+ #include "ruby_xml_xinclude.h"
7
+
8
+ VALUE cXMLXInclude;
9
+ VALUE eXMLXIncludeError;
10
+
11
+ // Rdoc needs to know
12
+ #ifdef RDOC_NEVER_DEFINED
13
+ mLibXML = rb_define_module("LibXML");
14
+ mXML = rb_define_module_under(mLibXML, "XML");
15
+ #endif
16
+
17
+ void
18
+ ruby_init_xml_xinclude(void) {
19
+ cXMLXInclude = rb_define_class_under(mXML, "XInclude", rb_cObject);
20
+ eXMLXIncludeError = rb_define_class_under(cXMLXInclude, "Error", rb_eRuntimeError);
21
+ }
@@ -1,89 +1,89 @@
1
- /* $Id: ruby_xml_xpath.c 461 2008-07-15 21:35:56Z 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 Namespaces
29
- *
30
- * Finding namespaced elements and attributes can be tricky.
31
- * Lets work through some examples using the following xml document:
32
- *
33
- * <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
34
- * <soap:Body>
35
- * <getManufacturerNamesResponse xmlns="http://services.somewhere.com">
36
- * <IDAndNameList xmlns="http://services.somewhere.com">
37
- * <ns1:IdAndName xmlns:ns1="http://domain.somewhere.com"/>
38
- * </IDAndNameList>
39
- * </getManufacturerNamesResponse>
40
- * </soap:Envelope>
41
- *
42
- * # Since the soap namespace is defined on the root
43
- * # node we can directly use it.
44
- * doc.find('/soap:Envelope')
45
- *
46
- * # Since the ns1 namespace is not defined on the root node
47
- * # we have to first register it with the xpath engine.
48
- * doc.find('//ns1:IdAndName',
49
- * 'ns1:http://domain.somewhere.com')
50
- *
51
- * # Since the getManufacturerNamesResponse element uses a default
52
- * # namespace we first have to give it a prefix and register
53
- * # it with the xpath engine.
54
- * doc.find('//ns:getManufacturerNamesResponse',
55
- * 'ns:http://services.somewhere.com')
56
- *
57
- * # Here is an example showing a complex namespace aware
58
- * # xpath expression.
59
- * doc.find('/soap:Envelope/soap:Body/ns0:getManufacturerNamesResponse/ns0:IDAndNameList/ns1:IdAndName',
60
- ['ns0:http://services.somewhere.com', 'ns1:http://domain.somewhere.com'])
61
- */
62
-
63
- VALUE mXPath;
64
- VALUE eXMLXPathInvalidPath;
65
-
66
- // Rdoc needs to know
67
- #ifdef RDOC_NEVER_DEFINED
68
- mLibXML = rb_define_module("LibXML");
69
- mXML = rb_define_module_under(mLibXML, "XML");
70
- #endif
71
-
72
- void
73
- ruby_init_xml_xpath(void) {
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));
87
-
88
- ruby_init_xml_xpath_object();
89
- }
1
+ /* $Id: ruby_xml_xpath.c 461 2008-07-15 21:35:56Z 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 Namespaces
29
+ *
30
+ * Finding namespaced elements and attributes can be tricky.
31
+ * Lets work through some examples using the following xml document:
32
+ *
33
+ * <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
34
+ * <soap:Body>
35
+ * <getManufacturerNamesResponse xmlns="http://services.somewhere.com">
36
+ * <IDAndNameList xmlns="http://services.somewhere.com">
37
+ * <ns1:IdAndName xmlns:ns1="http://domain.somewhere.com"/>
38
+ * </IDAndNameList>
39
+ * </getManufacturerNamesResponse>
40
+ * </soap:Envelope>
41
+ *
42
+ * # Since the soap namespace is defined on the root
43
+ * # node we can directly use it.
44
+ * doc.find('/soap:Envelope')
45
+ *
46
+ * # Since the ns1 namespace is not defined on the root node
47
+ * # we have to first register it with the xpath engine.
48
+ * doc.find('//ns1:IdAndName',
49
+ * 'ns1:http://domain.somewhere.com')
50
+ *
51
+ * # Since the getManufacturerNamesResponse element uses a default
52
+ * # namespace we first have to give it a prefix and register
53
+ * # it with the xpath engine.
54
+ * doc.find('//ns:getManufacturerNamesResponse',
55
+ * 'ns:http://services.somewhere.com')
56
+ *
57
+ * # Here is an example showing a complex namespace aware
58
+ * # xpath expression.
59
+ * doc.find('/soap:Envelope/soap:Body/ns0:getManufacturerNamesResponse/ns0:IDAndNameList/ns1:IdAndName',
60
+ ['ns0:http://services.somewhere.com', 'ns1:http://domain.somewhere.com'])
61
+ */
62
+
63
+ VALUE mXPath;
64
+ VALUE eXMLXPathInvalidPath;
65
+
66
+ // Rdoc needs to know
67
+ #ifdef RDOC_NEVER_DEFINED
68
+ mLibXML = rb_define_module("LibXML");
69
+ mXML = rb_define_module_under(mLibXML, "XML");
70
+ #endif
71
+
72
+ void
73
+ ruby_init_xml_xpath(void) {
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));
87
+
88
+ ruby_init_xml_xpath_object();
89
+ }
@@ -1,283 +1,283 @@
1
- /* $Id: ruby_xml_xpath_context.c 461 2008-07-15 21:35:56Z cfis $ */
2
-
3
- /* Please see the LICENSE file for copyright and distribution information */
4
-
5
- #include "ruby_libxml.h"
6
- #include "ruby_xml_xpath_context.h"
7
- #include <st.h>
8
-
9
-
10
- /*
11
- * Document-class: LibXML::XML::XPath::Context
12
- *
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')
22
- */
23
-
24
- VALUE cXMLXPathContext;
25
-
26
- void
27
- ruby_xml_xpath_context_free(xmlXPathContextPtr ctxt) {
28
- xmlXPathFreeContext(ctxt);
29
- }
30
-
31
-
32
- VALUE
33
- ruby_xml_xpath_context_alloc(VALUE klass) {
34
- return Data_Wrap_Struct(cXMLXPathContext,
35
- NULL,
36
- ruby_xml_xpath_context_free,
37
- NULL);
38
- }
39
-
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
- */
51
- VALUE
52
- ruby_xml_xpath_context_initialize(VALUE self, VALUE node) {
53
- ruby_xml_document_t *rxd;
54
- VALUE document;
55
- #ifndef LIBXML_XPATH_ENABLED
56
- rb_raise(rb_eTypeError, "libxml was not compiled with XPath support.");
57
- #endif
58
-
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;
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);
79
-
80
- return self;
81
- }
82
-
83
-
84
- /*
85
- * call-seq:
86
- * context.register_namespace(prefix, uri) -> (true|false)
87
- *
88
- * Register the specified namespace URI with the specified prefix
89
- * in this context.
90
-
91
- * context.register_namespace('xi', 'http://www.w3.org/2001/XInclude')
92
- */
93
- VALUE
94
- ruby_xml_xpath_context_register_namespace(VALUE self, VALUE prefix, VALUE uri) {
95
- xmlXPathContextPtr ctxt;
96
-
97
- Data_Get_Struct(self, xmlXPathContext, ctxt);
98
- if (xmlXPathRegisterNs(ctxt,
99
- (xmlChar*)StringValuePtr(prefix),
100
- (xmlChar*)StringValuePtr(uri))
101
- == 0) {
102
- return(Qtrue);
103
- } else {
104
- /* Should raise an exception, IMHO (whose?, why shouldnt it? -danj)*/
105
- rb_warning("register namespace failed");
106
- return(Qfalse);
107
- }
108
- }
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
-
265
- // Rdoc needs to know
266
- #ifdef RDOC_NEVER_DEFINED
267
- mLibXML = rb_define_module("LibXML");
268
- mXML = rb_define_module_under(mLibXML, "XML");
269
- mXPath = rb_define_module_under(mXML, "XPath");
270
- #endif
271
-
272
- void
273
- ruby_init_xml_xpath_context(void) {
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);
283
- }
1
+ /* $Id: ruby_xml_xpath_context.c 461 2008-07-15 21:35:56Z cfis $ */
2
+
3
+ /* Please see the LICENSE file for copyright and distribution information */
4
+
5
+ #include "ruby_libxml.h"
6
+ #include "ruby_xml_xpath_context.h"
7
+ #include <st.h>
8
+
9
+
10
+ /*
11
+ * Document-class: LibXML::XML::XPath::Context
12
+ *
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')
22
+ */
23
+
24
+ VALUE cXMLXPathContext;
25
+
26
+ void
27
+ ruby_xml_xpath_context_free(xmlXPathContextPtr ctxt) {
28
+ xmlXPathFreeContext(ctxt);
29
+ }
30
+
31
+
32
+ VALUE
33
+ ruby_xml_xpath_context_alloc(VALUE klass) {
34
+ return Data_Wrap_Struct(cXMLXPathContext,
35
+ NULL,
36
+ ruby_xml_xpath_context_free,
37
+ NULL);
38
+ }
39
+
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
+ */
51
+ VALUE
52
+ ruby_xml_xpath_context_initialize(VALUE self, VALUE node) {
53
+ ruby_xml_document_t *rxd;
54
+ VALUE document;
55
+ #ifndef LIBXML_XPATH_ENABLED
56
+ rb_raise(rb_eTypeError, "libxml was not compiled with XPath support.");
57
+ #endif
58
+
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;
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);
79
+
80
+ return self;
81
+ }
82
+
83
+
84
+ /*
85
+ * call-seq:
86
+ * context.register_namespace(prefix, uri) -> (true|false)
87
+ *
88
+ * Register the specified namespace URI with the specified prefix
89
+ * in this context.
90
+
91
+ * context.register_namespace('xi', 'http://www.w3.org/2001/XInclude')
92
+ */
93
+ VALUE
94
+ ruby_xml_xpath_context_register_namespace(VALUE self, VALUE prefix, VALUE uri) {
95
+ xmlXPathContextPtr ctxt;
96
+
97
+ Data_Get_Struct(self, xmlXPathContext, ctxt);
98
+ if (xmlXPathRegisterNs(ctxt,
99
+ (xmlChar*)StringValuePtr(prefix),
100
+ (xmlChar*)StringValuePtr(uri))
101
+ == 0) {
102
+ return(Qtrue);
103
+ } else {
104
+ /* Should raise an exception, IMHO (whose?, why shouldnt it? -danj)*/
105
+ rb_warning("register namespace failed");
106
+ return(Qfalse);
107
+ }
108
+ }
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
+
265
+ // Rdoc needs to know
266
+ #ifdef RDOC_NEVER_DEFINED
267
+ mLibXML = rb_define_module("LibXML");
268
+ mXML = rb_define_module_under(mLibXML, "XML");
269
+ mXPath = rb_define_module_under(mXML, "XPath");
270
+ #endif
271
+
272
+ void
273
+ ruby_init_xml_xpath_context(void) {
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);
283
+ }