libxml-ruby 2.9.0-x64-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/HISTORY +790 -0
- data/LICENSE +21 -0
- data/MANIFEST +166 -0
- data/README.rdoc +184 -0
- data/Rakefile +81 -0
- data/ext/libxml/extconf.h +4 -0
- data/ext/libxml/extconf.rb +57 -0
- data/ext/libxml/libxml.c +80 -0
- data/ext/libxml/libxml_ruby.def +35 -0
- data/ext/libxml/ruby_libxml.h +75 -0
- data/ext/libxml/ruby_xml.c +977 -0
- data/ext/libxml/ruby_xml.h +20 -0
- data/ext/libxml/ruby_xml_attr.c +333 -0
- data/ext/libxml/ruby_xml_attr.h +12 -0
- data/ext/libxml/ruby_xml_attr_decl.c +153 -0
- data/ext/libxml/ruby_xml_attr_decl.h +11 -0
- data/ext/libxml/ruby_xml_attributes.c +275 -0
- data/ext/libxml/ruby_xml_attributes.h +15 -0
- data/ext/libxml/ruby_xml_cbg.c +85 -0
- data/ext/libxml/ruby_xml_document.c +1133 -0
- data/ext/libxml/ruby_xml_document.h +11 -0
- data/ext/libxml/ruby_xml_dtd.c +261 -0
- data/ext/libxml/ruby_xml_dtd.h +9 -0
- data/ext/libxml/ruby_xml_encoding.c +262 -0
- data/ext/libxml/ruby_xml_encoding.h +19 -0
- data/ext/libxml/ruby_xml_error.c +996 -0
- data/ext/libxml/ruby_xml_error.h +12 -0
- data/ext/libxml/ruby_xml_html_parser.c +92 -0
- data/ext/libxml/ruby_xml_html_parser.h +10 -0
- data/ext/libxml/ruby_xml_html_parser_context.c +337 -0
- data/ext/libxml/ruby_xml_html_parser_context.h +10 -0
- data/ext/libxml/ruby_xml_html_parser_options.c +46 -0
- data/ext/libxml/ruby_xml_html_parser_options.h +10 -0
- data/ext/libxml/ruby_xml_input_cbg.c +191 -0
- data/ext/libxml/ruby_xml_input_cbg.h +20 -0
- data/ext/libxml/ruby_xml_io.c +52 -0
- data/ext/libxml/ruby_xml_io.h +10 -0
- data/ext/libxml/ruby_xml_namespace.c +153 -0
- data/ext/libxml/ruby_xml_namespace.h +10 -0
- data/ext/libxml/ruby_xml_namespaces.c +293 -0
- data/ext/libxml/ruby_xml_namespaces.h +9 -0
- data/ext/libxml/ruby_xml_node.c +1446 -0
- data/ext/libxml/ruby_xml_node.h +11 -0
- data/ext/libxml/ruby_xml_parser.c +94 -0
- data/ext/libxml/ruby_xml_parser.h +12 -0
- data/ext/libxml/ruby_xml_parser_context.c +999 -0
- data/ext/libxml/ruby_xml_parser_context.h +10 -0
- data/ext/libxml/ruby_xml_parser_options.c +66 -0
- data/ext/libxml/ruby_xml_parser_options.h +12 -0
- data/ext/libxml/ruby_xml_reader.c +1226 -0
- data/ext/libxml/ruby_xml_reader.h +17 -0
- data/ext/libxml/ruby_xml_relaxng.c +110 -0
- data/ext/libxml/ruby_xml_relaxng.h +10 -0
- data/ext/libxml/ruby_xml_sax2_handler.c +326 -0
- data/ext/libxml/ruby_xml_sax2_handler.h +10 -0
- data/ext/libxml/ruby_xml_sax_parser.c +120 -0
- data/ext/libxml/ruby_xml_sax_parser.h +10 -0
- data/ext/libxml/ruby_xml_schema.c +300 -0
- data/ext/libxml/ruby_xml_schema.h +809 -0
- data/ext/libxml/ruby_xml_schema_attribute.c +109 -0
- data/ext/libxml/ruby_xml_schema_attribute.h +15 -0
- data/ext/libxml/ruby_xml_schema_element.c +94 -0
- data/ext/libxml/ruby_xml_schema_element.h +14 -0
- data/ext/libxml/ruby_xml_schema_facet.c +52 -0
- data/ext/libxml/ruby_xml_schema_facet.h +13 -0
- data/ext/libxml/ruby_xml_schema_type.c +259 -0
- data/ext/libxml/ruby_xml_schema_type.h +9 -0
- data/ext/libxml/ruby_xml_version.h +9 -0
- data/ext/libxml/ruby_xml_writer.c +1136 -0
- data/ext/libxml/ruby_xml_writer.h +10 -0
- data/ext/libxml/ruby_xml_xinclude.c +16 -0
- data/ext/libxml/ruby_xml_xinclude.h +11 -0
- data/ext/libxml/ruby_xml_xpath.c +188 -0
- data/ext/libxml/ruby_xml_xpath.h +13 -0
- data/ext/libxml/ruby_xml_xpath_context.c +360 -0
- data/ext/libxml/ruby_xml_xpath_context.h +9 -0
- data/ext/libxml/ruby_xml_xpath_expression.c +81 -0
- data/ext/libxml/ruby_xml_xpath_expression.h +10 -0
- data/ext/libxml/ruby_xml_xpath_object.c +335 -0
- data/ext/libxml/ruby_xml_xpath_object.h +17 -0
- data/ext/libxml/ruby_xml_xpointer.c +99 -0
- data/ext/libxml/ruby_xml_xpointer.h +11 -0
- data/ext/vc/libxml_ruby.sln +26 -0
- data/lib/2.3/libxml_ruby.so +0 -0
- data/lib/libs/libiconv-2.dll +0 -0
- data/lib/libs/libxml2-2.dll +0 -0
- data/lib/libs/zlib1.dll +0 -0
- data/lib/libxml.rb +35 -0
- data/lib/libxml/attr.rb +123 -0
- data/lib/libxml/attr_decl.rb +80 -0
- data/lib/libxml/attributes.rb +14 -0
- data/lib/libxml/document.rb +194 -0
- data/lib/libxml/error.rb +95 -0
- data/lib/libxml/hpricot.rb +78 -0
- data/lib/libxml/html_parser.rb +96 -0
- data/lib/libxml/namespace.rb +62 -0
- data/lib/libxml/namespaces.rb +38 -0
- data/lib/libxml/node.rb +399 -0
- data/lib/libxml/ns.rb +22 -0
- data/lib/libxml/parser.rb +367 -0
- data/lib/libxml/properties.rb +23 -0
- data/lib/libxml/reader.rb +29 -0
- data/lib/libxml/sax_callbacks.rb +180 -0
- data/lib/libxml/sax_parser.rb +58 -0
- data/lib/libxml/schema.rb +67 -0
- data/lib/libxml/schema/attribute.rb +19 -0
- data/lib/libxml/schema/element.rb +27 -0
- data/lib/libxml/schema/type.rb +29 -0
- data/lib/libxml/tree.rb +29 -0
- data/lib/libxml/xpath_object.rb +16 -0
- data/lib/xml.rb +14 -0
- data/lib/xml/libxml.rb +10 -0
- data/libxml-ruby.gemspec +47 -0
- data/script/benchmark/depixelate +634 -0
- data/script/benchmark/hamlet.xml +9055 -0
- data/script/benchmark/parsecount +170 -0
- data/script/benchmark/sock_entries.xml +507 -0
- data/script/benchmark/throughput +41 -0
- data/script/test +6 -0
- data/setup.rb +1585 -0
- data/test/c14n/given/doc.dtd +1 -0
- data/test/c14n/given/example-1.xml +14 -0
- data/test/c14n/given/example-2.xml +11 -0
- data/test/c14n/given/example-3.xml +18 -0
- data/test/c14n/given/example-4.xml +9 -0
- data/test/c14n/given/example-5.xml +12 -0
- data/test/c14n/given/example-6.xml +2 -0
- data/test/c14n/given/example-7.xml +11 -0
- data/test/c14n/given/example-8.xml +11 -0
- data/test/c14n/given/example-8.xpath +10 -0
- data/test/c14n/given/world.txt +1 -0
- data/test/c14n/result/1-1-without-comments/example-1 +4 -0
- data/test/c14n/result/1-1-without-comments/example-2 +11 -0
- data/test/c14n/result/1-1-without-comments/example-3 +14 -0
- data/test/c14n/result/1-1-without-comments/example-4 +9 -0
- data/test/c14n/result/1-1-without-comments/example-5 +3 -0
- data/test/c14n/result/1-1-without-comments/example-6 +1 -0
- data/test/c14n/result/1-1-without-comments/example-7 +1 -0
- data/test/c14n/result/1-1-without-comments/example-8 +1 -0
- data/test/c14n/result/with-comments/example-1 +6 -0
- data/test/c14n/result/with-comments/example-2 +11 -0
- data/test/c14n/result/with-comments/example-3 +14 -0
- data/test/c14n/result/with-comments/example-4 +9 -0
- data/test/c14n/result/with-comments/example-5 +4 -0
- data/test/c14n/result/with-comments/example-6 +1 -0
- data/test/c14n/result/with-comments/example-7 +1 -0
- data/test/c14n/result/without-comments/example-1 +4 -0
- data/test/c14n/result/without-comments/example-2 +11 -0
- data/test/c14n/result/without-comments/example-3 +14 -0
- data/test/c14n/result/without-comments/example-4 +9 -0
- data/test/c14n/result/without-comments/example-5 +3 -0
- data/test/c14n/result/without-comments/example-6 +1 -0
- data/test/c14n/result/without-comments/example-7 +1 -0
- data/test/model/atom.xml +13 -0
- data/test/model/bands.iso-8859-1.xml +5 -0
- data/test/model/bands.utf-8.xml +5 -0
- data/test/model/bands.xml +5 -0
- data/test/model/books.xml +154 -0
- data/test/model/merge_bug_data.xml +58 -0
- data/test/model/ruby-lang.html +238 -0
- data/test/model/rubynet.xml +79 -0
- data/test/model/rubynet_project +1 -0
- data/test/model/shiporder.rnc +28 -0
- data/test/model/shiporder.rng +86 -0
- data/test/model/shiporder.xml +23 -0
- data/test/model/shiporder.xsd +40 -0
- data/test/model/soap.xml +27 -0
- data/test/model/xinclude.xml +5 -0
- data/test/tc_attr.rb +181 -0
- data/test/tc_attr_decl.rb +132 -0
- data/test/tc_attributes.rb +142 -0
- data/test/tc_canonicalize.rb +124 -0
- data/test/tc_deprecated_require.rb +12 -0
- data/test/tc_document.rb +125 -0
- data/test/tc_document_write.rb +195 -0
- data/test/tc_dtd.rb +128 -0
- data/test/tc_encoding.rb +126 -0
- data/test/tc_encoding_sax.rb +115 -0
- data/test/tc_error.rb +179 -0
- data/test/tc_html_parser.rb +161 -0
- data/test/tc_html_parser_context.rb +23 -0
- data/test/tc_namespace.rb +61 -0
- data/test/tc_namespaces.rb +209 -0
- data/test/tc_node.rb +215 -0
- data/test/tc_node_cdata.rb +50 -0
- data/test/tc_node_comment.rb +32 -0
- data/test/tc_node_copy.rb +41 -0
- data/test/tc_node_edit.rb +174 -0
- data/test/tc_node_pi.rb +39 -0
- data/test/tc_node_text.rb +70 -0
- data/test/tc_node_write.rb +107 -0
- data/test/tc_node_xlink.rb +28 -0
- data/test/tc_parser.rb +375 -0
- data/test/tc_parser_context.rb +204 -0
- data/test/tc_properties.rb +38 -0
- data/test/tc_reader.rb +399 -0
- data/test/tc_relaxng.rb +53 -0
- data/test/tc_sax_parser.rb +319 -0
- data/test/tc_schema.rb +161 -0
- data/test/tc_traversal.rb +152 -0
- data/test/tc_writer.rb +447 -0
- data/test/tc_xinclude.rb +20 -0
- data/test/tc_xml.rb +225 -0
- data/test/tc_xpath.rb +244 -0
- data/test/tc_xpath_context.rb +88 -0
- data/test/tc_xpath_expression.rb +37 -0
- data/test/tc_xpointer.rb +72 -0
- data/test/test_helper.rb +16 -0
- data/test/test_suite.rb +49 -0
- metadata +344 -0
data/lib/libxml/error.rb
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
module LibXML
|
4
|
+
module XML
|
5
|
+
class Error
|
6
|
+
# Create mapping from domain constant value to keys
|
7
|
+
DOMAIN_CODE_MAP = [:NO_ERROR, :PARSER, :TREE, :NAMESPACE, :DTD, :HTML, :MEMORY,
|
8
|
+
:OUTPUT, :IO, :FTP, :HTTP, :XINCLUDE, :XPATH, :XPOINTER, :REGEXP,
|
9
|
+
:DATATYPE, :SCHEMASP, :SCHEMASV, :RELAXNGP, :RELAXNGV, :CATALOG,
|
10
|
+
:C14N, :XSLT, :VALID, :CHECK, :WRITER, :MODULE, :I18N, :SCHEMATRONV].inject(Hash.new) do |hash, code|
|
11
|
+
if const_defined?(code)
|
12
|
+
hash[const_get(code)] = code.to_s
|
13
|
+
end
|
14
|
+
hash
|
15
|
+
end
|
16
|
+
|
17
|
+
# Create mapping from domain constant value to keys
|
18
|
+
ERROR_CODE_MAP = Hash.new.tap do |map|
|
19
|
+
(constants -
|
20
|
+
DOMAIN_CODE_MAP.values - #Domains
|
21
|
+
[:NONE, :WARNING, :ERROR, :FATAL] # Levels
|
22
|
+
).each do |code|
|
23
|
+
map[const_get(code)] = code.to_s
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# Verbose error handler
|
28
|
+
VERBOSE_HANDLER = lambda do |error|
|
29
|
+
STDERR << error.to_s << "\n"
|
30
|
+
STDERR.flush
|
31
|
+
end
|
32
|
+
|
33
|
+
# Quiet error handler
|
34
|
+
QUIET_HANDLER = lambda do |error|
|
35
|
+
end
|
36
|
+
|
37
|
+
def ==(other)
|
38
|
+
eql?(other)
|
39
|
+
end
|
40
|
+
|
41
|
+
def eql?(other)
|
42
|
+
self.code == other.code and
|
43
|
+
self.domain == other.domain and
|
44
|
+
self.message == other.message and
|
45
|
+
self.level == other.level and
|
46
|
+
self.file == other.file and
|
47
|
+
self.line == other.line and
|
48
|
+
self.str1 == other.str1 and
|
49
|
+
self.str2 == other.str2 and
|
50
|
+
self.str3 == other.str3 and
|
51
|
+
self.int1 == other.int1 and
|
52
|
+
self.int2 == other.int2 and
|
53
|
+
self.ctxt == other.ctxt and
|
54
|
+
self.node == other.node
|
55
|
+
rescue
|
56
|
+
false
|
57
|
+
end
|
58
|
+
|
59
|
+
def level_to_s
|
60
|
+
case self.level
|
61
|
+
when NONE
|
62
|
+
''
|
63
|
+
when WARNING
|
64
|
+
'Warning:'
|
65
|
+
when ERROR
|
66
|
+
'Error:'
|
67
|
+
when FATAL
|
68
|
+
'Fatal error:'
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def domain_to_s
|
73
|
+
DOMAIN_CODE_MAP[self.domain]
|
74
|
+
end
|
75
|
+
|
76
|
+
def code_to_s
|
77
|
+
ERROR_CODE_MAP[self.code]
|
78
|
+
end
|
79
|
+
|
80
|
+
def to_s
|
81
|
+
msg = super
|
82
|
+
msg = msg ? msg.strip: ''
|
83
|
+
|
84
|
+
if self.line
|
85
|
+
sprintf("%s %s at %s:%d.", self.level_to_s, msg,
|
86
|
+
self.file, self.line)
|
87
|
+
else
|
88
|
+
sprintf("%s %s.", self.level_to_s, msg)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
LibXML::XML::Error.set_handler(&LibXML::XML::Error::VERBOSE_HANDLER)
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
## Provide hpricot API for libxml. Provided by Michael Guterl,
|
4
|
+
## inspired by http://thebogles.com/blog/an-hpricot-style-interface-to-libxml
|
5
|
+
#
|
6
|
+
#class String
|
7
|
+
# def to_libxml_doc
|
8
|
+
# xp = XML::Parser.new
|
9
|
+
# xp.string = self
|
10
|
+
# xp.parse
|
11
|
+
# end
|
12
|
+
#end
|
13
|
+
#
|
14
|
+
#module LibXML
|
15
|
+
# module XML
|
16
|
+
# class Document
|
17
|
+
# alias :search :find
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
# class Node
|
21
|
+
# # find the child node with the given xpath
|
22
|
+
# def at(xpath)
|
23
|
+
# self.find_first(xpath)
|
24
|
+
# end
|
25
|
+
#
|
26
|
+
# # find the array of child nodes matching the given xpath
|
27
|
+
# def search(xpath)
|
28
|
+
# results = self.find(xpath).to_a
|
29
|
+
# if block_given?
|
30
|
+
# results.each do |result|
|
31
|
+
# yield result
|
32
|
+
# end
|
33
|
+
# end
|
34
|
+
# return results
|
35
|
+
# end
|
36
|
+
#
|
37
|
+
# def /(xpath)
|
38
|
+
# search(xpath)
|
39
|
+
# end
|
40
|
+
#
|
41
|
+
# # return the inner contents of this node as a string
|
42
|
+
# def inner_xml
|
43
|
+
# child.to_s
|
44
|
+
# end
|
45
|
+
#
|
46
|
+
# # alias for inner_xml
|
47
|
+
# def inner_html
|
48
|
+
# inner_xml
|
49
|
+
# end
|
50
|
+
#
|
51
|
+
# # return this node and its contents as an xml string
|
52
|
+
# def to_xml
|
53
|
+
# self.to_s
|
54
|
+
# end
|
55
|
+
#
|
56
|
+
# # alias for path
|
57
|
+
# def xpath
|
58
|
+
# self.path
|
59
|
+
# end
|
60
|
+
#
|
61
|
+
# def find_with_default_ns(xpath_expr, namespace=nil)
|
62
|
+
# find_base(xpath_expr, namespace || default_namespaces)
|
63
|
+
# end
|
64
|
+
#
|
65
|
+
# def find_first_with_default_ns(xpath_expr, namespace=nil)
|
66
|
+
# find_first_base(xpath_expr, namespace || default_namespaces)
|
67
|
+
# end
|
68
|
+
#
|
69
|
+
## alias_method :find_base, :find unless method_defined?(:find_base)
|
70
|
+
## alias_method :find, :find_with_default_ns
|
71
|
+
## alias_method :find_first_base, :find_first unless method_defined?(:find_first_base)
|
72
|
+
## alias_method :find_first, :find_first_with_default_ns
|
73
|
+
## alias :child? :first?
|
74
|
+
## alias :children? :first?
|
75
|
+
## alias :child :first
|
76
|
+
# end
|
77
|
+
# end
|
78
|
+
#end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
module LibXML
|
4
|
+
module XML
|
5
|
+
class HTMLParser
|
6
|
+
# call-seq:
|
7
|
+
# XML::HTMLParser.file(path) -> XML::HTMLParser
|
8
|
+
# XML::HTMLParser.file(path, :encoding => XML::Encoding::UTF_8,
|
9
|
+
# :options => XML::HTMLParser::Options::NOENT) -> XML::HTMLParser
|
10
|
+
#
|
11
|
+
# Creates a new parser by parsing the specified file or uri.
|
12
|
+
#
|
13
|
+
# You may provide an optional hash table to control how the
|
14
|
+
# parsing is performed. Valid options are:
|
15
|
+
#
|
16
|
+
# encoding - The document encoding, defaults to nil. Valid values
|
17
|
+
# are the encoding constants defined on XML::Encoding.
|
18
|
+
# options - Parser options. Valid values are the constants defined on
|
19
|
+
# XML::HTMLParser::Options. Mutliple options can be combined
|
20
|
+
# by using Bitwise OR (|).
|
21
|
+
def self.file(path, options = {})
|
22
|
+
context = XML::HTMLParser::Context.file(path)
|
23
|
+
context.encoding = options[:encoding] if options[:encoding]
|
24
|
+
context.options = options[:options] if options[:options]
|
25
|
+
self.new(context)
|
26
|
+
end
|
27
|
+
|
28
|
+
# call-seq:
|
29
|
+
# XML::HTMLParser.io(io) -> XML::HTMLParser
|
30
|
+
# XML::HTMLParser.io(io, :encoding => XML::Encoding::UTF_8,
|
31
|
+
# :options => XML::HTMLParser::Options::NOENT
|
32
|
+
# :base_uri="http://libxml.org") -> XML::HTMLParser
|
33
|
+
#
|
34
|
+
# Creates a new reader by parsing the specified io object.
|
35
|
+
#
|
36
|
+
# Parameters:
|
37
|
+
#
|
38
|
+
# io - io object that contains the xml to parser
|
39
|
+
# base_uri - The base url for the parsed document.
|
40
|
+
# encoding - The document encoding, defaults to nil. Valid values
|
41
|
+
# are the encoding constants defined on XML::Encoding.
|
42
|
+
# options - Parser options. Valid values are the constants defined on
|
43
|
+
# XML::HTMLParser::Options. Mutliple options can be combined
|
44
|
+
# by using Bitwise OR (|).
|
45
|
+
def self.io(io, options = {})
|
46
|
+
context = XML::HTMLParser::Context.io(io)
|
47
|
+
context.base_uri = options[:base_uri] if options[:base_uri]
|
48
|
+
context.encoding = options[:encoding] if options[:encoding]
|
49
|
+
context.options = options[:options] if options[:options]
|
50
|
+
self.new(context)
|
51
|
+
end
|
52
|
+
|
53
|
+
# call-seq:
|
54
|
+
# XML::HTMLParser.string(string)
|
55
|
+
# XML::HTMLParser.string(string, :encoding => XML::Encoding::UTF_8,
|
56
|
+
# :options => XML::HTMLParser::Options::NOENT
|
57
|
+
# :base_uri="http://libxml.org") -> XML::HTMLParser
|
58
|
+
#
|
59
|
+
# Creates a new parser by parsing the specified string.
|
60
|
+
#
|
61
|
+
# You may provide an optional hash table to control how the
|
62
|
+
# parsing is performed. Valid options are:
|
63
|
+
#
|
64
|
+
# base_uri - The base url for the parsed document.
|
65
|
+
# encoding - The document encoding, defaults to nil. Valid values
|
66
|
+
# are the encoding constants defined on XML::Encoding.
|
67
|
+
# options - Parser options. Valid values are the constants defined on
|
68
|
+
# XML::HTMLParser::Options. Mutliple options can be combined
|
69
|
+
# by using Bitwise OR (|).
|
70
|
+
def self.string(string, options = {})
|
71
|
+
context = XML::HTMLParser::Context.string(string)
|
72
|
+
context.base_uri = options[:base_uri] if options[:base_uri]
|
73
|
+
context.encoding = options[:encoding] if options[:encoding]
|
74
|
+
context.options = options[:options] if options[:options]
|
75
|
+
self.new(context)
|
76
|
+
end
|
77
|
+
|
78
|
+
# :enddoc:
|
79
|
+
|
80
|
+
def file=(value)
|
81
|
+
warn("XML::HTMLParser#file is deprecated. Use XML::HTMLParser.file instead")
|
82
|
+
@context = XML::HTMLParser::Context.file(value)
|
83
|
+
end
|
84
|
+
|
85
|
+
def io=(value)
|
86
|
+
warn("XML::HTMLParser#io is deprecated. Use XML::HTMLParser.io instead")
|
87
|
+
@context = XML::HTMLParser::Context.io(value)
|
88
|
+
end
|
89
|
+
|
90
|
+
def string=(value)
|
91
|
+
warn("XML::HTMLParser#string is deprecated. Use XML::HTMLParser.string instead")
|
92
|
+
@context = XML::HTMLParser::Context.string(value)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
module LibXML
|
4
|
+
module XML
|
5
|
+
class Namespace
|
6
|
+
include Comparable
|
7
|
+
include Enumerable
|
8
|
+
|
9
|
+
# call-seq:
|
10
|
+
# namespace1 <=> namespace2
|
11
|
+
#
|
12
|
+
# Compares two namespace objects. Namespace objects are
|
13
|
+
# considered equal if their prefixes and hrefs are the same.
|
14
|
+
def <=>(other)
|
15
|
+
if self.prefix.nil? and other.prefix.nil?
|
16
|
+
self.href <=> other.href
|
17
|
+
elsif self.prefix.nil?
|
18
|
+
-1
|
19
|
+
elsif other.prefix.nil?
|
20
|
+
1
|
21
|
+
else
|
22
|
+
self.prefix <=> other.prefix
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# call-seq:
|
27
|
+
# namespace.each {|ns| .. }
|
28
|
+
#
|
29
|
+
# libxml stores namespaces in memory as a linked list.
|
30
|
+
# Use the each method to iterate over the list. Note
|
31
|
+
# the first namespace in the loop is the current namespace.
|
32
|
+
#
|
33
|
+
# Usage:
|
34
|
+
# namespace.each do |ns|
|
35
|
+
# ..
|
36
|
+
# end
|
37
|
+
def each
|
38
|
+
ns = self
|
39
|
+
|
40
|
+
while ns
|
41
|
+
yield ns
|
42
|
+
ns = ns.next
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# call-seq:
|
47
|
+
# namespace.to_s -> "string"
|
48
|
+
#
|
49
|
+
# Returns the string represenation of a namespace.
|
50
|
+
#
|
51
|
+
# Usage:
|
52
|
+
# namespace.to_s
|
53
|
+
def to_s
|
54
|
+
if self.prefix
|
55
|
+
"#{self.prefix}:#{self.href}"
|
56
|
+
else
|
57
|
+
self.href
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
module LibXML
|
4
|
+
module XML
|
5
|
+
class Namespaces
|
6
|
+
# call-seq:
|
7
|
+
# namespace.default -> XML::Namespace
|
8
|
+
#
|
9
|
+
# Returns the default namespace for this node or nil.
|
10
|
+
#
|
11
|
+
# Usage:
|
12
|
+
# doc = XML::Document.string('<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"/>')
|
13
|
+
# ns = doc.root.namespaces.default_namespace
|
14
|
+
# assert_equal(ns.href, 'http://schemas.xmlsoap.org/soap/envelope/')
|
15
|
+
def default
|
16
|
+
find_by_prefix(nil)
|
17
|
+
end
|
18
|
+
|
19
|
+
# call-seq:
|
20
|
+
# namespace.default_prefix = "string"
|
21
|
+
#
|
22
|
+
# Assigns a name (prefix) to the default namespace.
|
23
|
+
# This makes it much easier to perform XML::XPath
|
24
|
+
# searches.
|
25
|
+
#
|
26
|
+
# Usage:
|
27
|
+
# doc = XML::Document.string('<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"/>')
|
28
|
+
# doc.root.namespaces.default_prefix = 'soap'
|
29
|
+
# node = doc.root.find_first('soap:Envelope')
|
30
|
+
def default_prefix=(prefix)
|
31
|
+
# Find default prefix
|
32
|
+
ns = find_by_prefix(nil)
|
33
|
+
raise(ArgumentError, "No default namespace was found") unless ns
|
34
|
+
Namespace.new(self.node, prefix, ns.href)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/libxml/node.rb
ADDED
@@ -0,0 +1,399 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'stringio'
|
4
|
+
|
5
|
+
module LibXML
|
6
|
+
module XML
|
7
|
+
class Node
|
8
|
+
# Determines whether this node has attributes
|
9
|
+
def attributes?
|
10
|
+
attributes.length > 0
|
11
|
+
end
|
12
|
+
|
13
|
+
# Create a shallow copy of the node. To create
|
14
|
+
# a deep copy call Node#copy(true)
|
15
|
+
def clone
|
16
|
+
copy(false)
|
17
|
+
end
|
18
|
+
|
19
|
+
# call-seq:
|
20
|
+
# node.inner_xml -> "string"
|
21
|
+
# node.inner_xml(:indent => true, :encoding => 'UTF-8', :level => 0) -> "string"
|
22
|
+
#
|
23
|
+
# Converts a node's children, to a string representation. To include
|
24
|
+
# the node, use XML::Node#to_s. For more information about
|
25
|
+
# the supported options, see XML::Node#to_s.
|
26
|
+
def inner_xml(options = Hash.new)
|
27
|
+
io = nil
|
28
|
+
self.each do |node|
|
29
|
+
xml = node.to_s(options)
|
30
|
+
# Create the string IO here since we now know the encoding
|
31
|
+
io = create_string_io(xml) unless io
|
32
|
+
io << xml
|
33
|
+
end
|
34
|
+
|
35
|
+
io ? io.string : nil
|
36
|
+
end
|
37
|
+
|
38
|
+
# :call-seq:
|
39
|
+
# node.dup -> XML::Node
|
40
|
+
#
|
41
|
+
# Create a shallow copy of the node. To create
|
42
|
+
# a deep copy call Node#copy(true)
|
43
|
+
def dup
|
44
|
+
copy(false)
|
45
|
+
end
|
46
|
+
|
47
|
+
# call-seq:
|
48
|
+
# node.context(namespaces=nil) -> XPath::Context
|
49
|
+
#
|
50
|
+
# Returns a new XML::XPathContext for the current node.
|
51
|
+
#
|
52
|
+
# Namespaces is an optional array of XML::NS objects
|
53
|
+
def context(nslist = nil)
|
54
|
+
if not self.doc
|
55
|
+
raise(TypeError, "A node must belong to a document before a xpath context can be created")
|
56
|
+
end
|
57
|
+
|
58
|
+
context = XPath::Context.new(self.doc)
|
59
|
+
context.node = self
|
60
|
+
context.register_namespaces_from_node(self)
|
61
|
+
context.register_namespaces_from_node(self.doc.root)
|
62
|
+
context.register_namespaces(nslist) if nslist
|
63
|
+
context
|
64
|
+
end
|
65
|
+
|
66
|
+
# call-seq:
|
67
|
+
# node.find(namespaces=nil) -> XPath::XPathObject
|
68
|
+
#
|
69
|
+
# Return nodes matching the specified xpath expression.
|
70
|
+
# For more information, please refer to the documentation
|
71
|
+
# for XML::Document#find.
|
72
|
+
#
|
73
|
+
# Namespaces is an optional array of XML::NS objects
|
74
|
+
def find(xpath, nslist = nil)
|
75
|
+
self.context(nslist).find(xpath)
|
76
|
+
end
|
77
|
+
|
78
|
+
# call-seq:
|
79
|
+
# node.find_first(namespaces=nil) -> XML::Node
|
80
|
+
#
|
81
|
+
# Return the first node matching the specified xpath expression.
|
82
|
+
# For more information, please refer to the documentation
|
83
|
+
# for the #find method.
|
84
|
+
def find_first(xpath, nslist = nil)
|
85
|
+
find(xpath, nslist).first
|
86
|
+
end
|
87
|
+
|
88
|
+
# call-seq:
|
89
|
+
# node.namespacess -> XML::Namespaces
|
90
|
+
#
|
91
|
+
# Returns this node's XML::Namespaces object,
|
92
|
+
# which is used to access the namespaces
|
93
|
+
# associated with this node.
|
94
|
+
def namespaces
|
95
|
+
@namespaces ||= XML::Namespaces.new(self)
|
96
|
+
end
|
97
|
+
|
98
|
+
# ------- Traversal ----------------
|
99
|
+
# Iterates over this node's attributes.
|
100
|
+
#
|
101
|
+
# doc = XML::Document.new('model/books.xml')
|
102
|
+
# doc.root.each_attr {|attr| puts attr}
|
103
|
+
def each_attr
|
104
|
+
attributes.each do |attr|
|
105
|
+
yield(attr)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
# Iterates over this node's child elements (nodes
|
110
|
+
# that have a node_type == ELEMENT_NODE).
|
111
|
+
#
|
112
|
+
# doc = XML::Document.new('model/books.xml')
|
113
|
+
# doc.root.each_element {|element| puts element}
|
114
|
+
def each_element
|
115
|
+
each do |node|
|
116
|
+
yield(node) if node.node_type == ELEMENT_NODE
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
# Determines whether this node has a parent node
|
121
|
+
def parent?
|
122
|
+
not parent.nil?
|
123
|
+
end
|
124
|
+
|
125
|
+
# Determines whether this node has a first node
|
126
|
+
def first?
|
127
|
+
not first.nil?
|
128
|
+
end
|
129
|
+
|
130
|
+
# Returns this node's children as an array.
|
131
|
+
def children
|
132
|
+
entries
|
133
|
+
end
|
134
|
+
|
135
|
+
# Determines whether this node has a next node
|
136
|
+
def next?
|
137
|
+
not self.next.nil?
|
138
|
+
end
|
139
|
+
|
140
|
+
# Determines whether this node has a previous node
|
141
|
+
def prev?
|
142
|
+
not prev.nil?
|
143
|
+
end
|
144
|
+
|
145
|
+
# Determines whether this node has a last node
|
146
|
+
def last?
|
147
|
+
not last.nil?
|
148
|
+
end
|
149
|
+
|
150
|
+
|
151
|
+
# ------- Node Types ----------------
|
152
|
+
|
153
|
+
# Returns this node's type name
|
154
|
+
def node_type_name
|
155
|
+
case node_type
|
156
|
+
# Most common choices first
|
157
|
+
when ATTRIBUTE_NODE
|
158
|
+
'attribute'
|
159
|
+
when DOCUMENT_NODE
|
160
|
+
'document_xml'
|
161
|
+
when ELEMENT_NODE
|
162
|
+
'element'
|
163
|
+
when TEXT_NODE
|
164
|
+
'text'
|
165
|
+
|
166
|
+
# Now the rest
|
167
|
+
when ATTRIBUTE_DECL
|
168
|
+
'attribute_decl'
|
169
|
+
when CDATA_SECTION_NODE
|
170
|
+
'cdata'
|
171
|
+
when COMMENT_NODE
|
172
|
+
'comment'
|
173
|
+
when DOCB_DOCUMENT_NODE
|
174
|
+
'document_docbook'
|
175
|
+
when DOCUMENT_FRAG_NODE
|
176
|
+
'fragment'
|
177
|
+
when DOCUMENT_TYPE_NODE
|
178
|
+
'doctype'
|
179
|
+
when DTD_NODE
|
180
|
+
'dtd'
|
181
|
+
when ELEMENT_DECL
|
182
|
+
'elem_decl'
|
183
|
+
when ENTITY_DECL
|
184
|
+
'entity_decl'
|
185
|
+
when ENTITY_NODE
|
186
|
+
'entity'
|
187
|
+
when ENTITY_REF_NODE
|
188
|
+
'entity_ref'
|
189
|
+
when HTML_DOCUMENT_NODE
|
190
|
+
'document_html'
|
191
|
+
when NAMESPACE_DECL
|
192
|
+
'namespace'
|
193
|
+
when NOTATION_NODE
|
194
|
+
'notation'
|
195
|
+
when PI_NODE
|
196
|
+
'pi'
|
197
|
+
when XINCLUDE_START
|
198
|
+
'xinclude_start'
|
199
|
+
when XINCLUDE_END
|
200
|
+
'xinclude_end'
|
201
|
+
else
|
202
|
+
raise(UnknownType, "Unknown node type: %n", node.node_type);
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
# Specifies if this is an attribute node
|
207
|
+
def attribute?
|
208
|
+
node_type == ATTRIBUTE_NODE
|
209
|
+
end
|
210
|
+
|
211
|
+
# Specifies if this is an attribute declaration node
|
212
|
+
def attribute_decl?
|
213
|
+
node_type == ATTRIBUTE_DECL
|
214
|
+
end
|
215
|
+
|
216
|
+
# Specifies if this is an CDATA node
|
217
|
+
def cdata?
|
218
|
+
node_type == CDATA_SECTION_NODE
|
219
|
+
end
|
220
|
+
|
221
|
+
# Specifies if this is an comment node
|
222
|
+
def comment?
|
223
|
+
node_type == COMMENT_NODE
|
224
|
+
end
|
225
|
+
|
226
|
+
# Specifies if this is an docbook node
|
227
|
+
def docbook_doc?
|
228
|
+
node_type == DOCB_DOCUMENT_NODE
|
229
|
+
end
|
230
|
+
|
231
|
+
# Specifies if this is an doctype node
|
232
|
+
def doctype?
|
233
|
+
node_type == DOCUMENT_TYPE_NODE
|
234
|
+
end
|
235
|
+
|
236
|
+
# Specifies if this is an document node
|
237
|
+
def document?
|
238
|
+
node_type == DOCUMENT_NODE
|
239
|
+
end
|
240
|
+
|
241
|
+
# Specifies if this is an DTD node
|
242
|
+
def dtd?
|
243
|
+
node_type == DTD_NODE
|
244
|
+
end
|
245
|
+
|
246
|
+
# Specifies if this is an element node
|
247
|
+
def element?
|
248
|
+
node_type == ELEMENT_NODE
|
249
|
+
end
|
250
|
+
|
251
|
+
# Specifies if this is an entity node
|
252
|
+
def entity?
|
253
|
+
node_type == ENTITY_NODE
|
254
|
+
end
|
255
|
+
|
256
|
+
# Specifies if this is an element declaration node
|
257
|
+
def element_decl?
|
258
|
+
node_type == ELEMENT_DECL
|
259
|
+
end
|
260
|
+
|
261
|
+
# Specifies if this is an entity reference node
|
262
|
+
def entity_ref?
|
263
|
+
node_type == ENTITY_REF_NODE
|
264
|
+
end
|
265
|
+
|
266
|
+
# Specifies if this is a fragment node
|
267
|
+
def fragment?
|
268
|
+
node_type == DOCUMENT_FRAG_NODE
|
269
|
+
end
|
270
|
+
|
271
|
+
# Specifies if this is a html document node
|
272
|
+
def html_doc?
|
273
|
+
node_type == HTML_DOCUMENT_NODE
|
274
|
+
end
|
275
|
+
|
276
|
+
# Specifies if this is a namespace node (not if it
|
277
|
+
# has a namepsace)
|
278
|
+
def namespace?
|
279
|
+
node_type == NAMESPACE_DECL
|
280
|
+
end
|
281
|
+
|
282
|
+
# Specifies if this is a notation node
|
283
|
+
def notation?
|
284
|
+
node_type == NOTATION_NODE
|
285
|
+
end
|
286
|
+
|
287
|
+
# Specifies if this is a processiong instruction node
|
288
|
+
def pi?
|
289
|
+
node_type == PI_NODE
|
290
|
+
end
|
291
|
+
|
292
|
+
# Specifies if this is a text node
|
293
|
+
def text?
|
294
|
+
node_type == TEXT_NODE
|
295
|
+
end
|
296
|
+
|
297
|
+
# Specifies if this is an xinclude end node
|
298
|
+
def xinclude_end?
|
299
|
+
node_type == XINCLUDE_END
|
300
|
+
end
|
301
|
+
|
302
|
+
# Specifies if this is an xinclude start node
|
303
|
+
def xinclude_start?
|
304
|
+
node_type == XINCLUDE_START
|
305
|
+
end
|
306
|
+
|
307
|
+
alias :child? :first?
|
308
|
+
alias :children? :first?
|
309
|
+
alias :child :first
|
310
|
+
alias :each_child :each
|
311
|
+
|
312
|
+
# --- Deprecated Output ---
|
313
|
+
# :stopdoc:
|
314
|
+
def dump
|
315
|
+
warn('Node#dump is deprecated. Use Node#to_s instead.')
|
316
|
+
self.to_s
|
317
|
+
end
|
318
|
+
|
319
|
+
# --- Deprecated DOM Manipulation ---
|
320
|
+
def child_add(node)
|
321
|
+
warn('Node#child_add is deprecated. Use Node#<< instead.')
|
322
|
+
self << node
|
323
|
+
end
|
324
|
+
|
325
|
+
def child=(node)
|
326
|
+
warn('Node#child= is deprecated. Use Node#<< instead.')
|
327
|
+
self << node
|
328
|
+
end
|
329
|
+
|
330
|
+
# --- Deprecated Namespaces ---
|
331
|
+
def namespace
|
332
|
+
warn('Node#namespace is deprecated. Use Node#namespaces instead.')
|
333
|
+
self.namespaces.entries
|
334
|
+
end
|
335
|
+
|
336
|
+
def namespace=(value)
|
337
|
+
warn('Node#namespace= is deprecated. Use Node#namespaces.namespace= instead.')
|
338
|
+
self.namespaces.namespace = value
|
339
|
+
end
|
340
|
+
|
341
|
+
def namespace_node
|
342
|
+
warn('Node#namespace_node is deprecated. Use Node#namespaces.namespace instead.')
|
343
|
+
self.namespaces.namespace
|
344
|
+
end
|
345
|
+
|
346
|
+
def ns
|
347
|
+
warn('Node#ns is deprecated. Use Node#namespaces.namespace instead.')
|
348
|
+
self.namespaces.namespace
|
349
|
+
end
|
350
|
+
|
351
|
+
def ns?
|
352
|
+
warn('Node#ns? is deprecated. Use !Node#namespaces.namespace.nil? instead.')
|
353
|
+
!self.namespaces.namespace.nil?
|
354
|
+
end
|
355
|
+
|
356
|
+
def ns_def
|
357
|
+
warn('Node#ns_def is deprecated. Use Node#namespaces.definitions instead.')
|
358
|
+
self.namespaces.definitions
|
359
|
+
end
|
360
|
+
|
361
|
+
def ns_def?
|
362
|
+
warn('Node#ns_def? is deprecated. Use !Node#namespaces.definitions.nil? instead.')
|
363
|
+
!self.namespaces.definitions.nil?
|
364
|
+
end
|
365
|
+
|
366
|
+
def base
|
367
|
+
warn('Node#base is deprecated. Use Node#base_uri.')
|
368
|
+
self.base_uri
|
369
|
+
end
|
370
|
+
|
371
|
+
def base=(value)
|
372
|
+
warn('Node#base= is deprecated. Use Node#base_uri=.')
|
373
|
+
self.base_uri = value
|
374
|
+
end
|
375
|
+
|
376
|
+
def search_ns(prefix)
|
377
|
+
warn('Node#search_ns is deprecated. Use Node#namespaces.find_by_prefix instead.')
|
378
|
+
self.namespaces.find_by_prefix(prefix)
|
379
|
+
end
|
380
|
+
|
381
|
+
def search_href(href)
|
382
|
+
warn('Node#search_href is deprecated. Use Node#namespaces.find_by_href instead.')
|
383
|
+
self.namespaces.find_by_href(href)
|
384
|
+
end
|
385
|
+
|
386
|
+
# :startdoc:
|
387
|
+
|
388
|
+
private
|
389
|
+
|
390
|
+
def create_string_io(xml)
|
391
|
+
result = StringIO.new("")
|
392
|
+
if defined?(::Encoding)
|
393
|
+
result.set_encoding(xml.encoding)
|
394
|
+
end
|
395
|
+
result
|
396
|
+
end
|
397
|
+
end
|
398
|
+
end
|
399
|
+
end
|