libxml-ruby 1.1.4 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/{CHANGES → HISTORY} +35 -0
- data/LICENSE +1 -0
- data/MANIFEST +165 -0
- data/{README → README.rdoc} +2 -2
- data/Rakefile +47 -147
- data/ext/libxml/libxml.c +17 -1
- data/ext/libxml/ruby_libxml.h +9 -1
- data/ext/libxml/ruby_xml_attr.c +3 -3
- data/ext/libxml/ruby_xml_attr_decl.c +32 -32
- data/ext/libxml/ruby_xml_attributes.c +1 -1
- data/ext/libxml/ruby_xml_cbg.c +1 -2
- data/ext/libxml/ruby_xml_document.c +26 -4
- data/ext/libxml/ruby_xml_dtd.c +3 -3
- data/ext/libxml/ruby_xml_encoding.c +92 -5
- data/ext/libxml/ruby_xml_encoding.h +4 -0
- data/ext/libxml/ruby_xml_namespace.c +2 -2
- data/ext/libxml/ruby_xml_node.c +14 -14
- data/ext/libxml/ruby_xml_parser_context.c +8 -8
- data/ext/libxml/ruby_xml_reader.c +98 -43
- data/ext/libxml/ruby_xml_sax2_handler.c +13 -1
- data/ext/libxml/ruby_xml_sax_parser.c +4 -5
- data/ext/libxml/ruby_xml_version.h +5 -5
- data/ext/libxml/ruby_xml_xpath_context.c +9 -6
- data/ext/libxml/ruby_xml_xpath_object.c +1 -1
- data/ext/vc/libxml_ruby.sln +4 -4
- data/lib/libxml.rb +29 -29
- data/lib/libxml/attr.rb +112 -110
- data/lib/libxml/attr_decl.rb +2 -0
- data/lib/libxml/attributes.rb +13 -11
- data/lib/libxml/document.rb +192 -190
- data/lib/libxml/error.rb +89 -87
- data/lib/libxml/hpricot.rb +77 -75
- data/lib/libxml/html_parser.rb +96 -94
- data/lib/libxml/namespace.rb +61 -59
- data/lib/libxml/namespaces.rb +37 -35
- data/lib/libxml/node.rb +398 -384
- data/lib/libxml/ns.rb +21 -19
- data/lib/libxml/parser.rb +366 -364
- data/lib/libxml/properties.rb +22 -20
- data/lib/libxml/reader.rb +2 -0
- data/lib/libxml/sax_callbacks.rb +179 -177
- data/lib/libxml/sax_parser.rb +57 -55
- data/lib/libxml/tree.rb +28 -26
- data/lib/libxml/xpath_object.rb +15 -13
- data/lib/xml.rb +16 -14
- data/lib/xml/libxml.rb +10 -8
- data/libxml-ruby.gemspec +50 -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/test/etc_doc_to_s.rb +21 -19
- data/test/ets_doc_file.rb +17 -15
- data/test/ets_doc_to_s.rb +23 -21
- data/test/ets_gpx.rb +28 -26
- data/test/ets_node_gc.rb +23 -21
- data/test/ets_tsr.rb +11 -9
- data/test/model/bands.iso-8859-1.xml +5 -0
- data/test/model/bands.utf-8.xml +5 -0
- data/test/rb-magic-comment.rb +33 -0
- data/test/tc_attr.rb +181 -170
- data/test/tc_attr_decl.rb +3 -1
- data/test/tc_attributes.rb +134 -132
- data/test/tc_deprecated_require.rb +13 -11
- data/test/tc_document.rb +119 -113
- data/test/tc_document_write.rb +186 -117
- data/test/tc_dtd.rb +125 -123
- data/test/tc_error.rb +3 -1
- data/test/tc_html_parser.rb +139 -137
- data/test/tc_namespace.rb +61 -58
- data/test/tc_namespaces.rb +176 -173
- data/test/tc_node.rb +257 -180
- data/test/tc_node_cdata.rb +51 -49
- data/test/tc_node_comment.rb +33 -30
- data/test/tc_node_copy.rb +42 -40
- data/test/tc_node_edit.rb +159 -157
- data/test/tc_node_text.rb +71 -69
- data/test/tc_node_write.rb +41 -16
- data/test/tc_node_xlink.rb +29 -26
- data/test/tc_parser.rb +335 -329
- data/test/tc_parser_context.rb +188 -185
- data/test/tc_properties.rb +39 -36
- data/test/tc_reader.rb +297 -283
- data/test/tc_relaxng.rb +54 -51
- data/test/tc_sax_parser.rb +275 -273
- data/test/tc_schema.rb +53 -51
- data/test/tc_traversal.rb +222 -220
- data/test/tc_xinclude.rb +21 -19
- data/test/tc_xml.rb +3 -1
- data/test/tc_xpath.rb +195 -193
- data/test/tc_xpath_context.rb +80 -78
- data/test/tc_xpath_expression.rb +38 -35
- data/test/tc_xpointer.rb +74 -72
- data/test/test_helper.rb +14 -0
- data/test/test_suite.rb +39 -33
- metadata +65 -105
- data/doc/css/normal.css +0 -182
- data/doc/img/raze-tiny.png +0 -0
- data/doc/img/red-cube.jpg +0 -0
- data/doc/img/xml-ruby.png +0 -0
- data/doc/index.xml +0 -43
- data/doc/install.xml +0 -77
- data/doc/layout.rhtml +0 -38
- data/doc/layout.xsl +0 -67
- data/doc/license.xml +0 -32
- data/doc/log/changelog.xml +0 -1324
- data/doc/log/changelog.xsl +0 -42
- data/ext/libxml/Makefile +0 -156
- data/ext/libxml/extconf.h +0 -5
- 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 +0 -129
- data/ext/libxml/ruby_xml.o +0 -0
- 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.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.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.o +0 -0
- data/ext/libxml/ruby_xml_namespaces.o +0 -0
- data/ext/libxml/ruby_xml_node.o +0 -0
- data/ext/libxml/ruby_xml_parser.o +0 -0
- 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.o +0 -0
- data/ext/libxml/ruby_xml_schema.o +0 -0
- data/ext/libxml/ruby_xml_xinclude.o +0 -0
- data/ext/libxml/ruby_xml_xpath.o +0 -0
- 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.o +0 -0
data/test/tc_node_comment.rb
CHANGED
@@ -1,30 +1,33 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
@root.
|
29
|
-
|
30
|
-
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require './test_helper'
|
4
|
+
|
5
|
+
require 'test/unit'
|
6
|
+
|
7
|
+
class NodeCommentTest < Test::Unit::TestCase
|
8
|
+
def setup
|
9
|
+
xp = XML::Parser.string('<root></root>')
|
10
|
+
@doc = xp.parse
|
11
|
+
assert_instance_of(XML::Document, @doc)
|
12
|
+
@root = @doc.root
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_libxml_node_add_comment_01
|
16
|
+
@root << XML::Node.new_comment('mycomment')
|
17
|
+
assert_equal '<root><!--mycomment--></root>',
|
18
|
+
@root.to_s.gsub(/\n\s*/,'')
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_libxml_node_add_comment_02
|
22
|
+
@root << XML::Node.new_comment('mycomment')
|
23
|
+
assert_equal 'comment',
|
24
|
+
@root.child.node_type_name
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_libxml_node_add_comment_03
|
28
|
+
@root << el = XML::Node.new_comment('mycomment')
|
29
|
+
el << "_this_is_added"
|
30
|
+
assert_equal '<root><!--mycomment_this_is_added--></root>',
|
31
|
+
@root.to_s.gsub(/\n\s*/,'')
|
32
|
+
end
|
33
|
+
end
|
data/test/tc_node_copy.rb
CHANGED
@@ -1,40 +1,42 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
#
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
end
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require './test_helper'
|
4
|
+
require 'test/unit'
|
5
|
+
|
6
|
+
# see mailing list archive
|
7
|
+
# [libxml-devel] Segmentation fault when add the cloned/copied node
|
8
|
+
# 2007/11/27 20:51
|
9
|
+
|
10
|
+
class TestNodeCopy < Test::Unit::TestCase
|
11
|
+
def setup
|
12
|
+
str = <<-STR
|
13
|
+
<html><body>
|
14
|
+
<div class="textarea" id="t1" style="STATIC">foo</div>
|
15
|
+
<div class="textarea" id="t2" style="STATIC">bar</div>
|
16
|
+
</body></html>
|
17
|
+
STR
|
18
|
+
|
19
|
+
doc = XML::Parser.string(str).parse
|
20
|
+
|
21
|
+
xpath = "//div"
|
22
|
+
@div1 = doc.find(xpath).to_a[0]
|
23
|
+
@div2 = doc.find(xpath).to_a[1]
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_libxml_node_copy_not_segv
|
27
|
+
@div2.each do |child|
|
28
|
+
c = child.copy(false)
|
29
|
+
@div1 << c
|
30
|
+
end
|
31
|
+
assert @div1.to_s =~ /foo/
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_libxml_node_clone_not_segv
|
35
|
+
@div2.each do |child|
|
36
|
+
c = child.clone
|
37
|
+
@div1 << c
|
38
|
+
end
|
39
|
+
assert @div1.to_s =~ /foo/
|
40
|
+
end
|
41
|
+
|
42
|
+
end # TC_XML_Node_Copy
|
data/test/tc_node_edit.rb
CHANGED
@@ -1,158 +1,160 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
doc.
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require './test_helper'
|
4
|
+
require 'test/unit'
|
5
|
+
|
6
|
+
class TestNodeEdit < Test::Unit::TestCase
|
7
|
+
def setup
|
8
|
+
xp = XML::Parser.string('<test><num>one</num><num>two</num><num>three</num></test>')
|
9
|
+
@doc = xp.parse
|
10
|
+
end
|
11
|
+
|
12
|
+
def teardown
|
13
|
+
@doc = nil
|
14
|
+
end
|
15
|
+
|
16
|
+
def first_node
|
17
|
+
@doc.root.child
|
18
|
+
end
|
19
|
+
|
20
|
+
def second_node
|
21
|
+
first_node.next
|
22
|
+
end
|
23
|
+
|
24
|
+
def third_node
|
25
|
+
second_node.next
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_add_next_01
|
29
|
+
first_node.next = XML::Node.new('num', 'one-and-a-half')
|
30
|
+
assert_equal('<test><num>one</num><num>one-and-a-half</num><num>two</num><num>three</num></test>',
|
31
|
+
@doc.root.to_s.gsub(/\n\s*/,''))
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_add_next_02
|
35
|
+
second_node.next = XML::Node.new('num', 'two-and-a-half')
|
36
|
+
assert_equal('<test><num>one</num><num>two</num><num>two-and-a-half</num><num>three</num></test>',
|
37
|
+
@doc.root.to_s.gsub(/\n\s*/,''))
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_add_next_03
|
41
|
+
third_node.next = XML::Node.new('num', 'four')
|
42
|
+
assert_equal '<test><num>one</num><num>two</num><num>three</num><num>four</num></test>',
|
43
|
+
@doc.root.to_s.gsub(/\n\s*/,'')
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_add_prev_01
|
47
|
+
first_node.prev = XML::Node.new('num', 'half')
|
48
|
+
assert_equal '<test><num>half</num><num>one</num><num>two</num><num>three</num></test>',
|
49
|
+
@doc.root.to_s.gsub(/\n\s*/,'')
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_add_prev_02
|
53
|
+
second_node.prev = XML::Node.new('num', 'one-and-a-half')
|
54
|
+
assert_equal '<test><num>one</num><num>one-and-a-half</num><num>two</num><num>three</num></test>',
|
55
|
+
@doc.root.to_s.gsub(/\n\s*/,'')
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_add_prev_03
|
59
|
+
third_node.prev = XML::Node.new('num', 'two-and-a-half')
|
60
|
+
assert_equal '<test><num>one</num><num>two</num><num>two-and-a-half</num><num>three</num></test>',
|
61
|
+
@doc.root.to_s.gsub(/\n\s*/,'')
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_remove_node
|
65
|
+
first_node.remove!
|
66
|
+
assert_equal('<test><num>two</num><num>three</num></test>',
|
67
|
+
@doc.root.to_s.gsub(/\n\s*/,''))
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_remove_node_gc
|
71
|
+
xp = XML::Parser.string('<test><num>one</num><num>two</num><num>three</num></test>')
|
72
|
+
doc = xp.parse
|
73
|
+
node = doc.root.child.remove!
|
74
|
+
node = nil
|
75
|
+
GC.start
|
76
|
+
assert_not_nil(doc)
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_remove_node_iteration
|
80
|
+
nodes = Array.new
|
81
|
+
@doc.root.each_element do |node|
|
82
|
+
if node.name == 'num'
|
83
|
+
nodes << node
|
84
|
+
node.remove!
|
85
|
+
end
|
86
|
+
end
|
87
|
+
assert_equal(3, nodes.length)
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_reuse_removed_node
|
91
|
+
# Remove the node
|
92
|
+
node = @doc.root.first.remove!
|
93
|
+
assert_not_nil(node)
|
94
|
+
|
95
|
+
# Add it to the end of the documnet
|
96
|
+
@doc.root.last.next = node
|
97
|
+
|
98
|
+
assert_equal('<test><num>two</num><num>three</num><num>one</num></test>',
|
99
|
+
@doc.root.to_s.gsub(/\n\s*/,''))
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_append_existing_node
|
103
|
+
doc = XML::Parser.string('<top>a<bottom>b<one>first</one><two>second</two>c</bottom>d</top>').parse
|
104
|
+
node1 = doc.find_first('//two')
|
105
|
+
|
106
|
+
doc.root << node1
|
107
|
+
assert_equal('<top>a<bottom>b<one>first</one>c</bottom>d<two>second</two></top>',
|
108
|
+
doc.root.to_s)
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_wrong_doc
|
112
|
+
doc1 = XML::Parser.string('<nums><one></one></nums>').parse
|
113
|
+
doc2 = XML::Parser.string('<nums><two></two></nums>').parse
|
114
|
+
|
115
|
+
node = doc1.root.child
|
116
|
+
|
117
|
+
error = assert_raise(XML::Error) do
|
118
|
+
doc2.root << node
|
119
|
+
end
|
120
|
+
|
121
|
+
assert_equal(' Nodes belong to different documents. You must first import the by calling XML::Document.import.',
|
122
|
+
error.to_s)
|
123
|
+
end
|
124
|
+
|
125
|
+
|
126
|
+
# This test is to verify that an earlier reported bug has been fixed
|
127
|
+
def test_merge
|
128
|
+
documents = []
|
129
|
+
|
130
|
+
# Read in 500 documents
|
131
|
+
500.times do
|
132
|
+
documents << XML::Parser.string(File.read(File.join(File.dirname(__FILE__), 'model', 'merge_bug_data.xml'))).parse
|
133
|
+
end
|
134
|
+
|
135
|
+
master_doc = documents.shift
|
136
|
+
documents.inject(master_doc) do |master_doc, child_doc|
|
137
|
+
master_body = master_doc.find("//body").first
|
138
|
+
child_body = child_doc.find("//body").first
|
139
|
+
|
140
|
+
child_element = child_body.detect do |node|
|
141
|
+
node.element?
|
142
|
+
end
|
143
|
+
|
144
|
+
master_body << child_element.copy(true)
|
145
|
+
master_doc
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
def test_append_chain
|
150
|
+
node = XML::Node.new('foo') << XML::Node.new('bar') << "bars contents"
|
151
|
+
assert_equal('<foo><bar/>bars contents</foo>',
|
152
|
+
node.to_s)
|
153
|
+
end
|
154
|
+
|
155
|
+
def test_set_base
|
156
|
+
@doc.root.base_uri = 'http://www.rubynet.org/'
|
157
|
+
assert_equal("<test xml:base=\"http://www.rubynet.org/\">\n <num>one</num>\n <num>two</num>\n <num>three</num>\n</test>",
|
158
|
+
@doc.root.to_s)
|
159
|
+
end
|
158
160
|
end
|