libxml-ruby 5.0.4 → 5.0.5
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.
- checksums.yaml +4 -4
- data/HISTORY +10 -6
- data/README.rdoc +1 -1
- data/ext/libxml/extconf.rb +5 -0
- data/ext/libxml/ruby_xml.c +556 -556
- data/ext/libxml/ruby_xml_attributes.h +17 -17
- data/ext/libxml/ruby_xml_document.c +1129 -1129
- data/ext/libxml/ruby_xml_dtd.c +257 -257
- data/ext/libxml/ruby_xml_encoding.c +250 -250
- data/ext/libxml/ruby_xml_error.c +1003 -1003
- data/ext/libxml/ruby_xml_error.h +14 -14
- data/ext/libxml/ruby_xml_html_parser_context.c +351 -351
- data/ext/libxml/ruby_xml_input_cbg.c +188 -188
- data/ext/libxml/ruby_xml_namespace.c +151 -151
- data/ext/libxml/ruby_xml_parser.h +10 -10
- data/ext/libxml/ruby_xml_parser_context.c +1009 -1009
- data/ext/libxml/ruby_xml_parser_options.c +74 -74
- data/ext/libxml/ruby_xml_parser_options.h +10 -10
- data/ext/libxml/ruby_xml_sax2_handler.c +326 -326
- data/ext/libxml/ruby_xml_sax_parser.c +108 -108
- data/ext/libxml/ruby_xml_version.h +9 -9
- data/lib/libxml/attr.rb +122 -122
- data/lib/libxml/attr_decl.rb +80 -80
- data/lib/libxml/attributes.rb +13 -13
- data/lib/libxml/document.rb +194 -194
- data/lib/libxml/error.rb +95 -95
- data/lib/libxml/hpricot.rb +77 -77
- data/lib/libxml/html_parser.rb +96 -96
- data/lib/libxml/namespace.rb +61 -61
- data/lib/libxml/namespaces.rb +37 -37
- data/lib/libxml/node.rb +323 -323
- data/lib/libxml/parser.rb +102 -102
- data/lib/libxml/sax_callbacks.rb +179 -179
- data/lib/libxml/sax_parser.rb +40 -40
- data/lib/libxml/tree.rb +28 -28
- data/lib/libxml.rb +4 -4
- data/lib/xml/libxml.rb +10 -10
- data/lib/xml.rb +13 -13
- data/libxml-ruby.gemspec +50 -49
- data/test/test_document.rb +140 -140
- data/test/test_document_write.rb +142 -142
- data/test/test_dtd.rb +126 -126
- data/test/test_encoding.rb +126 -126
- data/test/test_error.rb +194 -194
- data/test/test_helper.rb +20 -20
- data/test/test_namespace.rb +58 -58
- data/test/test_node.rb +235 -235
- data/test/test_node_write.rb +93 -93
- data/test/test_parser.rb +333 -333
- data/test/test_reader.rb +364 -364
- data/test/test_xml.rb +168 -168
- metadata +5 -4
data/lib/libxml/tree.rb
CHANGED
@@ -1,29 +1,29 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
module LibXML
|
4
|
-
module XML
|
5
|
-
class Tree # :nodoc:
|
6
|
-
ELEMENT_NODE = Node::ELEMENT_NODE
|
7
|
-
ATTRIBUTE_NODE = Node::ATTRIBUTE_NODE
|
8
|
-
TEXT_NODE = Node::TEXT_NODE
|
9
|
-
CDATA_SECTION_NODE = Node::CDATA_SECTION_NODE
|
10
|
-
ENTITY_REF_NODE = Node::ENTITY_REF_NODE
|
11
|
-
ENTITY_NODE = Node::ENTITY_NODE
|
12
|
-
PI_NODE = Node::PI_NODE
|
13
|
-
COMMENT_NODE = Node::COMMENT_NODE
|
14
|
-
DOCUMENT_NODE = Node::DOCUMENT_NODE
|
15
|
-
DOCUMENT_TYPE_NODE = Node::DOCUMENT_TYPE_NODE
|
16
|
-
DOCUMENT_FRAG_NODE = Node::DOCUMENT_FRAG_NODE
|
17
|
-
NOTATION_NODE = Node::NOTATION_NODE
|
18
|
-
HTML_DOCUMENT_NODE = Node::HTML_DOCUMENT_NODE
|
19
|
-
DTD_NODE = Node::DTD_NODE
|
20
|
-
ELEMENT_DECL = Node::ELEMENT_DECL
|
21
|
-
ATTRIBUTE_DECL = Node::ATTRIBUTE_DECL
|
22
|
-
ENTITY_DECL = Node::ENTITY_DECL
|
23
|
-
NAMESPACE_DECL = Node::NAMESPACE_DECL
|
24
|
-
XINCLUDE_START = Node::XINCLUDE_START
|
25
|
-
XINCLUDE_END = Node::XINCLUDE_END
|
26
|
-
DOCB_DOCUMENT_NODE = Node::DOCB_DOCUMENT_NODE
|
27
|
-
end
|
28
|
-
end
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
module LibXML
|
4
|
+
module XML
|
5
|
+
class Tree # :nodoc:
|
6
|
+
ELEMENT_NODE = Node::ELEMENT_NODE
|
7
|
+
ATTRIBUTE_NODE = Node::ATTRIBUTE_NODE
|
8
|
+
TEXT_NODE = Node::TEXT_NODE
|
9
|
+
CDATA_SECTION_NODE = Node::CDATA_SECTION_NODE
|
10
|
+
ENTITY_REF_NODE = Node::ENTITY_REF_NODE
|
11
|
+
ENTITY_NODE = Node::ENTITY_NODE
|
12
|
+
PI_NODE = Node::PI_NODE
|
13
|
+
COMMENT_NODE = Node::COMMENT_NODE
|
14
|
+
DOCUMENT_NODE = Node::DOCUMENT_NODE
|
15
|
+
DOCUMENT_TYPE_NODE = Node::DOCUMENT_TYPE_NODE
|
16
|
+
DOCUMENT_FRAG_NODE = Node::DOCUMENT_FRAG_NODE
|
17
|
+
NOTATION_NODE = Node::NOTATION_NODE
|
18
|
+
HTML_DOCUMENT_NODE = Node::HTML_DOCUMENT_NODE
|
19
|
+
DTD_NODE = Node::DTD_NODE
|
20
|
+
ELEMENT_DECL = Node::ELEMENT_DECL
|
21
|
+
ATTRIBUTE_DECL = Node::ATTRIBUTE_DECL
|
22
|
+
ENTITY_DECL = Node::ENTITY_DECL
|
23
|
+
NAMESPACE_DECL = Node::NAMESPACE_DECL
|
24
|
+
XINCLUDE_START = Node::XINCLUDE_START
|
25
|
+
XINCLUDE_END = Node::XINCLUDE_END
|
26
|
+
DOCB_DOCUMENT_NODE = Node::DOCB_DOCUMENT_NODE
|
27
|
+
end
|
28
|
+
end
|
29
29
|
end
|
data/lib/libxml.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
#
|
3
|
-
# This include is deprecated, use libxml-ruby instead!
|
4
|
-
|
1
|
+
# encoding: UTF-8
|
2
|
+
#
|
3
|
+
# This include is deprecated, use libxml-ruby instead!
|
4
|
+
|
5
5
|
require 'libxml-ruby'
|
data/lib/xml/libxml.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
# This is here for backward compatibility.
|
4
|
-
#
|
5
|
-
# TODO: DEPRECATE!
|
6
|
-
|
7
|
-
require 'libxml.rb'
|
8
|
-
|
9
|
-
include LibXML
|
10
|
-
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
# This is here for backward compatibility.
|
4
|
+
#
|
5
|
+
# TODO: DEPRECATE!
|
6
|
+
|
7
|
+
require 'libxml.rb'
|
8
|
+
|
9
|
+
include LibXML
|
10
|
+
|
data/lib/xml.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
# This file loads libxml and adds the LibXML namespace
|
4
|
-
# to the toplevel for conveneience. The end result
|
5
|
-
# is to have XML:: universally exposed.
|
6
|
-
#
|
7
|
-
# It is recommend that you only load this file for libs
|
8
|
-
# that do not have their own namespace, eg. administrative
|
9
|
-
# scripts, personal programs, etc. For other applications
|
10
|
-
# require 'libxml' instead and include LibXML into your
|
11
|
-
# app/libs namespace.
|
12
|
-
|
13
|
-
require 'libxml'
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
# This file loads libxml and adds the LibXML namespace
|
4
|
+
# to the toplevel for conveneience. The end result
|
5
|
+
# is to have XML:: universally exposed.
|
6
|
+
#
|
7
|
+
# It is recommend that you only load this file for libs
|
8
|
+
# that do not have their own namespace, eg. administrative
|
9
|
+
# scripts, personal programs, etc. For other applications
|
10
|
+
# require 'libxml' instead and include LibXML into your
|
11
|
+
# app/libs namespace.
|
12
|
+
|
13
|
+
require 'libxml'
|
14
14
|
include LibXML
|
data/libxml-ruby.gemspec
CHANGED
@@ -1,49 +1,50 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require 'date'
|
3
|
-
|
4
|
-
# Determine the current version of the software
|
5
|
-
version = File.read('ext/libxml/ruby_xml_version.h').match(/\s*RUBY_LIBXML_VERSION\s*['"](\d.+)['"]/)[1]
|
6
|
-
|
7
|
-
Gem::Specification.new do |spec|
|
8
|
-
spec.name = 'libxml-ruby'
|
9
|
-
spec.version = version
|
10
|
-
spec.homepage = 'https://xml4r.github.io/libxml-ruby/'
|
11
|
-
spec.summary = 'Ruby Bindings for LibXML2'
|
12
|
-
spec.description = <<-EOS
|
13
|
-
The Libxml-Ruby project provides Ruby language bindings for the GNOME
|
14
|
-
Libxml2 XML toolkit. It is free software, released under the MIT License.
|
15
|
-
Libxml-ruby's primary advantage over REXML is performance - if speed
|
16
|
-
is your need, these are good libraries to consider, as demonstrated
|
17
|
-
by the informal benchmark below.
|
18
|
-
EOS
|
19
|
-
spec.authors = ['Ross Bamform', 'Wai-Sun Chia', 'Sean Chittenden',
|
20
|
-
'Dan Janwoski', 'Anurag Priyam', 'Charlie Savage',
|
21
|
-
'Ryan Johnson']
|
22
|
-
spec.platform = Gem::Platform::RUBY
|
23
|
-
spec.bindir = 'bin'
|
24
|
-
spec.extensions = ['ext/libxml/extconf.rb']
|
25
|
-
spec.
|
26
|
-
|
27
|
-
'
|
28
|
-
'
|
29
|
-
'
|
30
|
-
'
|
31
|
-
'
|
32
|
-
'
|
33
|
-
'ext/libxml/*.
|
34
|
-
'ext/libxml/*.
|
35
|
-
'ext/libxml/*.
|
36
|
-
'ext/
|
37
|
-
'ext/vc/*.
|
38
|
-
'
|
39
|
-
'
|
40
|
-
'
|
41
|
-
|
42
|
-
|
43
|
-
spec.
|
44
|
-
spec.
|
45
|
-
spec.
|
46
|
-
spec.add_development_dependency('
|
47
|
-
spec.add_development_dependency('
|
48
|
-
spec.
|
49
|
-
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'date'
|
3
|
+
|
4
|
+
# Determine the current version of the software
|
5
|
+
version = File.read('ext/libxml/ruby_xml_version.h').match(/\s*RUBY_LIBXML_VERSION\s*['"](\d.+)['"]/)[1]
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'libxml-ruby'
|
9
|
+
spec.version = version
|
10
|
+
spec.homepage = 'https://xml4r.github.io/libxml-ruby/'
|
11
|
+
spec.summary = 'Ruby Bindings for LibXML2'
|
12
|
+
spec.description = <<-EOS
|
13
|
+
The Libxml-Ruby project provides Ruby language bindings for the GNOME
|
14
|
+
Libxml2 XML toolkit. It is free software, released under the MIT License.
|
15
|
+
Libxml-ruby's primary advantage over REXML is performance - if speed
|
16
|
+
is your need, these are good libraries to consider, as demonstrated
|
17
|
+
by the informal benchmark below.
|
18
|
+
EOS
|
19
|
+
spec.authors = ['Ross Bamform', 'Wai-Sun Chia', 'Sean Chittenden',
|
20
|
+
'Dan Janwoski', 'Anurag Priyam', 'Charlie Savage',
|
21
|
+
'Ryan Johnson']
|
22
|
+
spec.platform = Gem::Platform::RUBY
|
23
|
+
spec.bindir = 'bin'
|
24
|
+
spec.extensions = ['ext/libxml/extconf.rb']
|
25
|
+
spec.metadata = {'documentation_uri' => 'https://xml4r.github.io/libxml-ruby/'}
|
26
|
+
spec.files = Dir.glob(['HISTORY',
|
27
|
+
'LICENSE',
|
28
|
+
'libxml-ruby.gemspec',
|
29
|
+
'MANIFEST',
|
30
|
+
'Rakefile',
|
31
|
+
'README.rdoc',
|
32
|
+
'setup.rb',
|
33
|
+
'ext/libxml/*.def',
|
34
|
+
'ext/libxml/*.h',
|
35
|
+
'ext/libxml/*.c',
|
36
|
+
'ext/libxml/*.rb',
|
37
|
+
'ext/vc/*.sln',
|
38
|
+
'ext/vc/*.vcprojx',
|
39
|
+
'lib/**/*.rb',
|
40
|
+
'script/**/*',
|
41
|
+
'test/**/*'])
|
42
|
+
|
43
|
+
spec.test_files = Dir.glob('test/test_*.rb')
|
44
|
+
spec.required_ruby_version = '>= 2.5'
|
45
|
+
spec.date = DateTime.now
|
46
|
+
spec.add_development_dependency('logger')
|
47
|
+
spec.add_development_dependency('rake-compiler')
|
48
|
+
spec.add_development_dependency('minitest')
|
49
|
+
spec.license = 'MIT'
|
50
|
+
end
|
data/test/test_document.rb
CHANGED
@@ -1,140 +1,140 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
require_relative './test_helper'
|
3
|
-
|
4
|
-
class TestDocument < Minitest::Test
|
5
|
-
def setup
|
6
|
-
xp = LibXML::XML::Parser.string('<ruby_array uga="booga" foo="bar"><fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>')
|
7
|
-
assert_instance_of(LibXML::XML::Parser, xp)
|
8
|
-
@doc = xp.parse
|
9
|
-
assert_instance_of(LibXML::XML::Document, @doc)
|
10
|
-
end
|
11
|
-
|
12
|
-
def teardown
|
13
|
-
@doc = nil
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_klass
|
17
|
-
assert_instance_of(LibXML::XML::Document, @doc)
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_context
|
21
|
-
context = @doc.context
|
22
|
-
assert_instance_of(LibXML::XML::XPath::Context, context)
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_find
|
26
|
-
set = @doc.find('/ruby_array/fixnum')
|
27
|
-
assert_instance_of(LibXML::XML::XPath::Object, set)
|
28
|
-
assert_raises(NoMethodError) {
|
29
|
-
set.xpath
|
30
|
-
}
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_compression
|
34
|
-
if LibXML::XML.enabled_zlib?
|
35
|
-
0.upto(9) do |i|
|
36
|
-
assert_equal(i, @doc.compression = i)
|
37
|
-
assert_equal(i, @doc.compression)
|
38
|
-
end
|
39
|
-
|
40
|
-
9.downto(0) do |i|
|
41
|
-
assert_equal(i, @doc.compression = i)
|
42
|
-
assert_equal(i, @doc.compression)
|
43
|
-
end
|
44
|
-
|
45
|
-
10.upto(20) do |i|
|
46
|
-
# assert_equal(9, @doc.compression = i)
|
47
|
-
assert_equal(i, @doc.compression = i) # This works around a bug in Ruby 1.8
|
48
|
-
assert_equal(9, @doc.compression)
|
49
|
-
end
|
50
|
-
|
51
|
-
-1.downto(-10) do |i|
|
52
|
-
# assert_equal(0, @doc.compression = i)
|
53
|
-
assert_equal(i, @doc.compression = i) # FIXME This bug should get fixed ASAP
|
54
|
-
assert_equal(0, @doc.compression)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
def test_version
|
60
|
-
assert_equal('1.0', @doc.version)
|
61
|
-
|
62
|
-
doc = LibXML::XML::Document.new('6.9')
|
63
|
-
assert_equal('6.9', doc.version)
|
64
|
-
end
|
65
|
-
|
66
|
-
def test_write_root
|
67
|
-
@doc.root = LibXML::XML::Node.new('rubynet')
|
68
|
-
assert_instance_of(LibXML::XML::Node, @doc.root)
|
69
|
-
assert_instance_of(LibXML::XML::Document, @doc.root.doc)
|
70
|
-
assert_equal("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<rubynet/>\n",
|
71
|
-
@doc.to_s(:indent => false))
|
72
|
-
end
|
73
|
-
|
74
|
-
def test_doc_node_type
|
75
|
-
assert_equal(LibXML::XML::Node::DOCUMENT_NODE, LibXML::XML::Document.new.node_type)
|
76
|
-
end
|
77
|
-
|
78
|
-
def test_doc_node_type_name
|
79
|
-
assert_equal('document_xml', LibXML::XML::Document.new.node_type_name)
|
80
|
-
end
|
81
|
-
|
82
|
-
def test_xhtml
|
83
|
-
doc = LibXML::XML::Document.new
|
84
|
-
assert(!doc.xhtml?)
|
85
|
-
LibXML::XML::Dtd.new("-//W3C//DTD XHTML 1.0 Transitional//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", nil, doc, true)
|
86
|
-
assert(doc.xhtml?)
|
87
|
-
end
|
88
|
-
|
89
|
-
def test_document_root
|
90
|
-
doc1 = LibXML::XML::Document.string("<one/>")
|
91
|
-
doc2 = LibXML::XML::Document.string("<two/>")
|
92
|
-
|
93
|
-
error = assert_raises(LibXML::XML::Error) do
|
94
|
-
doc1.root = doc2.root
|
95
|
-
end
|
96
|
-
assert_equal(" Nodes belong to different documents. You must first import the node by calling LibXML::XML::Document.import.",
|
97
|
-
error.to_s)
|
98
|
-
|
99
|
-
doc2.root << doc2.import(doc1.root)
|
100
|
-
assert_equal('<one/>', doc1.root.to_s)
|
101
|
-
assert_equal('<two><one/></two>', doc2.root.to_s(:indent => false))
|
102
|
-
|
103
|
-
assert(!doc1.root.equal?(doc2.root))
|
104
|
-
assert(doc1.root.doc != doc2.root.doc)
|
105
|
-
end
|
106
|
-
|
107
|
-
def test_import_node
|
108
|
-
doc1 = LibXML::XML::Parser.string('<nums><one></one></nums>').parse
|
109
|
-
doc2 = LibXML::XML::Parser.string('<nums><two></two></nums>').parse
|
110
|
-
|
111
|
-
node = doc1.root.child
|
112
|
-
|
113
|
-
error = assert_raises(LibXML::XML::Error) do
|
114
|
-
doc2.root << node
|
115
|
-
end
|
116
|
-
|
117
|
-
assert_equal(" Nodes belong to different documents. You must first import the node by calling LibXML::XML::Document.import.",
|
118
|
-
error.to_s)
|
119
|
-
|
120
|
-
doc2.root << doc2.import(node)
|
121
|
-
|
122
|
-
assert_equal("<nums><two/><one/></nums>",
|
123
|
-
doc2.root.to_s(:indent => false))
|
124
|
-
end
|
125
|
-
|
126
|
-
def test_nonet
|
127
|
-
xml_string = '<ruby_array uga="booga" foo="bar"><fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>'
|
128
|
-
xml = LibXML::XML::Document.string(xml_string, options: LibXML::XML::Parser::Options::NONET)
|
129
|
-
file = File.join(File.dirname(__FILE__), 'model/atom.xml')
|
130
|
-
schema_document = LibXML::XML::Document.file(file, options: LibXML::XML::Parser::Options::NONET)
|
131
|
-
end
|
132
|
-
|
133
|
-
def test_io
|
134
|
-
File.open(File.join(File.dirname(__FILE__), 'model/rubynet.xml')) do |io|
|
135
|
-
doc = LibXML::XML::Document.io(io)
|
136
|
-
assert_instance_of(LibXML::XML::Document, doc)
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
end
|
1
|
+
# encoding: UTF-8
|
2
|
+
require_relative './test_helper'
|
3
|
+
|
4
|
+
class TestDocument < Minitest::Test
|
5
|
+
def setup
|
6
|
+
xp = LibXML::XML::Parser.string('<ruby_array uga="booga" foo="bar"><fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>')
|
7
|
+
assert_instance_of(LibXML::XML::Parser, xp)
|
8
|
+
@doc = xp.parse
|
9
|
+
assert_instance_of(LibXML::XML::Document, @doc)
|
10
|
+
end
|
11
|
+
|
12
|
+
def teardown
|
13
|
+
@doc = nil
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_klass
|
17
|
+
assert_instance_of(LibXML::XML::Document, @doc)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_context
|
21
|
+
context = @doc.context
|
22
|
+
assert_instance_of(LibXML::XML::XPath::Context, context)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_find
|
26
|
+
set = @doc.find('/ruby_array/fixnum')
|
27
|
+
assert_instance_of(LibXML::XML::XPath::Object, set)
|
28
|
+
assert_raises(NoMethodError) {
|
29
|
+
set.xpath
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_compression
|
34
|
+
if LibXML::XML.enabled_zlib?
|
35
|
+
0.upto(9) do |i|
|
36
|
+
assert_equal(i, @doc.compression = i)
|
37
|
+
assert_equal(i, @doc.compression)
|
38
|
+
end
|
39
|
+
|
40
|
+
9.downto(0) do |i|
|
41
|
+
assert_equal(i, @doc.compression = i)
|
42
|
+
assert_equal(i, @doc.compression)
|
43
|
+
end
|
44
|
+
|
45
|
+
10.upto(20) do |i|
|
46
|
+
# assert_equal(9, @doc.compression = i)
|
47
|
+
assert_equal(i, @doc.compression = i) # This works around a bug in Ruby 1.8
|
48
|
+
assert_equal(9, @doc.compression)
|
49
|
+
end
|
50
|
+
|
51
|
+
-1.downto(-10) do |i|
|
52
|
+
# assert_equal(0, @doc.compression = i)
|
53
|
+
assert_equal(i, @doc.compression = i) # FIXME This bug should get fixed ASAP
|
54
|
+
assert_equal(0, @doc.compression)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_version
|
60
|
+
assert_equal('1.0', @doc.version)
|
61
|
+
|
62
|
+
doc = LibXML::XML::Document.new('6.9')
|
63
|
+
assert_equal('6.9', doc.version)
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_write_root
|
67
|
+
@doc.root = LibXML::XML::Node.new('rubynet')
|
68
|
+
assert_instance_of(LibXML::XML::Node, @doc.root)
|
69
|
+
assert_instance_of(LibXML::XML::Document, @doc.root.doc)
|
70
|
+
assert_equal("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<rubynet/>\n",
|
71
|
+
@doc.to_s(:indent => false))
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_doc_node_type
|
75
|
+
assert_equal(LibXML::XML::Node::DOCUMENT_NODE, LibXML::XML::Document.new.node_type)
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_doc_node_type_name
|
79
|
+
assert_equal('document_xml', LibXML::XML::Document.new.node_type_name)
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_xhtml
|
83
|
+
doc = LibXML::XML::Document.new
|
84
|
+
assert(!doc.xhtml?)
|
85
|
+
LibXML::XML::Dtd.new("-//W3C//DTD XHTML 1.0 Transitional//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", nil, doc, true)
|
86
|
+
assert(doc.xhtml?)
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_document_root
|
90
|
+
doc1 = LibXML::XML::Document.string("<one/>")
|
91
|
+
doc2 = LibXML::XML::Document.string("<two/>")
|
92
|
+
|
93
|
+
error = assert_raises(LibXML::XML::Error) do
|
94
|
+
doc1.root = doc2.root
|
95
|
+
end
|
96
|
+
assert_equal(" Nodes belong to different documents. You must first import the node by calling LibXML::XML::Document.import.",
|
97
|
+
error.to_s)
|
98
|
+
|
99
|
+
doc2.root << doc2.import(doc1.root)
|
100
|
+
assert_equal('<one/>', doc1.root.to_s)
|
101
|
+
assert_equal('<two><one/></two>', doc2.root.to_s(:indent => false))
|
102
|
+
|
103
|
+
assert(!doc1.root.equal?(doc2.root))
|
104
|
+
assert(doc1.root.doc != doc2.root.doc)
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_import_node
|
108
|
+
doc1 = LibXML::XML::Parser.string('<nums><one></one></nums>').parse
|
109
|
+
doc2 = LibXML::XML::Parser.string('<nums><two></two></nums>').parse
|
110
|
+
|
111
|
+
node = doc1.root.child
|
112
|
+
|
113
|
+
error = assert_raises(LibXML::XML::Error) do
|
114
|
+
doc2.root << node
|
115
|
+
end
|
116
|
+
|
117
|
+
assert_equal(" Nodes belong to different documents. You must first import the node by calling LibXML::XML::Document.import.",
|
118
|
+
error.to_s)
|
119
|
+
|
120
|
+
doc2.root << doc2.import(node)
|
121
|
+
|
122
|
+
assert_equal("<nums><two/><one/></nums>",
|
123
|
+
doc2.root.to_s(:indent => false))
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_nonet
|
127
|
+
xml_string = '<ruby_array uga="booga" foo="bar"><fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>'
|
128
|
+
xml = LibXML::XML::Document.string(xml_string, options: LibXML::XML::Parser::Options::NONET)
|
129
|
+
file = File.join(File.dirname(__FILE__), 'model/atom.xml')
|
130
|
+
schema_document = LibXML::XML::Document.file(file, options: LibXML::XML::Parser::Options::NONET)
|
131
|
+
end
|
132
|
+
|
133
|
+
def test_io
|
134
|
+
File.open(File.join(File.dirname(__FILE__), 'model/rubynet.xml')) do |io|
|
135
|
+
doc = LibXML::XML::Document.io(io)
|
136
|
+
assert_instance_of(LibXML::XML::Document, doc)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
end
|