libxml-ruby 0.8.3 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +18 -0
- data/RAKEFILE +15 -39
- data/README +48 -47
- data/ext/libxml/libxml.c +847 -22
- data/ext/libxml/ruby_libxml.h +71 -95
- data/ext/libxml/ruby_xml_attr.c +500 -500
- data/ext/libxml/ruby_xml_attributes.c +1 -1
- data/ext/libxml/ruby_xml_document.c +1144 -1135
- data/ext/libxml/ruby_xml_document.h +4 -11
- data/ext/libxml/ruby_xml_dtd.c +27 -0
- data/ext/libxml/ruby_xml_encoding.c +164 -0
- data/ext/libxml/ruby_xml_encoding.h +13 -0
- data/ext/libxml/ruby_xml_error.c +941 -0
- data/ext/libxml/ruby_xml_error.h +13 -0
- data/ext/libxml/ruby_xml_html_parser.c +71 -387
- data/ext/libxml/ruby_xml_html_parser.h +1 -17
- data/ext/libxml/ruby_xml_input.c +179 -0
- data/ext/libxml/ruby_xml_input.h +18 -0
- data/ext/libxml/ruby_xml_input_cbg.c +17 -3
- data/ext/libxml/ruby_xml_node.c +1566 -1582
- data/ext/libxml/ruby_xml_node.h +1 -4
- data/ext/libxml/ruby_xml_ns.c +14 -3
- data/ext/libxml/ruby_xml_parser.c +164 -1398
- data/ext/libxml/ruby_xml_parser.h +5 -17
- data/ext/libxml/ruby_xml_parser_context.c +131 -169
- data/ext/libxml/ruby_xml_parser_context.h +2 -9
- data/ext/libxml/ruby_xml_reader.c +910 -945
- data/ext/libxml/ruby_xml_relaxng.c +32 -3
- data/ext/libxml/ruby_xml_sax_parser.c +106 -364
- data/ext/libxml/ruby_xml_sax_parser.h +1 -37
- data/ext/libxml/ruby_xml_schema.c +174 -145
- data/ext/libxml/ruby_xml_xinclude.c +9 -5
- data/ext/libxml/ruby_xml_xpath.c +25 -6
- data/ext/libxml/ruby_xml_xpath.h +1 -2
- data/ext/libxml/ruby_xml_xpath_context.c +17 -19
- data/ext/libxml/ruby_xml_xpath_object.c +60 -56
- data/ext/libxml/ruby_xml_xpointer.c +11 -5
- data/ext/libxml/sax_parser_callbacks.inc +42 -37
- data/ext/libxml/version.h +3 -3
- data/ext/mingw/Rakefile +20 -27
- data/ext/mingw/build.rake +41 -0
- data/ext/vc/libxml_ruby.vcproj +23 -15
- data/lib/libxml.rb +8 -2
- data/lib/libxml/document.rb +16 -4
- data/lib/libxml/error.rb +84 -0
- data/lib/libxml/hpricot.rb +76 -0
- data/lib/libxml/html_parser.rb +61 -0
- data/lib/libxml/node.rb +36 -25
- data/lib/libxml/parser.rb +312 -33
- data/lib/libxml/parser_context.rb +17 -0
- data/lib/libxml/properties.rb +15 -2
- data/lib/libxml/reader.rb +15 -0
- data/lib/libxml/sax_callbacks.rb +179 -0
- data/lib/libxml/sax_parser.rb +42 -0
- data/lib/libxml/tree.rb +1 -2
- data/lib/libxml/xpath_object.rb +12 -0
- data/test/model/atom.xml +4 -0
- data/test/tc_attributes.rb +43 -19
- data/test/tc_document.rb +1 -1
- data/test/tc_document_write.rb +15 -8
- data/test/tc_dtd.rb +36 -20
- data/test/tc_encoding.rb +13 -0
- data/test/tc_error.rb +136 -0
- data/test/tc_node.rb +2 -3
- data/test/tc_node_copy.rb +1 -1
- data/test/tc_node_edit.rb +6 -0
- data/test/tc_ns.rb +18 -0
- data/test/tc_parser.rb +113 -228
- data/test/tc_parser_context.rb +1 -2
- data/test/tc_reader.rb +24 -14
- data/test/tc_relaxng.rb +18 -6
- data/test/tc_sax_parser.rb +48 -13
- data/test/tc_schema.rb +20 -8
- data/test/tc_well_formed.rb +2 -1
- data/test/tc_xml.rb +212 -0
- data/test/tc_xpath.rb +60 -46
- data/test/tc_xpointer.rb +7 -11
- data/test/test_suite.rb +4 -3
- metadata +26 -109
- data/doc/rdoc/classes/LibXML.html +0 -241
- data/doc/rdoc/classes/LibXML/XML.html +0 -185
- data/doc/rdoc/classes/LibXML/XML/Attr.html +0 -1010
- data/doc/rdoc/classes/LibXML/XML/Attributes.html +0 -526
- data/doc/rdoc/classes/LibXML/XML/Document.html +0 -1489
- data/doc/rdoc/classes/LibXML/XML/Dtd.html +0 -213
- data/doc/rdoc/classes/LibXML/XML/Error.html +0 -117
- data/doc/rdoc/classes/LibXML/XML/HTMLParser.html +0 -348
- data/doc/rdoc/classes/LibXML/XML/InputCallbacks.html +0 -160
- data/doc/rdoc/classes/LibXML/XML/NS.html +0 -381
- data/doc/rdoc/classes/LibXML/XML/Node.html +0 -3396
- data/doc/rdoc/classes/LibXML/XML/Node/FailedModify.html +0 -123
- data/doc/rdoc/classes/LibXML/XML/Node/Set.html +0 -440
- data/doc/rdoc/classes/LibXML/XML/Node/SetNamespace.html +0 -123
- data/doc/rdoc/classes/LibXML/XML/Node/UnknownType.html +0 -123
- data/doc/rdoc/classes/LibXML/XML/Parser.html +0 -2239
- data/doc/rdoc/classes/LibXML/XML/Parser/Context.html +0 -1255
- data/doc/rdoc/classes/LibXML/XML/Parser/ParseError.html +0 -123
- data/doc/rdoc/classes/LibXML/XML/Reader.html +0 -2264
- data/doc/rdoc/classes/LibXML/XML/RelaxNG.html +0 -237
- data/doc/rdoc/classes/LibXML/XML/SaxParser.html +0 -415
- data/doc/rdoc/classes/LibXML/XML/Schema.html +0 -308
- data/doc/rdoc/classes/LibXML/XML/State.html +0 -124
- data/doc/rdoc/classes/LibXML/XML/Tree.html +0 -111
- data/doc/rdoc/classes/LibXML/XML/XInclude.html +0 -123
- data/doc/rdoc/classes/LibXML/XML/XInclude/Error.html +0 -117
- data/doc/rdoc/classes/LibXML/XML/XMLParserOptions.html +0 -198
- data/doc/rdoc/classes/LibXML/XML/XPath.html +0 -184
- data/doc/rdoc/classes/LibXML/XML/XPath/Context.html +0 -404
- data/doc/rdoc/classes/LibXML/XML/XPath/InvalidPath.html +0 -172
- data/doc/rdoc/classes/LibXML/XML/XPath/Object.html +0 -627
- data/doc/rdoc/classes/LibXML/XML/XPointer.html +0 -170
- data/doc/rdoc/classes/LibXML/XML/XPointer/Context.html +0 -123
- data/doc/rdoc/classes/LibXML/XML/XPointer/Context/InvalidPath.html +0 -117
- data/doc/rdoc/classes/LibXML/XML/XPointer/InvalidExpression.html +0 -124
- data/doc/rdoc/classes/singleton.html +0 -114
- data/doc/rdoc/created.rid +0 -1
- data/doc/rdoc/files/CHANGES.html +0 -442
- data/doc/rdoc/files/LICENSE.html +0 -133
- data/doc/rdoc/files/README.html +0 -388
- data/doc/rdoc/files/VERSION.html +0 -107
- data/doc/rdoc/files/ext/libxml/cbg_c.html +0 -101
- data/doc/rdoc/files/ext/libxml/libxml_c.html +0 -101
- data/doc/rdoc/files/ext/libxml/ruby_xml_attr_c.html +0 -101
- data/doc/rdoc/files/ext/libxml/ruby_xml_attributes_c.html +0 -101
- data/doc/rdoc/files/ext/libxml/ruby_xml_document_c.html +0 -101
- data/doc/rdoc/files/ext/libxml/ruby_xml_dtd_c.html +0 -101
- data/doc/rdoc/files/ext/libxml/ruby_xml_html_parser_c.html +0 -101
- data/doc/rdoc/files/ext/libxml/ruby_xml_input_cbg_c.html +0 -101
- data/doc/rdoc/files/ext/libxml/ruby_xml_node_c.html +0 -101
- data/doc/rdoc/files/ext/libxml/ruby_xml_node_set_c.html +0 -101
- data/doc/rdoc/files/ext/libxml/ruby_xml_ns_c.html +0 -101
- data/doc/rdoc/files/ext/libxml/ruby_xml_parser_c.html +0 -101
- data/doc/rdoc/files/ext/libxml/ruby_xml_parser_context_c.html +0 -101
- data/doc/rdoc/files/ext/libxml/ruby_xml_reader_c.html +0 -101
- data/doc/rdoc/files/ext/libxml/ruby_xml_relaxng_c.html +0 -101
- data/doc/rdoc/files/ext/libxml/ruby_xml_sax_parser_c.html +0 -101
- data/doc/rdoc/files/ext/libxml/ruby_xml_schema_c.html +0 -101
- data/doc/rdoc/files/ext/libxml/ruby_xml_state_c.html +0 -101
- data/doc/rdoc/files/ext/libxml/ruby_xml_xinclude_c.html +0 -101
- data/doc/rdoc/files/ext/libxml/ruby_xml_xpath_c.html +0 -101
- data/doc/rdoc/files/ext/libxml/ruby_xml_xpath_context_c.html +0 -101
- data/doc/rdoc/files/ext/libxml/ruby_xml_xpath_object_c.html +0 -101
- data/doc/rdoc/files/ext/libxml/ruby_xml_xpointer_c.html +0 -101
- data/doc/rdoc/files/ext/libxml/ruby_xml_xpointer_context_c.html +0 -101
- data/doc/rdoc/files/lib/libxml/attr_rb.html +0 -108
- data/doc/rdoc/files/lib/libxml/attributes_rb.html +0 -108
- data/doc/rdoc/files/lib/libxml/document_rb.html +0 -108
- data/doc/rdoc/files/lib/libxml/node_rb.html +0 -108
- data/doc/rdoc/files/lib/libxml/node_set_rb.html +0 -108
- data/doc/rdoc/files/lib/libxml/parser_options_rb.html +0 -107
- data/doc/rdoc/files/lib/libxml/parser_rb.html +0 -101
- data/doc/rdoc/files/lib/libxml/properties_rb.html +0 -108
- data/doc/rdoc/files/lib/libxml/tree_rb.html +0 -107
- data/doc/rdoc/files/lib/libxml_rb.html +0 -124
- data/doc/rdoc/files/lib/xml/libxml_rb.html +0 -124
- data/doc/rdoc/files/lib/xml_rb.html +0 -134
- data/doc/rdoc/fr_class_index.html +0 -62
- data/doc/rdoc/fr_file_index.html +0 -66
- data/doc/rdoc/fr_method_index.html +0 -392
- data/doc/rdoc/index.html +0 -24
- data/doc/rdoc/rdoc-style.css +0 -208
- data/ext/libxml/ruby_xml_node_set.c +0 -172
- data/ext/libxml/ruby_xml_node_set.h +0 -20
- data/ext/libxml/ruby_xml_xpointer_context.c +0 -22
- data/ext/libxml/ruby_xml_xpointer_context.h +0 -18
- data/lib/libxml/node_set.rb +0 -27
- data/test/tc_node_set.rb +0 -24
- data/test/tc_node_set2.rb +0 -37
data/ext/libxml/version.h
CHANGED
@@ -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.
|
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
|
-
#define RUBY_LIBXML_VER_MIC
|
7
|
+
#define RUBY_LIBXML_VER_MIN 9
|
8
|
+
#define RUBY_LIBXML_VER_MIC 0
|
9
9
|
#define RUBY_LIBXML_VER_PATCH 0
|
data/ext/mingw/Rakefile
CHANGED
@@ -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 '
|
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
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
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
|
-
|
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
|
data/ext/vc/libxml_ruby.vcproj
CHANGED
@@ -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.
|
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\
|
221
|
+
RelativePath="..\libxml\ruby_xml_input.c"
|
214
222
|
>
|
215
223
|
</File>
|
216
224
|
<File
|
217
|
-
RelativePath="..\libxml\
|
225
|
+
RelativePath="..\libxml\ruby_xml_input_cbg.c"
|
218
226
|
>
|
219
227
|
</File>
|
220
228
|
<File
|
221
|
-
RelativePath="..\libxml\
|
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\
|
323
|
+
RelativePath="..\libxml\ruby_xml_input.h"
|
312
324
|
>
|
313
325
|
</File>
|
314
326
|
<File
|
315
|
-
RelativePath="..\libxml\
|
327
|
+
RelativePath="..\libxml\ruby_xml_input_cbg.h"
|
316
328
|
>
|
317
329
|
</File>
|
318
330
|
<File
|
319
|
-
RelativePath="..\libxml\
|
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
|
>
|
data/lib/libxml.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# $Id: libxml.rb
|
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'
|
data/lib/libxml/document.rb
CHANGED
@@ -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
|
data/lib/libxml/error.rb
ADDED
@@ -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
|