libxml-ruby 0.8.3 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (168) hide show
  1. data/CHANGES +18 -0
  2. data/RAKEFILE +15 -39
  3. data/README +48 -47
  4. data/ext/libxml/libxml.c +847 -22
  5. data/ext/libxml/ruby_libxml.h +71 -95
  6. data/ext/libxml/ruby_xml_attr.c +500 -500
  7. data/ext/libxml/ruby_xml_attributes.c +1 -1
  8. data/ext/libxml/ruby_xml_document.c +1144 -1135
  9. data/ext/libxml/ruby_xml_document.h +4 -11
  10. data/ext/libxml/ruby_xml_dtd.c +27 -0
  11. data/ext/libxml/ruby_xml_encoding.c +164 -0
  12. data/ext/libxml/ruby_xml_encoding.h +13 -0
  13. data/ext/libxml/ruby_xml_error.c +941 -0
  14. data/ext/libxml/ruby_xml_error.h +13 -0
  15. data/ext/libxml/ruby_xml_html_parser.c +71 -387
  16. data/ext/libxml/ruby_xml_html_parser.h +1 -17
  17. data/ext/libxml/ruby_xml_input.c +179 -0
  18. data/ext/libxml/ruby_xml_input.h +18 -0
  19. data/ext/libxml/ruby_xml_input_cbg.c +17 -3
  20. data/ext/libxml/ruby_xml_node.c +1566 -1582
  21. data/ext/libxml/ruby_xml_node.h +1 -4
  22. data/ext/libxml/ruby_xml_ns.c +14 -3
  23. data/ext/libxml/ruby_xml_parser.c +164 -1398
  24. data/ext/libxml/ruby_xml_parser.h +5 -17
  25. data/ext/libxml/ruby_xml_parser_context.c +131 -169
  26. data/ext/libxml/ruby_xml_parser_context.h +2 -9
  27. data/ext/libxml/ruby_xml_reader.c +910 -945
  28. data/ext/libxml/ruby_xml_relaxng.c +32 -3
  29. data/ext/libxml/ruby_xml_sax_parser.c +106 -364
  30. data/ext/libxml/ruby_xml_sax_parser.h +1 -37
  31. data/ext/libxml/ruby_xml_schema.c +174 -145
  32. data/ext/libxml/ruby_xml_xinclude.c +9 -5
  33. data/ext/libxml/ruby_xml_xpath.c +25 -6
  34. data/ext/libxml/ruby_xml_xpath.h +1 -2
  35. data/ext/libxml/ruby_xml_xpath_context.c +17 -19
  36. data/ext/libxml/ruby_xml_xpath_object.c +60 -56
  37. data/ext/libxml/ruby_xml_xpointer.c +11 -5
  38. data/ext/libxml/sax_parser_callbacks.inc +42 -37
  39. data/ext/libxml/version.h +3 -3
  40. data/ext/mingw/Rakefile +20 -27
  41. data/ext/mingw/build.rake +41 -0
  42. data/ext/vc/libxml_ruby.vcproj +23 -15
  43. data/lib/libxml.rb +8 -2
  44. data/lib/libxml/document.rb +16 -4
  45. data/lib/libxml/error.rb +84 -0
  46. data/lib/libxml/hpricot.rb +76 -0
  47. data/lib/libxml/html_parser.rb +61 -0
  48. data/lib/libxml/node.rb +36 -25
  49. data/lib/libxml/parser.rb +312 -33
  50. data/lib/libxml/parser_context.rb +17 -0
  51. data/lib/libxml/properties.rb +15 -2
  52. data/lib/libxml/reader.rb +15 -0
  53. data/lib/libxml/sax_callbacks.rb +179 -0
  54. data/lib/libxml/sax_parser.rb +42 -0
  55. data/lib/libxml/tree.rb +1 -2
  56. data/lib/libxml/xpath_object.rb +12 -0
  57. data/test/model/atom.xml +4 -0
  58. data/test/tc_attributes.rb +43 -19
  59. data/test/tc_document.rb +1 -1
  60. data/test/tc_document_write.rb +15 -8
  61. data/test/tc_dtd.rb +36 -20
  62. data/test/tc_encoding.rb +13 -0
  63. data/test/tc_error.rb +136 -0
  64. data/test/tc_node.rb +2 -3
  65. data/test/tc_node_copy.rb +1 -1
  66. data/test/tc_node_edit.rb +6 -0
  67. data/test/tc_ns.rb +18 -0
  68. data/test/tc_parser.rb +113 -228
  69. data/test/tc_parser_context.rb +1 -2
  70. data/test/tc_reader.rb +24 -14
  71. data/test/tc_relaxng.rb +18 -6
  72. data/test/tc_sax_parser.rb +48 -13
  73. data/test/tc_schema.rb +20 -8
  74. data/test/tc_well_formed.rb +2 -1
  75. data/test/tc_xml.rb +212 -0
  76. data/test/tc_xpath.rb +60 -46
  77. data/test/tc_xpointer.rb +7 -11
  78. data/test/test_suite.rb +4 -3
  79. metadata +26 -109
  80. data/doc/rdoc/classes/LibXML.html +0 -241
  81. data/doc/rdoc/classes/LibXML/XML.html +0 -185
  82. data/doc/rdoc/classes/LibXML/XML/Attr.html +0 -1010
  83. data/doc/rdoc/classes/LibXML/XML/Attributes.html +0 -526
  84. data/doc/rdoc/classes/LibXML/XML/Document.html +0 -1489
  85. data/doc/rdoc/classes/LibXML/XML/Dtd.html +0 -213
  86. data/doc/rdoc/classes/LibXML/XML/Error.html +0 -117
  87. data/doc/rdoc/classes/LibXML/XML/HTMLParser.html +0 -348
  88. data/doc/rdoc/classes/LibXML/XML/InputCallbacks.html +0 -160
  89. data/doc/rdoc/classes/LibXML/XML/NS.html +0 -381
  90. data/doc/rdoc/classes/LibXML/XML/Node.html +0 -3396
  91. data/doc/rdoc/classes/LibXML/XML/Node/FailedModify.html +0 -123
  92. data/doc/rdoc/classes/LibXML/XML/Node/Set.html +0 -440
  93. data/doc/rdoc/classes/LibXML/XML/Node/SetNamespace.html +0 -123
  94. data/doc/rdoc/classes/LibXML/XML/Node/UnknownType.html +0 -123
  95. data/doc/rdoc/classes/LibXML/XML/Parser.html +0 -2239
  96. data/doc/rdoc/classes/LibXML/XML/Parser/Context.html +0 -1255
  97. data/doc/rdoc/classes/LibXML/XML/Parser/ParseError.html +0 -123
  98. data/doc/rdoc/classes/LibXML/XML/Reader.html +0 -2264
  99. data/doc/rdoc/classes/LibXML/XML/RelaxNG.html +0 -237
  100. data/doc/rdoc/classes/LibXML/XML/SaxParser.html +0 -415
  101. data/doc/rdoc/classes/LibXML/XML/Schema.html +0 -308
  102. data/doc/rdoc/classes/LibXML/XML/State.html +0 -124
  103. data/doc/rdoc/classes/LibXML/XML/Tree.html +0 -111
  104. data/doc/rdoc/classes/LibXML/XML/XInclude.html +0 -123
  105. data/doc/rdoc/classes/LibXML/XML/XInclude/Error.html +0 -117
  106. data/doc/rdoc/classes/LibXML/XML/XMLParserOptions.html +0 -198
  107. data/doc/rdoc/classes/LibXML/XML/XPath.html +0 -184
  108. data/doc/rdoc/classes/LibXML/XML/XPath/Context.html +0 -404
  109. data/doc/rdoc/classes/LibXML/XML/XPath/InvalidPath.html +0 -172
  110. data/doc/rdoc/classes/LibXML/XML/XPath/Object.html +0 -627
  111. data/doc/rdoc/classes/LibXML/XML/XPointer.html +0 -170
  112. data/doc/rdoc/classes/LibXML/XML/XPointer/Context.html +0 -123
  113. data/doc/rdoc/classes/LibXML/XML/XPointer/Context/InvalidPath.html +0 -117
  114. data/doc/rdoc/classes/LibXML/XML/XPointer/InvalidExpression.html +0 -124
  115. data/doc/rdoc/classes/singleton.html +0 -114
  116. data/doc/rdoc/created.rid +0 -1
  117. data/doc/rdoc/files/CHANGES.html +0 -442
  118. data/doc/rdoc/files/LICENSE.html +0 -133
  119. data/doc/rdoc/files/README.html +0 -388
  120. data/doc/rdoc/files/VERSION.html +0 -107
  121. data/doc/rdoc/files/ext/libxml/cbg_c.html +0 -101
  122. data/doc/rdoc/files/ext/libxml/libxml_c.html +0 -101
  123. data/doc/rdoc/files/ext/libxml/ruby_xml_attr_c.html +0 -101
  124. data/doc/rdoc/files/ext/libxml/ruby_xml_attributes_c.html +0 -101
  125. data/doc/rdoc/files/ext/libxml/ruby_xml_document_c.html +0 -101
  126. data/doc/rdoc/files/ext/libxml/ruby_xml_dtd_c.html +0 -101
  127. data/doc/rdoc/files/ext/libxml/ruby_xml_html_parser_c.html +0 -101
  128. data/doc/rdoc/files/ext/libxml/ruby_xml_input_cbg_c.html +0 -101
  129. data/doc/rdoc/files/ext/libxml/ruby_xml_node_c.html +0 -101
  130. data/doc/rdoc/files/ext/libxml/ruby_xml_node_set_c.html +0 -101
  131. data/doc/rdoc/files/ext/libxml/ruby_xml_ns_c.html +0 -101
  132. data/doc/rdoc/files/ext/libxml/ruby_xml_parser_c.html +0 -101
  133. data/doc/rdoc/files/ext/libxml/ruby_xml_parser_context_c.html +0 -101
  134. data/doc/rdoc/files/ext/libxml/ruby_xml_reader_c.html +0 -101
  135. data/doc/rdoc/files/ext/libxml/ruby_xml_relaxng_c.html +0 -101
  136. data/doc/rdoc/files/ext/libxml/ruby_xml_sax_parser_c.html +0 -101
  137. data/doc/rdoc/files/ext/libxml/ruby_xml_schema_c.html +0 -101
  138. data/doc/rdoc/files/ext/libxml/ruby_xml_state_c.html +0 -101
  139. data/doc/rdoc/files/ext/libxml/ruby_xml_xinclude_c.html +0 -101
  140. data/doc/rdoc/files/ext/libxml/ruby_xml_xpath_c.html +0 -101
  141. data/doc/rdoc/files/ext/libxml/ruby_xml_xpath_context_c.html +0 -101
  142. data/doc/rdoc/files/ext/libxml/ruby_xml_xpath_object_c.html +0 -101
  143. data/doc/rdoc/files/ext/libxml/ruby_xml_xpointer_c.html +0 -101
  144. data/doc/rdoc/files/ext/libxml/ruby_xml_xpointer_context_c.html +0 -101
  145. data/doc/rdoc/files/lib/libxml/attr_rb.html +0 -108
  146. data/doc/rdoc/files/lib/libxml/attributes_rb.html +0 -108
  147. data/doc/rdoc/files/lib/libxml/document_rb.html +0 -108
  148. data/doc/rdoc/files/lib/libxml/node_rb.html +0 -108
  149. data/doc/rdoc/files/lib/libxml/node_set_rb.html +0 -108
  150. data/doc/rdoc/files/lib/libxml/parser_options_rb.html +0 -107
  151. data/doc/rdoc/files/lib/libxml/parser_rb.html +0 -101
  152. data/doc/rdoc/files/lib/libxml/properties_rb.html +0 -108
  153. data/doc/rdoc/files/lib/libxml/tree_rb.html +0 -107
  154. data/doc/rdoc/files/lib/libxml_rb.html +0 -124
  155. data/doc/rdoc/files/lib/xml/libxml_rb.html +0 -124
  156. data/doc/rdoc/files/lib/xml_rb.html +0 -134
  157. data/doc/rdoc/fr_class_index.html +0 -62
  158. data/doc/rdoc/fr_file_index.html +0 -66
  159. data/doc/rdoc/fr_method_index.html +0 -392
  160. data/doc/rdoc/index.html +0 -24
  161. data/doc/rdoc/rdoc-style.css +0 -208
  162. data/ext/libxml/ruby_xml_node_set.c +0 -172
  163. data/ext/libxml/ruby_xml_node_set.h +0 -20
  164. data/ext/libxml/ruby_xml_xpointer_context.c +0 -22
  165. data/ext/libxml/ruby_xml_xpointer_context.h +0 -18
  166. data/lib/libxml/node_set.rb +0 -27
  167. data/test/tc_node_set.rb +0 -24
  168. data/test/tc_node_set2.rb +0 -37
@@ -1,9 +1,9 @@
1
1
  /* Don't nuke this block! It is used for automatically updating the
2
2
  * versions below. VERSION = string formatting, VERNUM = numbered
3
3
  * version for inline testing: increment both or none at all.*/
4
- #define RUBY_LIBXML_VERSION "0.8.3"
4
+ #define RUBY_LIBXML_VERSION "0.9.0"
5
5
  #define RUBY_LIBXML_VERNUM 0
6
6
  #define RUBY_LIBXML_VER_MAJ 0
7
- #define RUBY_LIBXML_VER_MIN 8
8
- #define RUBY_LIBXML_VER_MIC 3
7
+ #define RUBY_LIBXML_VER_MIN 9
8
+ #define RUBY_LIBXML_VER_MIC 0
9
9
  #define RUBY_LIBXML_VER_PATCH 0
@@ -3,39 +3,32 @@
3
3
  # built with VC++ while here we want to build
4
4
  # with MingW. So just roll our own...
5
5
 
6
- require 'rake/clean'
6
+ require 'fileutils'
7
7
  require 'rbconfig'
8
8
 
9
- RUBY_INCLUDE_DIR = Config::CONFIG["archdir"]
10
- RUBY_BIN_DIR = Config::CONFIG["bindir"]
11
- RUBY_LIB_DIR = Config::CONFIG["libdir"]
12
- RUBY_SHARED_LIB = Config::CONFIG["LIBRUBY"]
13
- RUBY_SHARED_DLL = RUBY_SHARED_LIB.gsub(/lib$/, 'dll')
14
-
15
9
  EXTENSION_NAME = "libxml_ruby.#{Config::CONFIG["DLEXT"]}"
10
+
16
11
  # MingW insists the import library is .dll.a
17
12
  EXTENSION_LIB_NAME = "libxml_ruby.dll.a"
18
13
 
19
- CLEAN.include('*.o')
20
- CLOBBER.include(EXTENSION_NAME)
21
- CLOBBER.include(EXTENSION_LIB_NAME)
22
-
23
- task :default => "libxml"
24
-
25
- SRC = FileList['../libxml/*.c']
26
- OBJ = SRC.collect do |file_name|
27
- File.basename(file_name).ext('o')
28
- end
29
-
30
- SRC.each do |srcfile|
31
- objfile = File.basename(srcfile).ext('o')
32
- file objfile => srcfile do
33
- command = "gcc -c -fPIC -O2 -Wall -o #{objfile} -I/usr/local/include #{srcfile} -I#{RUBY_INCLUDE_DIR}"
34
- sh "sh -c '#{command}'"
14
+ # This is called when the Windows GEM is installed!
15
+ task :install do
16
+ # Gems will pass these two environment variables:
17
+ # RUBYARCHDIR=#{dest_path}
18
+ # RUBYLIBDIR=#{dest_path}
19
+
20
+ dest_path = ENV['RUBYLIBDIR']
21
+
22
+ # Copy the extension
23
+ cp(EXTENSION_NAME, dest_path)
24
+
25
+ # Copy the import library (used by libxslt)
26
+ cp(EXTENSION_LIB_NAME, dest_path)
27
+
28
+ # Copy dllss
29
+ Dir.glob('*.dll').each do |dll|
30
+ cp(dll, dest_path)
35
31
  end
36
32
  end
37
33
 
38
- file "libxml" => OBJ do
39
- command = "gcc -shared -o #{EXTENSION_NAME} -Wl,--out-implib,#{EXTENSION_LIB_NAME} -L/usr/local/lib #{OBJ} -lxml2 #{RUBY_BIN_DIR}/#{RUBY_SHARED_DLL}"
40
- sh "sh -c '#{command}'"
41
- end
34
+ task :default => :install
@@ -0,0 +1,41 @@
1
+ # We can't use Ruby's standard build procedures
2
+ # on Windows because the Ruby executable is
3
+ # built with VC++ while here we want to build
4
+ # with MingW. So just roll our own...
5
+
6
+ require 'rake/clean'
7
+ require 'rbconfig'
8
+
9
+ RUBY_INCLUDE_DIR = Config::CONFIG["archdir"]
10
+ RUBY_BIN_DIR = Config::CONFIG["bindir"]
11
+ RUBY_LIB_DIR = Config::CONFIG["libdir"]
12
+ RUBY_SHARED_LIB = Config::CONFIG["LIBRUBY"]
13
+ RUBY_SHARED_DLL = RUBY_SHARED_LIB.gsub(/lib$/, 'dll')
14
+
15
+ EXTENSION_NAME = "libxml_ruby.#{Config::CONFIG["DLEXT"]}"
16
+ # MingW insists the import library is .dll.a
17
+ EXTENSION_LIB_NAME = "libxml_ruby.dll.a"
18
+
19
+ CLEAN.include('*.o')
20
+ CLOBBER.include(EXTENSION_NAME)
21
+ CLOBBER.include(EXTENSION_LIB_NAME)
22
+
23
+ task :default => "libxml"
24
+
25
+ SRC = FileList['../libxml/*.c']
26
+ OBJ = SRC.collect do |file_name|
27
+ File.basename(file_name).ext('o')
28
+ end
29
+
30
+ SRC.each do |srcfile|
31
+ objfile = File.basename(srcfile).ext('o')
32
+ file objfile => srcfile do
33
+ command = "gcc -c -O2 -Wall -o #{objfile} -I/usr/local/include #{srcfile} -I#{RUBY_INCLUDE_DIR}"
34
+ sh "sh -c '#{command}'"
35
+ end
36
+ end
37
+
38
+ file "libxml" => OBJ do
39
+ command = "gcc -shared -o #{EXTENSION_NAME} -Wl,--out-implib,#{EXTENSION_LIB_NAME} -L/usr/local/lib #{OBJ} -lxml2 #{RUBY_BIN_DIR}/#{RUBY_SHARED_DLL}"
40
+ sh "sh -c '#{command}'"
41
+ end
@@ -63,7 +63,7 @@
63
63
  <Tool
64
64
  Name="VCLinkerTool"
65
65
  AdditionalDependencies="msvcrt-ruby18.lib libxml2.lib"
66
- OutputFile="C:\Development\ruby\lib\ruby\gems\1.8\gems\libxml-ruby-0.8.2-x86-mswin32-60\lib\$(ProjectName).so"
66
+ OutputFile="C:\Development\ruby\lib\ruby\gems\1.8\gems\libxml-ruby-0.9.0-x86-mswin32-60\lib\$(ProjectName).so"
67
67
  LinkIncremental="2"
68
68
  AdditionalLibraryDirectories="C:\Development\ruby\lib;C:\Development\msys\local\lib"
69
69
  GenerateDebugInformation="true"
@@ -205,20 +205,28 @@
205
205
  RelativePath="..\libxml\ruby_xml_dtd.c"
206
206
  >
207
207
  </File>
208
+ <File
209
+ RelativePath="..\libxml\ruby_xml_encoding.c"
210
+ >
211
+ </File>
212
+ <File
213
+ RelativePath="..\libxml\ruby_xml_error.c"
214
+ >
215
+ </File>
208
216
  <File
209
217
  RelativePath="..\libxml\ruby_xml_html_parser.c"
210
218
  >
211
219
  </File>
212
220
  <File
213
- RelativePath="..\libxml\ruby_xml_input_cbg.c"
221
+ RelativePath="..\libxml\ruby_xml_input.c"
214
222
  >
215
223
  </File>
216
224
  <File
217
- RelativePath="..\libxml\ruby_xml_node.c"
225
+ RelativePath="..\libxml\ruby_xml_input_cbg.c"
218
226
  >
219
227
  </File>
220
228
  <File
221
- RelativePath="..\libxml\ruby_xml_node_set.c"
229
+ RelativePath="..\libxml\ruby_xml_node.c"
222
230
  >
223
231
  </File>
224
232
  <File
@@ -273,10 +281,6 @@
273
281
  RelativePath="..\libxml\ruby_xml_xpointer.c"
274
282
  >
275
283
  </File>
276
- <File
277
- RelativePath="..\libxml\ruby_xml_xpointer_context.c"
278
- >
279
- </File>
280
284
  </Filter>
281
285
  <Filter
282
286
  Name="Header Files"
@@ -303,20 +307,28 @@
303
307
  RelativePath="..\libxml\ruby_xml_dtd.h"
304
308
  >
305
309
  </File>
310
+ <File
311
+ RelativePath="..\libxml\ruby_xml_encoding.h"
312
+ >
313
+ </File>
314
+ <File
315
+ RelativePath="..\libxml\ruby_xml_error.h"
316
+ >
317
+ </File>
306
318
  <File
307
319
  RelativePath="..\libxml\ruby_xml_html_parser.h"
308
320
  >
309
321
  </File>
310
322
  <File
311
- RelativePath="..\libxml\ruby_xml_input_cbg.h"
323
+ RelativePath="..\libxml\ruby_xml_input.h"
312
324
  >
313
325
  </File>
314
326
  <File
315
- RelativePath="..\libxml\ruby_xml_node.h"
327
+ RelativePath="..\libxml\ruby_xml_input_cbg.h"
316
328
  >
317
329
  </File>
318
330
  <File
319
- RelativePath="..\libxml\ruby_xml_node_set.h"
331
+ RelativePath="..\libxml\ruby_xml_node.h"
320
332
  >
321
333
  </File>
322
334
  <File
@@ -371,10 +383,6 @@
371
383
  RelativePath="..\libxml\ruby_xml_xpointer.h"
372
384
  >
373
385
  </File>
374
- <File
375
- RelativePath="..\libxml\ruby_xml_xpointer_context.h"
376
- >
377
- </File>
378
386
  <File
379
387
  RelativePath="..\libxml\version.h"
380
388
  >
@@ -1,4 +1,4 @@
1
- # $Id: libxml.rb 509 2008-07-22 02:11:00Z cfis $
1
+ # $Id: libxml.rb 561 2008-11-18 04:17:29Z cfis $
2
2
  # Please see the LICENSE file for copyright and distribution information
3
3
 
4
4
  # If running on Windows, then add the current directory to the PATH
@@ -12,14 +12,20 @@ end
12
12
  require 'libxml_ruby'
13
13
 
14
14
  # Load Ruby supporting code.
15
+ require 'libxml/error'
15
16
  require 'libxml/parser'
16
17
  require 'libxml/parser_options'
18
+ require 'libxml/parser_context'
17
19
  require 'libxml/document'
18
20
  require 'libxml/node'
19
- require 'libxml/node_set'
20
21
  require 'libxml/attributes'
21
22
  require 'libxml/attr'
22
23
  require 'libxml/tree'
24
+ require 'libxml/reader'
25
+ require 'libxml/html_parser'
26
+ require 'libxml/sax_parser'
27
+ require 'libxml/sax_callbacks'
28
+ require 'libxml/xpath_object'
23
29
 
24
30
  # Deprecated
25
31
  require 'libxml/properties'
@@ -1,9 +1,22 @@
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
1
  module LibXML
5
2
  module XML
6
3
  class Document
4
+ def self.file(value)
5
+ Parser.file(value).parse
6
+ end
7
+
8
+ def self.string(value)
9
+ Parser.string(value).parse
10
+ end
11
+
12
+ def self.document(value)
13
+ Parser.document(value).parse
14
+ end
15
+
16
+ def self.io(value)
17
+ Parser.io(value).parse
18
+ end
19
+
7
20
  # Return the nodes matching the specified xpath expression,
8
21
  # optionally using the specified namespace. For more
9
22
  # information about working with namespaces, please refer
@@ -33,7 +46,6 @@ module LibXML
33
46
  #
34
47
  # nodes = nil
35
48
  # GC.start
36
- #
37
49
  def find(xpath, nslist = nil)
38
50
  context = XPath::Context.new(self)
39
51
  context.node = self.root
@@ -0,0 +1,84 @@
1
+ module LibXML
2
+ module XML
3
+ class Error
4
+ # Verbose error handler
5
+ VERBOSE_HANDLER = lambda do |error|
6
+ STDERR << error.to_s << "\n"
7
+ STDERR.flush
8
+ end
9
+
10
+ # Quiet error handler
11
+ QUIET_HANDLER = lambda do |error|
12
+ end
13
+
14
+ def ==(other)
15
+ eql?(other)
16
+ end
17
+
18
+ def eql?(other)
19
+ self.code == other.code and
20
+ self.domain == other.domain and
21
+ self.message == other.message and
22
+ self.level == other.level and
23
+ self.file == other.file and
24
+ self.line == other.line and
25
+ self.str1 == other.str1 and
26
+ self.str2 == other.str2 and
27
+ self.str3 == other.str3 and
28
+ self.int1 == other.int1 and
29
+ self.int2 == other.int2 and
30
+ self.ctxt == other.ctxt and
31
+ self.node == other.node
32
+ end
33
+
34
+ def level_to_s
35
+ case self.level
36
+ when NONE:
37
+ ''
38
+ when WARNING:
39
+ 'Warning:'
40
+ when ERROR:
41
+ 'Error:'
42
+ when FATAL:
43
+ 'Fatal error:'
44
+ end
45
+ end
46
+
47
+ def domain_to_s
48
+ const_map = Hash.new
49
+ domains = self.class.constants.grep(/XML_FROM/)
50
+ domains.each do |domain|
51
+ human_name = domain.gsub(/XML_FROM_/, '')
52
+ const_map[self.class.const_get(domain)] = human_name
53
+ end
54
+
55
+ const_map[self.domain]
56
+ end
57
+
58
+ def code_to_s
59
+ const_map = Hash.new
60
+ codes = self.class.constants -
61
+ self.class.constants.grep(/XML_FROM/) -
62
+ ["XML_ERR_NONE", "XML_ERR_WARNING", "XML_ERR_ERROR", "XML_ERR_FATAL"]
63
+
64
+
65
+ codes.each do |code|
66
+ human_name = code.gsub(/XML_ERR_/, '')
67
+ const_map[self.class.const_get(code)] = human_name
68
+ end
69
+
70
+ const_map[self.code]
71
+ end
72
+
73
+ def to_s
74
+ msg = super
75
+ msg = msg ? msg.strip: ''
76
+
77
+ sprintf("%s %s at %s:%d.", self.level_to_s, msg,
78
+ self.file, self.line)
79
+ end
80
+ end
81
+ end
82
+ end
83
+
84
+ LibXML::XML::Error.set_handler(&LibXML::XML::Error::VERBOSE_HANDLER)
@@ -0,0 +1,76 @@
1
+ # Provide hpricot API for libxml. Provided by Michael Guterl,
2
+ # inspired by http://thebogles.com/blog/an-hpricot-style-interface-to-libxml
3
+
4
+ class String
5
+ def to_libxml_doc
6
+ xp = XML::Parser.new
7
+ xp.string = self
8
+ xp.parse
9
+ end
10
+ end
11
+
12
+ module LibXML
13
+ module XML
14
+ class Document
15
+ alias :search :find
16
+ end
17
+
18
+ class Node
19
+ # find the child node with the given xpath
20
+ def at(xpath)
21
+ self.find_first(xpath)
22
+ end
23
+
24
+ # find the array of child nodes matching the given xpath
25
+ def search(xpath)
26
+ results = self.find(xpath).to_a
27
+ if block_given?
28
+ results.each do |result|
29
+ yield result
30
+ end
31
+ end
32
+ return results
33
+ end
34
+
35
+ def /(xpath)
36
+ search(xpath)
37
+ end
38
+
39
+ # return the inner contents of this node as a string
40
+ def inner_xml
41
+ child.to_s
42
+ end
43
+
44
+ # alias for inner_xml
45
+ def inner_html
46
+ inner_xml
47
+ end
48
+
49
+ # return this node and its contents as an xml string
50
+ def to_xml
51
+ self.to_s
52
+ end
53
+
54
+ # alias for path
55
+ def xpath
56
+ self.path
57
+ end
58
+
59
+ def find_with_default_ns(xpath_expr, namespace=nil)
60
+ find_base(xpath_expr, namespace || default_namespaces)
61
+ end
62
+
63
+ def find_first_with_default_ns(xpath_expr, namespace=nil)
64
+ find_first_base(xpath_expr, namespace || default_namespaces)
65
+ end
66
+
67
+ # alias_method :find_base, :find unless method_defined?(:find_base)
68
+ # alias_method :find, :find_with_default_ns
69
+ # alias_method :find_first_base, :find_first unless method_defined?(:find_first_base)
70
+ # alias_method :find_first, :find_first_with_default_ns
71
+ # alias :child? :first?
72
+ # alias :children? :first?
73
+ # alias :child :first
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,61 @@
1
+ module LibXML
2
+ module XML
3
+ class HTMLParser
4
+ def self.file(value)
5
+ parser = Parser.new
6
+ parser.input.file = value
7
+ parser
8
+ end
9
+
10
+ def self.string(value)
11
+ parser = Parser.new
12
+ parser.input.string = value
13
+ parser
14
+ end
15
+
16
+ def self.document(value)
17
+ parser = Parser.new
18
+ parser.input.document = value
19
+ parser
20
+ end
21
+
22
+ def self.io(value)
23
+ parser = Parser.new
24
+ parser.input.io = value
25
+ parser
26
+ end
27
+
28
+ def file
29
+ input.filename
30
+ end
31
+
32
+ def file=(value)
33
+ input.file = value
34
+ end
35
+
36
+ def string
37
+ input.string
38
+ end
39
+
40
+ def string=(value)
41
+ input.string = value
42
+ end
43
+
44
+ def document
45
+ input.document
46
+ end
47
+
48
+ def document=(value)
49
+ input.document = value
50
+ end
51
+
52
+ def io
53
+ input.io
54
+ end
55
+
56
+ def io=(value)
57
+ input.io = value
58
+ end
59
+ end
60
+ end
61
+ end