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,4 +1,4 @@
1
- /* $Id: ruby_xml_xpointer.c 351 2008-07-09 19:55:21Z cfis $ */
1
+ /* $Id: ruby_xml_xpointer.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
 
@@ -12,9 +12,12 @@ VALUE
12
12
  ruby_xml_xpointer_point(VALUE class, VALUE rnode, VALUE xptr_str) {
13
13
  #ifdef LIBXML_XPTR_ENABLED
14
14
  xmlNodePtr xnode;
15
- xmlXPathContextPtr ctxt;
16
- VALUE rxptr_xpth_ctxt, rxxp;
17
- xmlXPathObjectPtr xpath;
15
+ xmlXPathContextPtr xctxt;
16
+ xmlXPathObjectPtr xpop;
17
+
18
+ VALUE context;
19
+ VALUE result;
20
+ VALUE argv[1];
18
21
 
19
22
  Check_Type(xptr_str, T_STRING);
20
23
  if (rb_obj_is_kind_of(rnode, cXMLNode) == Qfalse)
@@ -22,18 +25,18 @@ ruby_xml_xpointer_point(VALUE class, VALUE rnode, VALUE xptr_str) {
22
25
 
23
26
  Data_Get_Struct(rnode, xmlNode, xnode);
24
27
 
25
- rxptr_xpth_ctxt =
26
- ruby_xml_xpath_context_wrap(ctxt=xmlXPtrNewContext(xnode->doc, xnode, NULL));
27
-
28
- if (NIL_P(rxptr_xpth_ctxt))
29
- return(Qnil);
28
+ argv[0] = rb_funcall(rnode, rb_intern("doc"), 0);
29
+ context = rb_class_new_instance(1, argv, cXMLXPathContext);
30
+ Data_Get_Struct(context, xmlXPathContext, xctxt);
30
31
 
31
- xpath = xmlXPtrEval((xmlChar*)StringValuePtr(xptr_str), ctxt);
32
- if (xpath == NULL)
33
- rb_raise(eXMLXPointerInvalidExpression, "invalid xpointer expression");
32
+ xpop = xmlXPtrEval((xmlChar*)StringValuePtr(xptr_str), xctxt);
33
+ if (!xpop)
34
+ rb_raise(eXMLXPointerInvalidExpression, "Invalid xpointer expression");
34
35
 
35
- rxxp = ruby_xml_xpath_object_wrap(xpath);
36
- return(rxxp);
36
+ result = ruby_xml_xpath_object_wrap(xpop);
37
+ rb_iv_set(result, "@context", context);
38
+
39
+ return(result);
37
40
  #else
38
41
  rb_warn("libxml was compiled without XPointer support");
39
42
  return(Qfalse);
@@ -88,7 +91,8 @@ ruby_xml_xpointer_range(VALUE class, VALUE rstart, VALUE rend) {
88
91
 
89
92
  // Rdoc needs to know
90
93
  #ifdef RDOC_NEVER_DEFINED
91
- mXML = rb_define_module("XML");
94
+ mLibXML = rb_define_module("LibXML");
95
+ mXML = rb_define_module_under(mLibXML, "XML");
92
96
  #endif
93
97
 
94
98
  void
@@ -1,27 +1,27 @@
1
- /* $Id: ruby_xml_xpointer.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_XPOINTER__
6
- #define __RUBY_XML_XPOINTER__
7
-
8
- extern VALUE cXMLXPointer;
9
- extern VALUE eXMLXPointerInvalidExpression;
10
-
11
- typedef struct ruby_xml_xpointer {
12
- VALUE xd;
13
- VALUE ctxt;
14
- /*
15
- * This needs to go into a xpointer data struct:
16
- *
17
- * xmlLocationSetPtr xptr;
18
- *
19
- * I also need an xpointer data struct type.
20
- */
21
- } ruby_xml_xpointer;
22
-
23
- VALUE ruby_xml_xpointer_point(VALUE class, VALUE node, VALUE xptr_string);
24
- VALUE ruby_xml_xpointer_point2(VALUE node, VALUE xptr_string);
25
- void ruby_init_xml_xpointer(void);
26
-
27
- #endif
1
+ /* $Id: ruby_xml_xpointer.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_XPOINTER__
6
+ #define __RUBY_XML_XPOINTER__
7
+
8
+ extern VALUE cXMLXPointer;
9
+ extern VALUE eXMLXPointerInvalidExpression;
10
+
11
+ typedef struct ruby_xml_xpointer {
12
+ VALUE xd;
13
+ VALUE ctxt;
14
+ /*
15
+ * This needs to go into a xpointer data struct:
16
+ *
17
+ * xmlLocationSetPtr xptr;
18
+ *
19
+ * I also need an xpointer data struct type.
20
+ */
21
+ } ruby_xml_xpointer;
22
+
23
+ VALUE ruby_xml_xpointer_point(VALUE class, VALUE node, VALUE xptr_string);
24
+ VALUE ruby_xml_xpointer_point2(VALUE node, VALUE xptr_string);
25
+ void ruby_init_xml_xpointer(void);
26
+
27
+ #endif
@@ -1,4 +1,4 @@
1
- /* $Id: ruby_xml_xpointer_context.c 300 2008-07-01 19:14:15Z cfis $ */
1
+ /* $Id: ruby_xml_xpointer_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
 
@@ -10,7 +10,8 @@ VALUE eXMLXPointerContextInvalidPath;
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
  cXMLXPointer = rb_define_class_under(mXML, "XPointer", rb_cObject);
15
16
  #endif
16
17
 
@@ -1,18 +1,18 @@
1
- /* $Id: ruby_xml_xpointer_context.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_XPOINTER_CONTEXT__
6
- #define __RUBY_XML_XPOINTER_CONTEXT__
7
-
8
- extern VALUE cXMLXPointerContext;
9
- extern VALUE eXMLXPointerContextInvalidPath;
10
-
11
- typedef struct ruby_xml_xpointer_context {
12
- VALUE xd;
13
- xmlXPathContextPtr ctxt;
14
- } ruby_xml_xpointer_context;
15
-
16
- void ruby_init_xml_xpointer_context(void);
17
-
18
- #endif
1
+ /* $Id: ruby_xml_xpointer_context.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_XPOINTER_CONTEXT__
6
+ #define __RUBY_XML_XPOINTER_CONTEXT__
7
+
8
+ extern VALUE cXMLXPointerContext;
9
+ extern VALUE eXMLXPointerContextInvalidPath;
10
+
11
+ typedef struct ruby_xml_xpointer_context {
12
+ VALUE xd;
13
+ xmlXPathContextPtr ctxt;
14
+ } ruby_xml_xpointer_context;
15
+
16
+ void ruby_init_xml_xpointer_context(void);
17
+
18
+ #endif
@@ -1,9 +1,9 @@
1
- /* Don't nuke this block! It is used for automatically updating the
2
- * versions below. VERSION = string formatting, VERNUM = numbered
3
- * version for inline testing: increment both or none at all.*/
4
- #define RUBY_LIBXML_VERSION "0.7.0"
5
- #define RUBY_LIBXML_VERNUM 0
6
- #define RUBY_LIBXML_VER_MAJ 0
7
- #define RUBY_LIBXML_VER_MIN 7
8
- #define RUBY_LIBXML_VER_MIC 0
9
- #define RUBY_LIBXML_VER_PATCH 0
1
+ /* Don't nuke this block! It is used for automatically updating the
2
+ * versions below. VERSION = string formatting, VERNUM = numbered
3
+ * version for inline testing: increment both or none at all.*/
4
+ #define RUBY_LIBXML_VERSION "0.8.0"
5
+ #define RUBY_LIBXML_VERNUM 0
6
+ #define RUBY_LIBXML_VER_MAJ 0
7
+ #define RUBY_LIBXML_VER_MIN 8
8
+ #define RUBY_LIBXML_VER_MIC 0
9
+ #define RUBY_LIBXML_VER_PATCH 0
@@ -1,134 +1,22 @@
1
- # $Id: libxml.rb 326 2008-07-08 23:00:50Z cfis $
1
+ # $Id: libxml.rb 458 2008-07-15 21:10:55Z cfis $
2
2
  # Please see the LICENSE file for copyright and distribution information
3
3
 
4
- require 'libxml_ruby.so'
4
+ require 'libxml_ruby'
5
5
 
6
- module XML::XMLParserOptions
7
- XML_PARSE_RECOVER = 1 # recover on errors
8
- XML_PARSE_NOENT = 2 # substitute entities
9
- XML_PARSE_DTDLOAD = 4 # load the external subset
10
- XML_PARSE_DTDATTR = 8 # default DTD attributes
11
- XML_PARSE_DTDVALID = 16 # validate with the DTD
12
- XML_PARSE_NOERROR = 32 # suppress error reports
13
- XML_PARSE_NOWARNING = 64 # suppress warning reports
14
- XML_PARSE_PEDANTIC = 128 # pedantic error reporting
15
- XML_PARSE_NOBLANKS = 256 # remove blank nodes
16
- XML_PARSE_SAX1 = 512 # use the SAX1 interface internally
17
- XML_PARSE_XINCLUDE = 1024 # Implement XInclude substitition
18
- XML_PARSE_NONET = 2048 # Forbid network access
19
- XML_PARSE_NODICT = 4096 # Do not reuse the context dictionnary
20
- XML_PARSE_NSCLEAN = 8192 # remove redundant namespaces declarations
21
- XML_PARSE_NOCDATA = 16384 # merge CDATA as text nodes
22
- XML_PARSE_NOXINCNODE = 32768 # do not generate XINCLUDE START/END nodes
23
- XML_PARSE_COMPACT = 65536 # compact small text nodes; no modification of the tree allowed afterwards (will possibly crash if you try to modify the tree)
24
- end
6
+ require 'libxml/parser'
7
+ require 'libxml/parser_options'
8
+ require 'libxml/document'
9
+ require 'libxml/node'
10
+ require 'libxml/node_set'
11
+ require 'libxml/attributes'
12
+ require 'libxml/attr'
13
+ require 'libxml/tree'
25
14
 
26
- class XML::Document
27
- include Enumerable
15
+ # Deprecated
16
+ require 'libxml/properties'
28
17
 
29
- # maybe, maybe not...
30
- def each(&blk)
31
- find('//*').each(&blk)
32
- end
33
- end
34
-
35
- class XML::Node::Set
36
- include Enumerable
37
-
38
- # inefficient, but maybe can find a way to cache the
39
- # ary and dump on change?
40
- def [](i, count = nil)
41
- if count
42
- to_a[i,count]
43
- else
44
- to_a[i]
45
- end
46
- end
47
-
48
- def to_s #:nodoc:
49
- to_a.to_s
50
- end
51
- end
52
-
53
- module XML::SiblingEnum
54
- def length
55
- inject(0) do |result, node|
56
- result + 1
57
- end
58
- end
59
-
60
- private
61
-
62
- # Iterates nodes and attributes
63
- def siblings(node, &blk)
64
- if n = node
65
- loop do
66
- blk.call(n)
67
- break unless n = n.next
68
- end
69
- end
70
- end
71
- end
72
-
73
- class XML::Node
74
- include XML::SiblingEnum
75
- include Enumerable
76
-
77
- # maybe these don't belong on all nodes...
78
- def each_child(&blk)
79
- siblings(child, &blk)
80
- end
81
-
82
- def each_attr(&blk)
83
- siblings(properties, &blk)
84
- end
85
-
86
- # all siblings INCLUDING self
87
- def each_sibling(&blk)
88
- siblings(self, &blk)
89
- end
90
-
91
- # I guess this is what you'd expect?
92
- alias :each :each_child
93
-
94
- def to_a
95
- inject([]) do |ary,n|
96
- ary << n
97
- ary
98
- end
99
- end
100
-
101
- def clone
102
- copy(false)
103
- end
104
- end
105
-
106
- class XML::Attr
107
- include XML::SiblingEnum
108
- include Enumerable
109
-
110
- def each_sibling(&blk)
111
- siblings(self,&blk)
112
- end
113
-
114
- alias :each_attr :each_sibling
115
- alias :each :each_sibling
116
-
117
- def to_h
118
- inject({}) do |h,a|
119
- h[a.name] = a.value
120
- h
121
- end
122
- end
123
-
124
- def to_a
125
- inject([]) do |ary,a|
126
- ary << [a.name, a.value]
127
- ary
128
- end
129
- end
130
-
131
- def to_s
132
- "#{name} = #{value}"
133
- end
18
+ # Map the LibXML module into the XML module for both backwards
19
+ # compatibility and ease of use.
20
+ module XML
21
+ include LibXML::XML
134
22
  end
@@ -0,0 +1,45 @@
1
+ # $Id: libxml.rb 374 2008-07-11 04:51:41Z cfis $
2
+ # Please see the LICENSE file for copyright and distribution information
3
+
4
+ module LibXML
5
+ module XML
6
+ class Attr
7
+ include Enumerable
8
+
9
+ # Iterates nodes and attributes
10
+ def siblings(node, &blk)
11
+ if n = node
12
+ loop do
13
+ blk.call(n)
14
+ break unless n = n.next
15
+ end
16
+ end
17
+ end
18
+
19
+ def each_sibling(&blk)
20
+ siblings(self,&blk)
21
+ end
22
+
23
+ alias :each_attr :each_sibling
24
+ alias :each :each_sibling
25
+
26
+ def to_h
27
+ inject({}) do |h,a|
28
+ h[a.name] = a.value
29
+ h
30
+ end
31
+ end
32
+
33
+ def to_a
34
+ inject([]) do |ary,a|
35
+ ary << [a.name, a.value]
36
+ ary
37
+ end
38
+ end
39
+
40
+ def to_s
41
+ "#{name} = #{value}"
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,15 @@
1
+ # $Id: libxml.rb 374 2008-07-11 04:51:41Z cfis $
2
+ # Please see the LICENSE file for copyright and distribution information
3
+
4
+ module LibXML
5
+ module XML
6
+ class Attributes
7
+ def to_h
8
+ inject({}) do |hash, attr|
9
+ hash[attr.name] = attr.value
10
+ hash
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,54 @@
1
+ # $Id: libxml.rb 374 2008-07-11 04:51:41Z cfis $
2
+ # Please see the LICENSE file for copyright and distribution information
3
+
4
+ module LibXML
5
+ module XML
6
+ class Document
7
+ # Return the nodes matching the specified xpath expression,
8
+ # optionally using the specified namespace. For more
9
+ # information about working with namespaces, please refer
10
+ # to the XML::XPath documentation.
11
+ #
12
+ # Parameters:
13
+ # * xpath - The xpath expression as a string
14
+ # * namespaces - An optional list of namespaces (see XML::XPath for information).
15
+ # * Returns - XML::XPath::Object
16
+ #
17
+ # document.find('/foo', 'xlink:http://www.w3.org/1999/xlink')
18
+ #
19
+ # IMPORTANT - The returned XML::Node::Set must be freed before
20
+ # its associated document. In a running Ruby program this will
21
+ # happen automatically via Ruby's mark and sweep garbage collector.
22
+ # However, if the program exits, Ruby does not guarantee the order
23
+ # in which objects are freed
24
+ # (see http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/17700).
25
+ # As a result, the associated document may be freed before the node
26
+ # list, which will cause a segmentation fault.
27
+ # To avoid this, use the following (non-ruby like) coding style:
28
+ #
29
+ # nodes = doc.find('/header')
30
+ # nodes.each do |node|
31
+ # ... do stuff ...
32
+ # end
33
+ #
34
+ # nodes = nil
35
+ # GC.start
36
+ #
37
+ def find(xpath, nslist = nil)
38
+ context = XPath::Context.new(self)
39
+ context.node = self.root
40
+ context.register_namespaces_from_node(self.root)
41
+ context.register_namespaces(nslist) if nslist
42
+
43
+ context.find(xpath)
44
+ end
45
+
46
+ # Return the first node matching the specified xpath expression.
47
+ # For more information, please refer to the documentation
48
+ # for XML::Document#find.
49
+ def find_first(xpath, nslist = nil)
50
+ find(xpath, nslist).first
51
+ end
52
+ end
53
+ end
54
+ end