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_error.rb
CHANGED
data/test/tc_html_parser.rb
CHANGED
@@ -1,138 +1,140 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require '
|
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
|
-
file =
|
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
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
assert_equal '
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require './test_helper'
|
4
|
+
require 'stringio'
|
5
|
+
require 'test/unit'
|
6
|
+
|
7
|
+
class HTMLParserTest < Test::Unit::TestCase
|
8
|
+
def html_file
|
9
|
+
File.expand_path(File.join(File.dirname(__FILE__), 'model/ruby-lang.html'))
|
10
|
+
end
|
11
|
+
|
12
|
+
# ----- Sources ------
|
13
|
+
def test_file
|
14
|
+
xp = XML::HTMLParser.file(html_file)
|
15
|
+
assert_instance_of(XML::HTMLParser, xp)
|
16
|
+
doc = xp.parse
|
17
|
+
assert_not_nil(doc)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_noexistent_file
|
21
|
+
error = assert_raise(XML::Error) do
|
22
|
+
XML::HTMLParser.file('i_dont_exist.xml')
|
23
|
+
end
|
24
|
+
|
25
|
+
assert_equal('Warning: failed to load external entity "i_dont_exist.xml".', error.to_s)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_nil_file
|
29
|
+
error = assert_raise(TypeError) do
|
30
|
+
XML::HTMLParser.file(nil)
|
31
|
+
end
|
32
|
+
|
33
|
+
assert_equal("can't convert nil into String", error.to_s)
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_io
|
37
|
+
File.open(html_file) do |io|
|
38
|
+
xp = XML::HTMLParser.io(io)
|
39
|
+
assert_instance_of(XML::HTMLParser, xp)
|
40
|
+
|
41
|
+
doc = xp.parse
|
42
|
+
assert_instance_of(XML::Document, doc)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_io_gc
|
47
|
+
# Test that the reader keeps a reference
|
48
|
+
# to the io object
|
49
|
+
file = File.open(html_file)
|
50
|
+
parser = XML::HTMLParser.io(file)
|
51
|
+
file = nil
|
52
|
+
GC.start
|
53
|
+
assert(parser.parse)
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_nil_io
|
57
|
+
error = assert_raise(TypeError) do
|
58
|
+
XML::HTMLParser.io(nil)
|
59
|
+
end
|
60
|
+
|
61
|
+
assert_equal("Must pass in an IO object", error.to_s)
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_string_io
|
65
|
+
data = File.read(html_file)
|
66
|
+
io = StringIO.new(data)
|
67
|
+
xp = XML::HTMLParser.io(io)
|
68
|
+
assert_instance_of(XML::HTMLParser, xp)
|
69
|
+
|
70
|
+
doc = xp.parse
|
71
|
+
assert_instance_of(XML::Document, doc)
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_string
|
75
|
+
str = '<html><body><p>hi</p></body></html>'
|
76
|
+
xp = XML::HTMLParser.string(str)
|
77
|
+
|
78
|
+
assert_instance_of(XML::HTMLParser, xp)
|
79
|
+
assert_instance_of(XML::HTMLParser, xp)
|
80
|
+
|
81
|
+
doc = xp.parse
|
82
|
+
assert_instance_of(XML::Document, doc)
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_nil_string
|
86
|
+
error = assert_raise(TypeError) do
|
87
|
+
XML::HTMLParser.string(nil)
|
88
|
+
end
|
89
|
+
|
90
|
+
assert_equal("wrong argument type nil (expected String)", error.to_s)
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_parse
|
94
|
+
html = <<-EOS
|
95
|
+
<html>
|
96
|
+
<head>
|
97
|
+
<meta name=keywords content=nasty>
|
98
|
+
</head>
|
99
|
+
<body>Hello<br>World</html>
|
100
|
+
EOS
|
101
|
+
|
102
|
+
parser = XML::HTMLParser.string(html)
|
103
|
+
doc = parser.parse
|
104
|
+
assert_instance_of XML::Document, doc
|
105
|
+
|
106
|
+
root = doc.root
|
107
|
+
assert_instance_of XML::Node, root
|
108
|
+
assert_equal 'html', root.name
|
109
|
+
|
110
|
+
head = root.child
|
111
|
+
assert_instance_of XML::Node, head
|
112
|
+
assert_equal 'head', head.name
|
113
|
+
|
114
|
+
meta = head.child
|
115
|
+
assert_instance_of XML::Node, meta
|
116
|
+
assert_equal 'meta', meta.name
|
117
|
+
assert_equal 'keywords', meta[:name]
|
118
|
+
assert_equal 'nasty', meta[:content]
|
119
|
+
|
120
|
+
body = head.next
|
121
|
+
assert_instance_of XML::Node, body
|
122
|
+
assert_equal 'body', body.name
|
123
|
+
|
124
|
+
hello = body.child
|
125
|
+
# It appears that some versions of libxml2 add a layer of <p>
|
126
|
+
# cant figure our why or how, so this skips it if there
|
127
|
+
hello = hello.child if hello.name == "p"
|
128
|
+
|
129
|
+
assert_instance_of XML::Node, hello
|
130
|
+
assert_equal 'Hello', hello.content
|
131
|
+
|
132
|
+
br = hello.next
|
133
|
+
assert_instance_of XML::Node, br
|
134
|
+
assert_equal 'br', br.name
|
135
|
+
|
136
|
+
world = br.next
|
137
|
+
assert_instance_of XML::Node, world
|
138
|
+
assert_equal 'World', world.content
|
139
|
+
end
|
138
140
|
end
|
data/test/tc_namespace.rb
CHANGED
@@ -1,59 +1,62 @@
|
|
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
|
-
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require './test_helper'
|
4
|
+
|
5
|
+
require 'test/unit'
|
6
|
+
|
7
|
+
class TestNS < Test::Unit::TestCase
|
8
|
+
def setup
|
9
|
+
file = File.join(File.dirname(__FILE__), 'model/soap.xml')
|
10
|
+
@doc = XML::Document.file(file)
|
11
|
+
end
|
12
|
+
|
13
|
+
def teardown
|
14
|
+
@doc = nil
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_create_ns
|
18
|
+
node = XML::Node.new('foo')
|
19
|
+
ns = XML::Namespace.new(node, 'my_namepace', 'http://www.mynamespace.com')
|
20
|
+
assert_equal(ns.prefix, 'my_namepace')
|
21
|
+
assert_equal(ns.href, 'http://www.mynamespace.com')
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_create_default_ns
|
25
|
+
node = XML::Node.new('foo')
|
26
|
+
ns = XML::Namespace.new(node, nil, 'http://www.mynamespace.com')
|
27
|
+
assert_equal(ns.prefix, nil)
|
28
|
+
assert_equal(ns.href, 'http://www.mynamespace.com')
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_create_unbound_ns
|
32
|
+
error = assert_raise(TypeError) do
|
33
|
+
XML::Namespace.new(nil, 'my_namepace', 'http://www.mynamespace.com')
|
34
|
+
end
|
35
|
+
assert_equal('wrong argument type nil (expected Data)', error.to_s)
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_duplicate_ns
|
39
|
+
node = XML::Node.new('foo')
|
40
|
+
XML::Namespace.new(node, 'myname', 'http://www.mynamespace.com')
|
41
|
+
assert_raises(XML::Error) do
|
42
|
+
XML::Namespace.new(node, 'myname', 'http://www.mynamespace.com')
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_eql
|
47
|
+
node = XML::Node.new('Envelope')
|
48
|
+
ns = XML::Namespace.new(node, 'soap', 'http://schemas.xmlsoap.org/soap/envelope/')
|
49
|
+
|
50
|
+
assert(node.namespaces.namespace.eql?(node.namespaces.namespace))
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_equal
|
54
|
+
node1 = XML::Node.new('Envelope')
|
55
|
+
ns1 = XML::Namespace.new(node1, 'soap', 'http://schemas.xmlsoap.org/soap/envelope/')
|
56
|
+
|
57
|
+
node2 = XML::Node.new('Envelope')
|
58
|
+
ns2 = XML::Namespace.new(node2, 'soap', 'http://schemas.xmlsoap.org/soap/envelope/')
|
59
|
+
|
60
|
+
assert(ns1 == ns2)
|
61
|
+
end
|
59
62
|
end
|
data/test/tc_namespaces.rb
CHANGED
@@ -1,174 +1,177 @@
|
|
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
|
-
assert_equal(
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
node.namespaces.namespace
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
XML::
|
40
|
-
assert_equal(
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
XML::
|
49
|
-
assert_equal(
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
namespace
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
namespace
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
namespace
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
namespace
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
namespace
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
namespace
|
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
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require './test_helper'
|
4
|
+
|
5
|
+
require 'test/unit'
|
6
|
+
|
7
|
+
class TestNamespaces < Test::Unit::TestCase
|
8
|
+
def setup
|
9
|
+
file = File.join(File.dirname(__FILE__), 'model/soap.xml')
|
10
|
+
@doc = XML::Document.file(file)
|
11
|
+
end
|
12
|
+
|
13
|
+
def teardown
|
14
|
+
@doc = nil
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_namespace
|
18
|
+
node = @doc.root
|
19
|
+
ns = node.namespaces.namespace
|
20
|
+
assert_equal('soap', ns.prefix)
|
21
|
+
assert_equal('http://schemas.xmlsoap.org/soap/envelope/', ns.href)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_set_namespace
|
25
|
+
node = XML::Node.new('Envelope')
|
26
|
+
assert_equal('<Envelope/>', node.to_s)
|
27
|
+
|
28
|
+
ns = XML::Namespace.new(node, 'soap', 'http://schemas.xmlsoap.org/soap/envelope/')
|
29
|
+
assert_equal("<Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"/>", node.to_s)
|
30
|
+
assert_nil(node.namespaces.namespace)
|
31
|
+
|
32
|
+
# Now put the node in the soap namespace
|
33
|
+
node.namespaces.namespace = ns
|
34
|
+
assert_not_nil(node.namespaces.namespace)
|
35
|
+
assert_equal("<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"/>", node.to_s)
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_define_namespace
|
39
|
+
node = XML::Node.new('Envelope')
|
40
|
+
assert_equal('<Envelope/>', node.to_s)
|
41
|
+
|
42
|
+
XML::Namespace.new(node, 'soap', 'http://schemas.xmlsoap.org/soap/envelope/')
|
43
|
+
assert_equal("<Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"/>", node.to_s)
|
44
|
+
assert_nil(node.namespaces.namespace)
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_define_default_namespace
|
48
|
+
node = XML::Node.new('Envelope')
|
49
|
+
assert_equal('<Envelope/>', node.to_s)
|
50
|
+
|
51
|
+
XML::Namespace.new(node, nil, 'http://schemas.xmlsoap.org/soap/envelope/')
|
52
|
+
assert_equal("<Envelope xmlns=\"http://schemas.xmlsoap.org/soap/envelope/\"/>", node.to_s)
|
53
|
+
# This seems wrong, but appears to be the way libxml works
|
54
|
+
assert_nil(node.namespaces.namespace)
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_namespaces
|
58
|
+
node = @doc.find_first('//ns1:IdAndName',
|
59
|
+
:ns1 => 'http://domain.somewhere.com')
|
60
|
+
|
61
|
+
namespaces = node.namespaces.sort
|
62
|
+
assert_equal(5, namespaces.length)
|
63
|
+
|
64
|
+
namespace = namespaces[0]
|
65
|
+
assert_instance_of(XML::Namespace, namespace)
|
66
|
+
assert_equal(nil, namespace.prefix)
|
67
|
+
assert_equal('http://services.somewhere.com', namespace.href)
|
68
|
+
|
69
|
+
namespace = namespaces[1]
|
70
|
+
assert_instance_of(XML::Namespace, namespace)
|
71
|
+
assert_equal('ns1', namespace.prefix)
|
72
|
+
assert_equal('http://domain.somewhere.com', namespace.href)
|
73
|
+
|
74
|
+
namespace = namespaces[2]
|
75
|
+
assert_instance_of(XML::Namespace, namespace)
|
76
|
+
assert_equal('soap', namespace.prefix)
|
77
|
+
assert_equal('http://schemas.xmlsoap.org/soap/envelope/', namespace.href)
|
78
|
+
|
79
|
+
namespace = namespaces[3]
|
80
|
+
assert_instance_of(XML::Namespace, namespace)
|
81
|
+
assert_equal('xsd', namespace.prefix)
|
82
|
+
assert_equal('http://www.w3.org/2001/XMLSchema', namespace.href)
|
83
|
+
|
84
|
+
namespace = namespaces[4]
|
85
|
+
assert_instance_of(XML::Namespace, namespace)
|
86
|
+
assert_equal('xsi', namespace.prefix)
|
87
|
+
assert_equal('http://www.w3.org/2001/XMLSchema-instance', namespace.href)
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_namespaces
|
91
|
+
node = @doc.find_first('//ns1:IdAndName',
|
92
|
+
:ns1 => 'http://domain.somewhere.com')
|
93
|
+
|
94
|
+
namespaces = node.namespaces.each do |namespace|
|
95
|
+
assert_instance_of(XML::Namespace, namespace)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_namespace_definitions
|
100
|
+
ns_defs = @doc.root.namespaces.definitions
|
101
|
+
assert_equal(3, ns_defs.size)
|
102
|
+
|
103
|
+
namespace = ns_defs[0]
|
104
|
+
assert_instance_of(XML::Namespace, namespace)
|
105
|
+
assert_equal('soap', namespace.prefix)
|
106
|
+
assert_equal('http://schemas.xmlsoap.org/soap/envelope/', namespace.href)
|
107
|
+
|
108
|
+
namespace = ns_defs[1]
|
109
|
+
assert_instance_of(XML::Namespace, namespace)
|
110
|
+
assert_equal('xsd', namespace.prefix)
|
111
|
+
assert_equal('http://www.w3.org/2001/XMLSchema', namespace.href)
|
112
|
+
|
113
|
+
namespace = ns_defs[2]
|
114
|
+
assert_instance_of(XML::Namespace, namespace)
|
115
|
+
assert_equal('xsi', namespace.prefix)
|
116
|
+
assert_equal('http://www.w3.org/2001/XMLSchema-instance', namespace.href)
|
117
|
+
|
118
|
+
node = @doc.root.find_first('//ns:getManufacturerNamesResponse',
|
119
|
+
:ns => 'http://services.somewhere.com')
|
120
|
+
ns_defs = node.namespaces.definitions
|
121
|
+
assert_equal(1, ns_defs.size)
|
122
|
+
|
123
|
+
namespace = ns_defs[0]
|
124
|
+
assert_instance_of(XML::Namespace, namespace)
|
125
|
+
assert_equal(nil, namespace.prefix)
|
126
|
+
assert_equal('http://services.somewhere.com', namespace.href)
|
127
|
+
end
|
128
|
+
|
129
|
+
def test_find_by_prefix
|
130
|
+
node = @doc.find_first('//ns1:getManufacturerNamesResponse',
|
131
|
+
:ns1 => 'http://services.somewhere.com')
|
132
|
+
|
133
|
+
namespace = @doc.root.namespaces.find_by_prefix('soap')
|
134
|
+
|
135
|
+
assert_instance_of(XML::Namespace, namespace)
|
136
|
+
assert_equal('soap', namespace.prefix)
|
137
|
+
assert_equal('http://schemas.xmlsoap.org/soap/envelope/', namespace.href)
|
138
|
+
end
|
139
|
+
|
140
|
+
def test_find_default_ns
|
141
|
+
namespace = @doc.root.namespaces.find_by_prefix(nil)
|
142
|
+
assert_nil(namespace)
|
143
|
+
|
144
|
+
node = @doc.find_first('//ns1:getManufacturerNamesResponse',
|
145
|
+
:ns1 => 'http://services.somewhere.com')
|
146
|
+
namespace = node.namespaces.find_by_prefix(nil)
|
147
|
+
|
148
|
+
assert_instance_of(XML::Namespace, namespace)
|
149
|
+
assert_equal(nil, namespace.prefix)
|
150
|
+
assert_equal('http://services.somewhere.com', namespace.href)
|
151
|
+
end
|
152
|
+
|
153
|
+
def test_find_ns_by_href
|
154
|
+
node = @doc.find_first('//ns1:getManufacturerNamesResponse',
|
155
|
+
:ns1 => 'http://services.somewhere.com')
|
156
|
+
|
157
|
+
namespace = node.namespaces.find_by_href('http://schemas.xmlsoap.org/soap/envelope/')
|
158
|
+
|
159
|
+
assert_instance_of(XML::Namespace, namespace)
|
160
|
+
assert_equal('soap', namespace.prefix)
|
161
|
+
assert_equal('http://schemas.xmlsoap.org/soap/envelope/', namespace.href)
|
162
|
+
end
|
163
|
+
|
164
|
+
def test_default_namespace
|
165
|
+
doc = XML::Document.string('<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"/>')
|
166
|
+
ns = doc.root.namespaces.default
|
167
|
+
assert_equal(ns.href, 'http://schemas.xmlsoap.org/soap/envelope/')
|
168
|
+
end
|
169
|
+
|
170
|
+
def test_default_prefix
|
171
|
+
doc = XML::Document.string('<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"/>')
|
172
|
+
doc.root.namespaces.default_prefix = 'soap'
|
173
|
+
|
174
|
+
node = doc.root.find_first('/soap:Envelope')
|
175
|
+
assert_not_nil(node)
|
176
|
+
end
|
174
177
|
end
|