libxml-ruby 1.1.3-x86-mswin32-60 → 1.1.4-x86-mswin32-60
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +1 -1
- data/LICENSE +22 -22
- data/README +160 -160
- data/Rakefile +0 -9
- data/ext/libxml/Makefile +156 -0
- data/ext/libxml/extconf.h +5 -0
- data/ext/libxml/extconf.rb +4 -160
- data/ext/libxml/libxml-ruby.so.a +0 -0
- data/ext/libxml/libxml.o +0 -0
- data/ext/libxml/libxml_ruby.so +0 -0
- data/ext/libxml/mkmf.log +129 -0
- data/ext/libxml/ruby_xml.o +0 -0
- data/ext/libxml/ruby_xml_attr.c +1 -1
- data/ext/libxml/ruby_xml_attr.h +1 -1
- data/ext/libxml/ruby_xml_attr.o +0 -0
- data/ext/libxml/ruby_xml_attr_decl.o +0 -0
- data/ext/libxml/ruby_xml_attributes.o +0 -0
- data/ext/libxml/ruby_xml_cbg.o +0 -0
- data/ext/libxml/ruby_xml_document.c +936 -936
- data/ext/libxml/ruby_xml_document.h +1 -1
- data/ext/libxml/ruby_xml_document.o +0 -0
- data/ext/libxml/ruby_xml_dtd.o +0 -0
- data/ext/libxml/ruby_xml_encoding.o +0 -0
- data/ext/libxml/ruby_xml_error.o +0 -0
- data/ext/libxml/ruby_xml_html_parser.c +1 -1
- data/ext/libxml/ruby_xml_html_parser.h +1 -1
- data/ext/libxml/ruby_xml_html_parser.o +0 -0
- data/ext/libxml/ruby_xml_html_parser_context.o +0 -0
- data/ext/libxml/ruby_xml_html_parser_options.o +0 -0
- data/ext/libxml/ruby_xml_input_cbg.o +0 -0
- data/ext/libxml/ruby_xml_io.o +0 -0
- data/ext/libxml/ruby_xml_namespace.c +1 -1
- data/ext/libxml/ruby_xml_namespace.h +1 -1
- data/ext/libxml/ruby_xml_namespace.o +0 -0
- data/ext/libxml/ruby_xml_namespaces.o +0 -0
- data/ext/libxml/ruby_xml_node.c +1386 -1386
- data/ext/libxml/ruby_xml_node.h +1 -1
- data/ext/libxml/ruby_xml_node.o +0 -0
- data/ext/libxml/ruby_xml_parser.c +1 -1
- data/ext/libxml/ruby_xml_parser.h +1 -1
- data/ext/libxml/ruby_xml_parser.o +0 -0
- data/ext/libxml/ruby_xml_parser_context.c +1 -1
- data/ext/libxml/ruby_xml_parser_context.h +1 -1
- data/ext/libxml/ruby_xml_parser_context.o +0 -0
- data/ext/libxml/ruby_xml_parser_options.o +0 -0
- data/ext/libxml/ruby_xml_reader.o +0 -0
- data/ext/libxml/ruby_xml_relaxng.o +0 -0
- data/ext/libxml/ruby_xml_sax2_handler.o +0 -0
- data/ext/libxml/ruby_xml_sax_parser.c +1 -1
- data/ext/libxml/ruby_xml_sax_parser.h +1 -1
- data/ext/libxml/ruby_xml_sax_parser.o +0 -0
- data/ext/libxml/ruby_xml_schema.o +0 -0
- data/ext/libxml/ruby_xml_version.h +3 -3
- data/ext/libxml/ruby_xml_xinclude.c +1 -1
- data/ext/libxml/ruby_xml_xinclude.h +1 -1
- data/ext/libxml/ruby_xml_xinclude.o +0 -0
- data/ext/libxml/ruby_xml_xpath.c +1 -1
- data/ext/libxml/ruby_xml_xpath.h +1 -1
- data/ext/libxml/ruby_xml_xpath.o +0 -0
- data/ext/libxml/ruby_xml_xpath_context.c +1 -1
- data/ext/libxml/ruby_xml_xpath_context.h +1 -1
- data/ext/libxml/ruby_xml_xpath_context.o +0 -0
- data/ext/libxml/ruby_xml_xpath_expression.o +0 -0
- data/ext/libxml/ruby_xml_xpath_object.o +0 -0
- data/ext/libxml/ruby_xml_xpointer.c +1 -1
- data/ext/libxml/ruby_xml_xpointer.h +1 -1
- data/ext/libxml/ruby_xml_xpointer.o +0 -0
- data/ext/mingw/build.rake +3 -3
- data/ext/mingw/libiconv-2.dll +0 -0
- data/ext/mingw/libxml2-2.dll +0 -0
- data/ext/mingw/libxml_ruby.dll.a +0 -0
- data/ext/mingw/libxml_ruby.so +0 -0
- data/lib/libxml.rb +29 -29
- data/test/model/merge_bug_data.xml +58 -58
- data/test/model/rubynet.xml +79 -79
- data/test/model/xinclude.xml +4 -4
- data/test/tc_attr.rb +170 -170
- data/test/tc_document.rb +113 -113
- data/test/tc_document_write.rb +117 -117
- data/test/tc_dtd.rb +123 -123
- data/test/tc_html_parser.rb +137 -137
- data/test/tc_node.rb +180 -180
- data/test/tc_node_cdata.rb +49 -49
- data/test/tc_node_comment.rb +30 -30
- data/test/tc_node_edit.rb +157 -157
- data/test/tc_node_xlink.rb +26 -26
- data/test/tc_parser.rb +329 -329
- data/test/tc_parser_context.rb +185 -185
- data/test/tc_reader.rb +283 -283
- data/test/tc_sax_parser.rb +273 -273
- data/test/tc_schema.rb +51 -51
- data/test/tc_xinclude.rb +19 -19
- data/test/tc_xpath.rb +193 -193
- data/test/tc_xpointer.rb +72 -72
- metadata +55 -14
- data/ext/libxml/build.log +0 -4
data/test/tc_node_cdata.rb
CHANGED
@@ -1,49 +1,49 @@
|
|
1
|
-
require 'xml'
|
2
|
-
require 'test/unit'
|
3
|
-
|
4
|
-
class CDataCommentTest < Test::Unit::TestCase
|
5
|
-
def setup
|
6
|
-
xp = XML::Parser.string('<root></root>')
|
7
|
-
@doc = xp.parse
|
8
|
-
assert_instance_of(XML::Document, @doc)
|
9
|
-
@root = @doc.root
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_node_type
|
13
|
-
cnode = XML::Node.new_cdata('test cdata')
|
14
|
-
assert_equal(XML::Node::CDATA_SECTION_NODE, cnode.node_type)
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_add_cdata
|
18
|
-
@root << XML::Node.new_cdata('mycdata')
|
19
|
-
assert_equal '<root><![CDATA[mycdata]]></root>',
|
20
|
-
@root.to_s.gsub(/\n\s*/,'')
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_add_cdata_2
|
24
|
-
@root << XML::Node.new_cdata('mycdata')
|
25
|
-
assert_equal 'cdata',
|
26
|
-
@root.child.node_type_name
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_add_cdata_3
|
30
|
-
@root << el = XML::Node.new_cdata('mycdata')
|
31
|
-
el << "_this_is_added"
|
32
|
-
assert_equal '<root><![CDATA[mycdata_this_is_added]]></root>',
|
33
|
-
@root.to_s.gsub(/\n\s*/,'')
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_attributes
|
37
|
-
cnode = XML::Node.new_cdata('test cdata')
|
38
|
-
assert_equal(0, cnode.attributes.length)
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_set_cdata_attribute
|
42
|
-
cnode = XML::Node.new_cdata('test cdata')
|
43
|
-
|
44
|
-
# Can't create attributes on non-element nodes
|
45
|
-
assert_raise(ArgumentError) do
|
46
|
-
cnode['attr'] = '123'
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
1
|
+
require 'xml'
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
class CDataCommentTest < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
xp = XML::Parser.string('<root></root>')
|
7
|
+
@doc = xp.parse
|
8
|
+
assert_instance_of(XML::Document, @doc)
|
9
|
+
@root = @doc.root
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_node_type
|
13
|
+
cnode = XML::Node.new_cdata('test cdata')
|
14
|
+
assert_equal(XML::Node::CDATA_SECTION_NODE, cnode.node_type)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_add_cdata
|
18
|
+
@root << XML::Node.new_cdata('mycdata')
|
19
|
+
assert_equal '<root><![CDATA[mycdata]]></root>',
|
20
|
+
@root.to_s.gsub(/\n\s*/,'')
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_add_cdata_2
|
24
|
+
@root << XML::Node.new_cdata('mycdata')
|
25
|
+
assert_equal 'cdata',
|
26
|
+
@root.child.node_type_name
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_add_cdata_3
|
30
|
+
@root << el = XML::Node.new_cdata('mycdata')
|
31
|
+
el << "_this_is_added"
|
32
|
+
assert_equal '<root><![CDATA[mycdata_this_is_added]]></root>',
|
33
|
+
@root.to_s.gsub(/\n\s*/,'')
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_attributes
|
37
|
+
cnode = XML::Node.new_cdata('test cdata')
|
38
|
+
assert_equal(0, cnode.attributes.length)
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_set_cdata_attribute
|
42
|
+
cnode = XML::Node.new_cdata('test cdata')
|
43
|
+
|
44
|
+
# Can't create attributes on non-element nodes
|
45
|
+
assert_raise(ArgumentError) do
|
46
|
+
cnode['attr'] = '123'
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/test/tc_node_comment.rb
CHANGED
@@ -1,30 +1,30 @@
|
|
1
|
-
require "xml"
|
2
|
-
require 'test/unit'
|
3
|
-
|
4
|
-
class NodeCommentTest < Test::Unit::TestCase
|
5
|
-
def setup
|
6
|
-
xp = XML::Parser.string('<root></root>')
|
7
|
-
@doc = xp.parse
|
8
|
-
assert_instance_of(XML::Document, @doc)
|
9
|
-
@root = @doc.root
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_libxml_node_add_comment_01
|
13
|
-
@root << XML::Node.new_comment('mycomment')
|
14
|
-
assert_equal '<root><!--mycomment--></root>',
|
15
|
-
@root.to_s.gsub(/\n\s*/,'')
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_libxml_node_add_comment_02
|
19
|
-
@root << XML::Node.new_comment('mycomment')
|
20
|
-
assert_equal 'comment',
|
21
|
-
@root.child.node_type_name
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_libxml_node_add_comment_03
|
25
|
-
@root << el = XML::Node.new_comment('mycomment')
|
26
|
-
el << "_this_is_added"
|
27
|
-
assert_equal '<root><!--mycomment_this_is_added--></root>',
|
28
|
-
@root.to_s.gsub(/\n\s*/,'')
|
29
|
-
end
|
30
|
-
end
|
1
|
+
require "xml"
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
class NodeCommentTest < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
xp = XML::Parser.string('<root></root>')
|
7
|
+
@doc = xp.parse
|
8
|
+
assert_instance_of(XML::Document, @doc)
|
9
|
+
@root = @doc.root
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_libxml_node_add_comment_01
|
13
|
+
@root << XML::Node.new_comment('mycomment')
|
14
|
+
assert_equal '<root><!--mycomment--></root>',
|
15
|
+
@root.to_s.gsub(/\n\s*/,'')
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_libxml_node_add_comment_02
|
19
|
+
@root << XML::Node.new_comment('mycomment')
|
20
|
+
assert_equal 'comment',
|
21
|
+
@root.child.node_type_name
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_libxml_node_add_comment_03
|
25
|
+
@root << el = XML::Node.new_comment('mycomment')
|
26
|
+
el << "_this_is_added"
|
27
|
+
assert_equal '<root><!--mycomment_this_is_added--></root>',
|
28
|
+
@root.to_s.gsub(/\n\s*/,'')
|
29
|
+
end
|
30
|
+
end
|
data/test/tc_node_edit.rb
CHANGED
@@ -1,158 +1,158 @@
|
|
1
|
-
require 'xml'
|
2
|
-
require 'test/unit'
|
3
|
-
|
4
|
-
class TestNodeEdit < Test::Unit::TestCase
|
5
|
-
def setup
|
6
|
-
xp = XML::Parser.string('<test><num>one</num><num>two</num><num>three</num></test>')
|
7
|
-
@doc = xp.parse
|
8
|
-
end
|
9
|
-
|
10
|
-
def teardown
|
11
|
-
@doc = nil
|
12
|
-
end
|
13
|
-
|
14
|
-
def first_node
|
15
|
-
@doc.root.child
|
16
|
-
end
|
17
|
-
|
18
|
-
def second_node
|
19
|
-
first_node.next
|
20
|
-
end
|
21
|
-
|
22
|
-
def third_node
|
23
|
-
second_node.next
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_add_next_01
|
27
|
-
first_node.next = XML::Node.new('num', 'one-and-a-half')
|
28
|
-
assert_equal('<test><num>one</num><num>one-and-a-half</num><num>two</num><num>three</num></test>',
|
29
|
-
@doc.root.to_s.gsub(/\n\s*/,''))
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_add_next_02
|
33
|
-
second_node.next = XML::Node.new('num', 'two-and-a-half')
|
34
|
-
assert_equal('<test><num>one</num><num>two</num><num>two-and-a-half</num><num>three</num></test>',
|
35
|
-
@doc.root.to_s.gsub(/\n\s*/,''))
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_add_next_03
|
39
|
-
third_node.next = XML::Node.new('num', 'four')
|
40
|
-
assert_equal '<test><num>one</num><num>two</num><num>three</num><num>four</num></test>',
|
41
|
-
@doc.root.to_s.gsub(/\n\s*/,'')
|
42
|
-
end
|
43
|
-
|
44
|
-
def test_add_prev_01
|
45
|
-
first_node.prev = XML::Node.new('num', 'half')
|
46
|
-
assert_equal '<test><num>half</num><num>one</num><num>two</num><num>three</num></test>',
|
47
|
-
@doc.root.to_s.gsub(/\n\s*/,'')
|
48
|
-
end
|
49
|
-
|
50
|
-
def test_add_prev_02
|
51
|
-
second_node.prev = XML::Node.new('num', 'one-and-a-half')
|
52
|
-
assert_equal '<test><num>one</num><num>one-and-a-half</num><num>two</num><num>three</num></test>',
|
53
|
-
@doc.root.to_s.gsub(/\n\s*/,'')
|
54
|
-
end
|
55
|
-
|
56
|
-
def test_add_prev_03
|
57
|
-
third_node.prev = XML::Node.new('num', 'two-and-a-half')
|
58
|
-
assert_equal '<test><num>one</num><num>two</num><num>two-and-a-half</num><num>three</num></test>',
|
59
|
-
@doc.root.to_s.gsub(/\n\s*/,'')
|
60
|
-
end
|
61
|
-
|
62
|
-
def test_remove_node
|
63
|
-
first_node.remove!
|
64
|
-
assert_equal('<test><num>two</num><num>three</num></test>',
|
65
|
-
@doc.root.to_s.gsub(/\n\s*/,''))
|
66
|
-
end
|
67
|
-
|
68
|
-
def test_remove_node_gc
|
69
|
-
xp = XML::Parser.string('<test><num>one</num><num>two</num><num>three</num></test>')
|
70
|
-
doc = xp.parse
|
71
|
-
node = doc.root.child.remove!
|
72
|
-
node = nil
|
73
|
-
GC.start
|
74
|
-
assert_not_nil(doc)
|
75
|
-
end
|
76
|
-
|
77
|
-
def test_remove_node_iteration
|
78
|
-
nodes = Array.new
|
79
|
-
@doc.root.each_element do |node|
|
80
|
-
if node.name == 'num'
|
81
|
-
nodes << node
|
82
|
-
node.remove!
|
83
|
-
end
|
84
|
-
end
|
85
|
-
assert_equal(3, nodes.length)
|
86
|
-
end
|
87
|
-
|
88
|
-
def test_reuse_removed_node
|
89
|
-
# Remove the node
|
90
|
-
node = @doc.root.first.remove!
|
91
|
-
assert_not_nil(node)
|
92
|
-
|
93
|
-
# Add it to the end of the documnet
|
94
|
-
@doc.root.last.next = node
|
95
|
-
|
96
|
-
assert_equal('<test><num>two</num><num>three</num><num>one</num></test>',
|
97
|
-
@doc.root.to_s.gsub(/\n\s*/,''))
|
98
|
-
end
|
99
|
-
|
100
|
-
def test_append_existing_node
|
101
|
-
doc = XML::Parser.string('<top>a<bottom>b<one>first</one><two>second</two>c</bottom>d</top>').parse
|
102
|
-
node1 = doc.find_first('//two')
|
103
|
-
|
104
|
-
doc.root << node1
|
105
|
-
assert_equal('<top>a<bottom>b<one>first</one>c</bottom>d<two>second</two></top>',
|
106
|
-
doc.root.to_s)
|
107
|
-
end
|
108
|
-
|
109
|
-
def test_wrong_doc
|
110
|
-
doc1 = XML::Parser.string('<nums><one></one></nums>').parse
|
111
|
-
doc2 = XML::Parser.string('<nums><two></two></nums>').parse
|
112
|
-
|
113
|
-
node = doc1.root.child
|
114
|
-
|
115
|
-
error = assert_raise(XML::Error) do
|
116
|
-
doc2.root << node
|
117
|
-
end
|
118
|
-
|
119
|
-
assert_equal(' Nodes belong to different documents. You must first import the by calling XML::Document.import.',
|
120
|
-
error.to_s)
|
121
|
-
end
|
122
|
-
|
123
|
-
|
124
|
-
# This test is to verify that an earlier reported bug has been fixed
|
125
|
-
def test_merge
|
126
|
-
documents = []
|
127
|
-
|
128
|
-
# Read in 500 documents
|
129
|
-
500.times do
|
130
|
-
documents << XML::Parser.string(File.read(File.join(File.dirname(__FILE__), 'model', 'merge_bug_data.xml'))).parse
|
131
|
-
end
|
132
|
-
|
133
|
-
master_doc = documents.shift
|
134
|
-
documents.inject(master_doc) do |master_doc, child_doc|
|
135
|
-
master_body = master_doc.find("//body").first
|
136
|
-
child_body = child_doc.find("//body").first
|
137
|
-
|
138
|
-
child_element = child_body.detect do |node|
|
139
|
-
node.element?
|
140
|
-
end
|
141
|
-
|
142
|
-
master_body << child_element.copy(true)
|
143
|
-
master_doc
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
def test_append_chain
|
148
|
-
node = XML::Node.new('foo') << XML::Node.new('bar') << "bars contents"
|
149
|
-
assert_equal('<foo><bar/>bars contents</foo>',
|
150
|
-
node.to_s)
|
151
|
-
end
|
152
|
-
|
153
|
-
def test_set_base
|
154
|
-
@doc.root.base_uri = 'http://www.rubynet.org/'
|
155
|
-
assert_equal("<test xml:base=\"http://www.rubynet.org/\">\n <num>one</num>\n <num>two</num>\n <num>three</num>\n</test>",
|
156
|
-
@doc.root.to_s)
|
157
|
-
end
|
1
|
+
require 'xml'
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
class TestNodeEdit < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
xp = XML::Parser.string('<test><num>one</num><num>two</num><num>three</num></test>')
|
7
|
+
@doc = xp.parse
|
8
|
+
end
|
9
|
+
|
10
|
+
def teardown
|
11
|
+
@doc = nil
|
12
|
+
end
|
13
|
+
|
14
|
+
def first_node
|
15
|
+
@doc.root.child
|
16
|
+
end
|
17
|
+
|
18
|
+
def second_node
|
19
|
+
first_node.next
|
20
|
+
end
|
21
|
+
|
22
|
+
def third_node
|
23
|
+
second_node.next
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_add_next_01
|
27
|
+
first_node.next = XML::Node.new('num', 'one-and-a-half')
|
28
|
+
assert_equal('<test><num>one</num><num>one-and-a-half</num><num>two</num><num>three</num></test>',
|
29
|
+
@doc.root.to_s.gsub(/\n\s*/,''))
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_add_next_02
|
33
|
+
second_node.next = XML::Node.new('num', 'two-and-a-half')
|
34
|
+
assert_equal('<test><num>one</num><num>two</num><num>two-and-a-half</num><num>three</num></test>',
|
35
|
+
@doc.root.to_s.gsub(/\n\s*/,''))
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_add_next_03
|
39
|
+
third_node.next = XML::Node.new('num', 'four')
|
40
|
+
assert_equal '<test><num>one</num><num>two</num><num>three</num><num>four</num></test>',
|
41
|
+
@doc.root.to_s.gsub(/\n\s*/,'')
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_add_prev_01
|
45
|
+
first_node.prev = XML::Node.new('num', 'half')
|
46
|
+
assert_equal '<test><num>half</num><num>one</num><num>two</num><num>three</num></test>',
|
47
|
+
@doc.root.to_s.gsub(/\n\s*/,'')
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_add_prev_02
|
51
|
+
second_node.prev = XML::Node.new('num', 'one-and-a-half')
|
52
|
+
assert_equal '<test><num>one</num><num>one-and-a-half</num><num>two</num><num>three</num></test>',
|
53
|
+
@doc.root.to_s.gsub(/\n\s*/,'')
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_add_prev_03
|
57
|
+
third_node.prev = XML::Node.new('num', 'two-and-a-half')
|
58
|
+
assert_equal '<test><num>one</num><num>two</num><num>two-and-a-half</num><num>three</num></test>',
|
59
|
+
@doc.root.to_s.gsub(/\n\s*/,'')
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_remove_node
|
63
|
+
first_node.remove!
|
64
|
+
assert_equal('<test><num>two</num><num>three</num></test>',
|
65
|
+
@doc.root.to_s.gsub(/\n\s*/,''))
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_remove_node_gc
|
69
|
+
xp = XML::Parser.string('<test><num>one</num><num>two</num><num>three</num></test>')
|
70
|
+
doc = xp.parse
|
71
|
+
node = doc.root.child.remove!
|
72
|
+
node = nil
|
73
|
+
GC.start
|
74
|
+
assert_not_nil(doc)
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_remove_node_iteration
|
78
|
+
nodes = Array.new
|
79
|
+
@doc.root.each_element do |node|
|
80
|
+
if node.name == 'num'
|
81
|
+
nodes << node
|
82
|
+
node.remove!
|
83
|
+
end
|
84
|
+
end
|
85
|
+
assert_equal(3, nodes.length)
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_reuse_removed_node
|
89
|
+
# Remove the node
|
90
|
+
node = @doc.root.first.remove!
|
91
|
+
assert_not_nil(node)
|
92
|
+
|
93
|
+
# Add it to the end of the documnet
|
94
|
+
@doc.root.last.next = node
|
95
|
+
|
96
|
+
assert_equal('<test><num>two</num><num>three</num><num>one</num></test>',
|
97
|
+
@doc.root.to_s.gsub(/\n\s*/,''))
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_append_existing_node
|
101
|
+
doc = XML::Parser.string('<top>a<bottom>b<one>first</one><two>second</two>c</bottom>d</top>').parse
|
102
|
+
node1 = doc.find_first('//two')
|
103
|
+
|
104
|
+
doc.root << node1
|
105
|
+
assert_equal('<top>a<bottom>b<one>first</one>c</bottom>d<two>second</two></top>',
|
106
|
+
doc.root.to_s)
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_wrong_doc
|
110
|
+
doc1 = XML::Parser.string('<nums><one></one></nums>').parse
|
111
|
+
doc2 = XML::Parser.string('<nums><two></two></nums>').parse
|
112
|
+
|
113
|
+
node = doc1.root.child
|
114
|
+
|
115
|
+
error = assert_raise(XML::Error) do
|
116
|
+
doc2.root << node
|
117
|
+
end
|
118
|
+
|
119
|
+
assert_equal(' Nodes belong to different documents. You must first import the by calling XML::Document.import.',
|
120
|
+
error.to_s)
|
121
|
+
end
|
122
|
+
|
123
|
+
|
124
|
+
# This test is to verify that an earlier reported bug has been fixed
|
125
|
+
def test_merge
|
126
|
+
documents = []
|
127
|
+
|
128
|
+
# Read in 500 documents
|
129
|
+
500.times do
|
130
|
+
documents << XML::Parser.string(File.read(File.join(File.dirname(__FILE__), 'model', 'merge_bug_data.xml'))).parse
|
131
|
+
end
|
132
|
+
|
133
|
+
master_doc = documents.shift
|
134
|
+
documents.inject(master_doc) do |master_doc, child_doc|
|
135
|
+
master_body = master_doc.find("//body").first
|
136
|
+
child_body = child_doc.find("//body").first
|
137
|
+
|
138
|
+
child_element = child_body.detect do |node|
|
139
|
+
node.element?
|
140
|
+
end
|
141
|
+
|
142
|
+
master_body << child_element.copy(true)
|
143
|
+
master_doc
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
def test_append_chain
|
148
|
+
node = XML::Node.new('foo') << XML::Node.new('bar') << "bars contents"
|
149
|
+
assert_equal('<foo><bar/>bars contents</foo>',
|
150
|
+
node.to_s)
|
151
|
+
end
|
152
|
+
|
153
|
+
def test_set_base
|
154
|
+
@doc.root.base_uri = 'http://www.rubynet.org/'
|
155
|
+
assert_equal("<test xml:base=\"http://www.rubynet.org/\">\n <num>one</num>\n <num>two</num>\n <num>three</num>\n</test>",
|
156
|
+
@doc.root.to_s)
|
157
|
+
end
|
158
158
|
end
|