libxml-ruby 0.9.5-x86-mswin32-60 → 0.9.6-x86-mswin32-60
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +28 -0
- data/README +8 -12
- data/ext/libxml/cbg.c +86 -86
- data/ext/libxml/libxml.c +875 -899
- data/ext/libxml/ruby_libxml.h +91 -65
- data/ext/libxml/ruby_xml_attr.c +485 -485
- data/ext/libxml/ruby_xml_attr.h +3 -3
- data/ext/libxml/ruby_xml_attributes.h +2 -2
- data/ext/libxml/ruby_xml_document.c +124 -307
- data/ext/libxml/ruby_xml_document.h +3 -3
- data/ext/libxml/ruby_xml_dtd.c +119 -119
- data/ext/libxml/ruby_xml_dtd.h +2 -2
- data/ext/libxml/ruby_xml_error.c +1 -1
- data/ext/libxml/ruby_xml_error.h +2 -2
- data/ext/libxml/ruby_xml_html_parser.c +119 -119
- data/ext/libxml/ruby_xml_html_parser.h +3 -3
- data/ext/libxml/ruby_xml_input.c +13 -11
- data/ext/libxml/ruby_xml_input.h +3 -3
- data/ext/libxml/ruby_xml_input_cbg.c +197 -197
- data/ext/libxml/ruby_xml_namespace.c +158 -0
- data/ext/libxml/ruby_xml_namespace.h +12 -0
- data/ext/libxml/ruby_xml_namespaces.c +303 -0
- data/ext/libxml/{ruby_xml_ns.h → ruby_xml_namespaces.h} +4 -5
- data/ext/libxml/ruby_xml_node.c +88 -293
- data/ext/libxml/ruby_xml_node.h +4 -4
- data/ext/libxml/ruby_xml_parser.c +152 -152
- data/ext/libxml/ruby_xml_parser.h +3 -3
- data/ext/libxml/ruby_xml_parser_context.c +630 -657
- data/ext/libxml/ruby_xml_parser_context.h +3 -3
- data/ext/libxml/ruby_xml_reader.c +899 -904
- data/ext/libxml/ruby_xml_reader.h +2 -2
- data/ext/libxml/ruby_xml_relaxng.h +2 -2
- data/ext/libxml/ruby_xml_sax_parser.c +175 -175
- data/ext/libxml/ruby_xml_sax_parser.h +3 -3
- data/ext/libxml/ruby_xml_schema.c +165 -165
- data/ext/libxml/ruby_xml_schema.h +2 -2
- data/ext/libxml/ruby_xml_state.h +2 -2
- data/ext/libxml/ruby_xml_xinclude.c +24 -24
- data/ext/libxml/ruby_xml_xinclude.h +3 -3
- data/ext/libxml/ruby_xml_xpath.c +108 -108
- data/ext/libxml/ruby_xml_xpath.h +3 -3
- data/ext/libxml/ruby_xml_xpath_context.c +84 -35
- data/ext/libxml/ruby_xml_xpath_context.h +3 -3
- data/ext/libxml/ruby_xml_xpath_expression.c +5 -7
- data/ext/libxml/ruby_xml_xpath_expression.h +2 -2
- data/ext/libxml/ruby_xml_xpath_object.c +7 -7
- data/ext/libxml/ruby_xml_xpath_object.h +2 -2
- data/ext/libxml/ruby_xml_xpointer.c +107 -107
- data/ext/libxml/ruby_xml_xpointer.h +3 -3
- data/ext/libxml/version.h +2 -2
- data/ext/mingw/libxml_ruby.dll.a +0 -0
- data/ext/mingw/libxml_ruby.so +0 -0
- data/ext/vc/libxml_ruby.vcproj +13 -5
- data/lib/libxml.rb +4 -1
- data/lib/libxml/document.rb +40 -6
- data/lib/libxml/hpricot.rb +76 -76
- data/lib/libxml/namespace.rb +60 -0
- data/lib/libxml/namespaces.rb +36 -0
- data/lib/libxml/node.rb +90 -26
- data/lib/libxml/ns.rb +20 -0
- data/test/model/bands.xml +5 -0
- data/test/tc_attributes.rb +1 -1
- data/test/tc_document.rb +24 -41
- data/test/tc_document_write.rb +87 -115
- data/test/tc_namespace.rb +59 -0
- data/test/tc_namespaces.rb +174 -0
- data/test/tc_node.rb +41 -33
- data/test/tc_node_copy.rb +1 -1
- data/test/tc_node_edit.rb +6 -0
- data/test/tc_node_write.rb +76 -0
- data/test/tc_xinclude.rb +2 -9
- data/test/tc_xpath.rb +38 -11
- data/test/test_suite.rb +3 -1
- metadata +16 -9
- data/ext/libxml/ruby_xml_ns.c +0 -150
- data/test/ets_copy_bug.rb +0 -21
- data/test/ets_copy_bug3.rb +0 -38
- data/test/model/default_validation_bug.rb +0 -0
- data/test/tc_ns.rb +0 -18
data/test/tc_document_write.rb
CHANGED
@@ -1,146 +1,118 @@
|
|
1
|
-
require
|
1
|
+
require 'xml'
|
2
|
+
require 'tmpdir'
|
2
3
|
require 'test/unit'
|
3
4
|
|
4
5
|
class TestDocumentWrite < Test::Unit::TestCase
|
5
6
|
def setup
|
6
|
-
|
7
|
+
# Strip spaces to make testing easier
|
8
|
+
XML.default_keep_blanks = false
|
9
|
+
file = File.join(File.dirname(__FILE__), 'model/bands.xml')
|
10
|
+
@doc = XML::Document.file(file)
|
7
11
|
end
|
8
12
|
|
9
13
|
def teardown
|
14
|
+
XML.default_keep_blanks = true
|
10
15
|
@doc = nil
|
11
16
|
end
|
12
17
|
|
13
|
-
|
14
|
-
|
18
|
+
# --- to_s tests ---
|
19
|
+
def test_to_s_default
|
20
|
+
# Default to_s has indentation
|
21
|
+
assert_equal("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<bands genre=\"metal\">\n <m\303\266tley_cr\303\274e country=\"us\">An American heavy metal band formed in Los Angeles, California in 1981.</m\303\266tley_cr\303\274e>\n <iron_maiden country=\"uk\">British heavy metal band formed in 1975.</iron_maiden>\n</bands>\n",
|
22
|
+
@doc.to_s)
|
15
23
|
end
|
16
24
|
|
17
|
-
def
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
def test_write_root
|
25
|
-
@doc.root = XML::Node.new('rubynet')
|
26
|
-
assert_instance_of(XML::Node, @doc.root)
|
27
|
-
assert_instance_of(XML::Document, @doc.root.doc)
|
28
|
-
assert_equal("<?xml version=\"1.0\"?>\n<rubynet/>\n", @doc.to_s)
|
25
|
+
def test_to_s_no_global_indentation
|
26
|
+
# No indentation due to global setting
|
27
|
+
XML.indent_tree_output = false
|
28
|
+
assert_equal("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<bands genre=\"metal\">\n<m\303\266tley_cr\303\274e country=\"us\">An American heavy metal band formed in Los Angeles, California in 1981.</m\303\266tley_cr\303\274e>\n<iron_maiden country=\"uk\">British heavy metal band formed in 1975.</iron_maiden>\n</bands>\n",
|
29
|
+
@doc.to_s)
|
30
|
+
ensure
|
31
|
+
XML.indent_tree_output = true
|
29
32
|
end
|
30
33
|
|
31
|
-
def
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
assert_equal("<?xml version=\"1.0\"?>\n<rubynet/>\n", @doc.to_s(false))
|
34
|
+
def test_to_s_no_indentation
|
35
|
+
# No indentation due to local setting
|
36
|
+
assert_equal("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<bands genre=\"metal\"><m\303\266tley_cr\303\274e country=\"us\">An American heavy metal band formed in Los Angeles, California in 1981.</m\303\266tley_cr\303\274e><iron_maiden country=\"uk\">British heavy metal band formed in 1975.</iron_maiden></bands>\n",
|
37
|
+
@doc.to_s(:indent => false))
|
36
38
|
end
|
37
39
|
|
38
|
-
def
|
39
|
-
|
40
|
-
@doc.root = XML::Node.new('rubynet')
|
41
|
-
@doc.root.child = XML::Node.new('pkg')
|
42
|
-
assert_equal(xml, @doc.to_s)
|
43
|
-
end
|
40
|
+
def test_to_s_encoding
|
41
|
+
# Test encodings
|
44
42
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
xml
|
49
|
-
|
50
|
-
xml << " <pkgname>libxml</pkgname>\n"
|
51
|
-
xml << " </meta>\n"
|
52
|
-
xml << " </pkg>\n"
|
53
|
-
xml << "</rubynet>\n"
|
54
|
-
|
55
|
-
@doc.root = XML::Node.new('rubynet')
|
56
|
-
pkg = @doc.root.child = XML::Node.new('pkg')
|
57
|
-
meta = pkg.child = XML::Node.new('meta')
|
58
|
-
assert_equal(meta, meta << (pkgname = XML::Node.new('pkgname')))
|
59
|
-
pkgname << 'libxml'
|
60
|
-
assert_equal(xml, @doc.to_s)
|
61
|
-
end
|
43
|
+
# UTF8:
|
44
|
+
# ö - c3 b6 in hex, \303\266 in octal
|
45
|
+
# ü - c3 bc in hex, \303\274 in octal
|
46
|
+
assert_equal("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<bands genre=\"metal\">\n <m\303\266tley_cr\303\274e country=\"us\">An American heavy metal band formed in Los Angeles, California in 1981.</m\303\266tley_cr\303\274e>\n <iron_maiden country=\"uk\">British heavy metal band formed in 1975.</iron_maiden>\n</bands>\n",
|
47
|
+
@doc.to_s(:encoding => XML::Input::UTF_8))
|
62
48
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
xml << " <pkg/>\n"
|
69
|
-
xml << "</rubynet>\n"
|
70
|
-
|
71
|
-
@doc.root = XML::Node.new('rubynet')
|
72
|
-
@doc = XML::Parser.string(xml).parse
|
73
|
-
assert_equal(xml, @doc.to_s)
|
74
|
-
ns = @doc.root.search_href(uri)
|
75
|
-
assert_instance_of(XML::NS, ns)
|
76
|
-
assert_equal(uri, ns.href)
|
77
|
-
assert_equal(prefix, ns.prefix)
|
78
|
-
end
|
49
|
+
# ISO_8859_1:
|
50
|
+
# ö - f6 in hex, \366 in octal
|
51
|
+
# ü - fc in hex, \374 in octal
|
52
|
+
assert_equal("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n<bands genre=\"metal\">\n <m\366tley_cr\374e country=\"us\">An American heavy metal band formed in Los Angeles, California in 1981.</m\366tley_cr\374e>\n <iron_maiden country=\"uk\">British heavy metal band formed in 1975.</iron_maiden>\n</bands>\n",
|
53
|
+
@doc.to_s(:encoding => XML::Input::ISO_8859_1))
|
79
54
|
|
80
|
-
def test_sibling
|
81
|
-
xml = "<?xml version=\"1.0\"?>\n<rubynet>\n <pkg/>\n <pkg2/>\n</rubynet>\n"
|
82
55
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
assert_equal(
|
56
|
+
# Invalid encoding
|
57
|
+
error = assert_raise(ArgumentError) do
|
58
|
+
@doc.to_s(:encoding => -9999)
|
59
|
+
end
|
60
|
+
assert_equal('Unknown encoding.', error.to_s)
|
88
61
|
end
|
89
62
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
63
|
+
# --- save tests -----
|
64
|
+
def test_save_utf8
|
65
|
+
temp_filename = File.join(Dir.tmpdir, "tc_document_write_test_save_utf8.xml")
|
66
|
+
|
67
|
+
bytes = @doc.save(temp_filename)
|
68
|
+
assert_equal(271, bytes)
|
69
|
+
|
70
|
+
contents = File.read(temp_filename)
|
71
|
+
assert_equal("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<bands genre=\"metal\">\n <m\303\266tley_cr\303\274e country=\"us\">An American heavy metal band formed in Los Angeles, California in 1981.</m\303\266tley_cr\303\274e>\n <iron_maiden country=\"uk\">British heavy metal band formed in 1975.</iron_maiden>\n</bands>\n",
|
72
|
+
contents)
|
73
|
+
ensure
|
74
|
+
File.delete(temp_filename)
|
100
75
|
end
|
101
76
|
|
102
|
-
def
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
77
|
+
def test_save_utf8_no_indents
|
78
|
+
temp_filename = File.join(Dir.tmpdir, "tc_document_write_test_save_utf8_no_indents.xml")
|
79
|
+
|
80
|
+
bytes = @doc.save(temp_filename, :indent => false)
|
81
|
+
assert_equal(264, bytes)
|
82
|
+
|
83
|
+
contents = File.read(temp_filename)
|
84
|
+
assert_equal("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<bands genre=\"metal\"><m\303\266tley_cr\303\274e country=\"us\">An American heavy metal band formed in Los Angeles, California in 1981.</m\303\266tley_cr\303\274e><iron_maiden country=\"uk\">British heavy metal band formed in 1975.</iron_maiden></bands>\n",
|
85
|
+
contents)
|
86
|
+
ensure
|
87
|
+
File.delete(temp_filename)
|
112
88
|
end
|
113
89
|
|
114
|
-
def
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
xml
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
@doc.root = XML::Node.new('rubynet')
|
125
|
-
@doc.root['xmlns:xlink'] = "http://www.w3.org/1999/xlink"
|
126
|
-
pkg = @doc.root.child = XML::Node.new('pkg')
|
127
|
-
pkg['version'] = '1.0'
|
128
|
-
meta = pkg.child = XML::Node.new('meta')
|
129
|
-
pkgname = meta.child = XML::Node.new('pkgname', 'libxml')
|
130
|
-
assert_equal(xml, @doc.to_s)
|
90
|
+
def test_save_iso_8859_1
|
91
|
+
temp_filename = File.join(Dir.tmpdir, "tc_document_write_test_save_iso_8859_1.xml")
|
92
|
+
bytes = @doc.save(temp_filename, :encoding => XML::Input::ISO_8859_1)
|
93
|
+
assert_equal(272, bytes)
|
94
|
+
|
95
|
+
contents = File.read(temp_filename)
|
96
|
+
assert_equal("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n<bands genre=\"metal\">\n <m\366tley_cr\374e country=\"us\">An American heavy metal band formed in Los Angeles, California in 1981.</m\366tley_cr\374e>\n <iron_maiden country=\"uk\">British heavy metal band formed in 1975.</iron_maiden>\n</bands>\n",
|
97
|
+
contents)
|
98
|
+
ensure
|
99
|
+
File.delete(temp_filename)
|
131
100
|
end
|
132
101
|
|
133
|
-
def
|
134
|
-
|
135
|
-
@doc.encoding
|
136
|
-
|
137
|
-
|
102
|
+
def test_save_iso_8859_1_no_indent
|
103
|
+
temp_filename = File.join(Dir.tmpdir, "tc_document_write_test_save_iso_8859_1_no_indent.xml")
|
104
|
+
bytes = @doc.save(temp_filename, :indent => false, :encoding => XML::Input::ISO_8859_1)
|
105
|
+
assert_equal(265, bytes)
|
106
|
+
|
107
|
+
contents = File.read(temp_filename)
|
108
|
+
assert_equal("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n<bands genre=\"metal\"><m\366tley_cr\374e country=\"us\">An American heavy metal band formed in Los Angeles, California in 1981.</m\366tley_cr\374e><iron_maiden country=\"uk\">British heavy metal band formed in 1975.</iron_maiden></bands>\n",
|
109
|
+
contents)
|
110
|
+
ensure
|
111
|
+
File.delete(temp_filename)
|
138
112
|
end
|
139
113
|
|
140
|
-
|
141
|
-
|
142
|
-
@doc.
|
143
|
-
assert_instance_of(XML::Node, @doc.root)
|
144
|
-
assert_equal("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n<rubynet/>\n", @doc.to_s)
|
114
|
+
# --- Debug ---
|
115
|
+
def test_debug
|
116
|
+
assert(@doc.debug)
|
145
117
|
end
|
146
|
-
end
|
118
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require "xml"
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
class TestNS < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
file = File.join(File.dirname(__FILE__), 'model/soap.xml')
|
7
|
+
@doc = XML::Document.file(file)
|
8
|
+
end
|
9
|
+
|
10
|
+
def teardown
|
11
|
+
@doc = nil
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_create_ns
|
15
|
+
node = XML::Node.new('foo')
|
16
|
+
ns = XML::Namespace.new(node, 'my_namepace', 'http://www.mynamespace.com')
|
17
|
+
assert_equal(ns.prefix, 'my_namepace')
|
18
|
+
assert_equal(ns.href, 'http://www.mynamespace.com')
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_create_default_ns
|
22
|
+
node = XML::Node.new('foo')
|
23
|
+
ns = XML::Namespace.new(node, nil, 'http://www.mynamespace.com')
|
24
|
+
assert_equal(ns.prefix, nil)
|
25
|
+
assert_equal(ns.href, 'http://www.mynamespace.com')
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_create_unbound_ns
|
29
|
+
error = assert_raise(TypeError) do
|
30
|
+
XML::Namespace.new(nil, 'my_namepace', 'http://www.mynamespace.com')
|
31
|
+
end
|
32
|
+
assert_equal('wrong argument type nil (expected Data)', error.to_s)
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_duplicate_ns
|
36
|
+
node = XML::Node.new('foo')
|
37
|
+
XML::Namespace.new(node, 'myname', 'http://www.mynamespace.com')
|
38
|
+
assert_raises(XML::Error) do
|
39
|
+
XML::Namespace.new(node, 'myname', 'http://www.mynamespace.com')
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_eql
|
44
|
+
node = XML::Node.new('Envelope')
|
45
|
+
ns = XML::Namespace.new(node, 'soap', 'http://schemas.xmlsoap.org/soap/envelope/')
|
46
|
+
|
47
|
+
assert(node.namespaces.namespace.eql?(node.namespaces.namespace))
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_equal
|
51
|
+
node1 = XML::Node.new('Envelope')
|
52
|
+
ns1 = XML::Namespace.new(node1, 'soap', 'http://schemas.xmlsoap.org/soap/envelope/')
|
53
|
+
|
54
|
+
node2 = XML::Node.new('Envelope')
|
55
|
+
ns2 = XML::Namespace.new(node2, 'soap', 'http://schemas.xmlsoap.org/soap/envelope/')
|
56
|
+
|
57
|
+
assert(ns1 == ns2)
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,174 @@
|
|
1
|
+
require "xml"
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
class TestNamespaces < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
file = File.join(File.dirname(__FILE__), 'model/soap.xml')
|
7
|
+
@doc = XML::Document.file(file)
|
8
|
+
end
|
9
|
+
|
10
|
+
def teardown
|
11
|
+
@doc = nil
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_namespace
|
15
|
+
node = @doc.root
|
16
|
+
ns = node.namespaces.namespace
|
17
|
+
assert_equal('soap', ns.prefix)
|
18
|
+
assert_equal('http://schemas.xmlsoap.org/soap/envelope/', ns.href)
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_set_namespace
|
22
|
+
node = XML::Node.new('Envelope')
|
23
|
+
assert_equal('<Envelope/>', node.to_s)
|
24
|
+
|
25
|
+
ns = XML::Namespace.new(node, 'soap', 'http://schemas.xmlsoap.org/soap/envelope/')
|
26
|
+
assert_equal("<Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"/>", node.to_s)
|
27
|
+
assert_nil(node.namespaces.namespace)
|
28
|
+
|
29
|
+
# Now put the node in the soap namespace
|
30
|
+
node.namespaces.namespace = ns
|
31
|
+
assert_not_nil(node.namespaces.namespace)
|
32
|
+
assert_equal("<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"/>", node.to_s)
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_define_namespace
|
36
|
+
node = XML::Node.new('Envelope')
|
37
|
+
assert_equal('<Envelope/>', node.to_s)
|
38
|
+
|
39
|
+
XML::Namespace.new(node, 'soap', 'http://schemas.xmlsoap.org/soap/envelope/')
|
40
|
+
assert_equal("<Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"/>", node.to_s)
|
41
|
+
assert_nil(node.namespaces.namespace)
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_define_default_namespace
|
45
|
+
node = XML::Node.new('Envelope')
|
46
|
+
assert_equal('<Envelope/>', node.to_s)
|
47
|
+
|
48
|
+
XML::Namespace.new(node, nil, 'http://schemas.xmlsoap.org/soap/envelope/')
|
49
|
+
assert_equal("<Envelope xmlns=\"http://schemas.xmlsoap.org/soap/envelope/\"/>", node.to_s)
|
50
|
+
# This seems wrong, but appears to be the way libxml works
|
51
|
+
assert_nil(node.namespaces.namespace)
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_namespaces
|
55
|
+
node = @doc.find_first('//ns1:IdAndName',
|
56
|
+
:ns1 => 'http://domain.somewhere.com')
|
57
|
+
|
58
|
+
namespaces = node.namespaces.sort
|
59
|
+
assert_equal(5, namespaces.length)
|
60
|
+
|
61
|
+
namespace = namespaces[0]
|
62
|
+
assert_instance_of(XML::Namespace, namespace)
|
63
|
+
assert_equal(nil, namespace.prefix)
|
64
|
+
assert_equal('http://services.somewhere.com', namespace.href)
|
65
|
+
|
66
|
+
namespace = namespaces[1]
|
67
|
+
assert_instance_of(XML::Namespace, namespace)
|
68
|
+
assert_equal('ns1', namespace.prefix)
|
69
|
+
assert_equal('http://domain.somewhere.com', namespace.href)
|
70
|
+
|
71
|
+
namespace = namespaces[2]
|
72
|
+
assert_instance_of(XML::Namespace, namespace)
|
73
|
+
assert_equal('soap', namespace.prefix)
|
74
|
+
assert_equal('http://schemas.xmlsoap.org/soap/envelope/', namespace.href)
|
75
|
+
|
76
|
+
namespace = namespaces[3]
|
77
|
+
assert_instance_of(XML::Namespace, namespace)
|
78
|
+
assert_equal('xsd', namespace.prefix)
|
79
|
+
assert_equal('http://www.w3.org/2001/XMLSchema', namespace.href)
|
80
|
+
|
81
|
+
namespace = namespaces[4]
|
82
|
+
assert_instance_of(XML::Namespace, namespace)
|
83
|
+
assert_equal('xsi', namespace.prefix)
|
84
|
+
assert_equal('http://www.w3.org/2001/XMLSchema-instance', namespace.href)
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_namespaces
|
88
|
+
node = @doc.find_first('//ns1:IdAndName',
|
89
|
+
:ns1 => 'http://domain.somewhere.com')
|
90
|
+
|
91
|
+
namespaces = node.namespaces.each do |namespace|
|
92
|
+
assert_instance_of(XML::Namespace, namespace)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_namespace_definitions
|
97
|
+
ns_defs = @doc.root.namespaces.definitions
|
98
|
+
assert_equal(3, ns_defs.size)
|
99
|
+
|
100
|
+
namespace = ns_defs[0]
|
101
|
+
assert_instance_of(XML::Namespace, namespace)
|
102
|
+
assert_equal('soap', namespace.prefix)
|
103
|
+
assert_equal('http://schemas.xmlsoap.org/soap/envelope/', namespace.href)
|
104
|
+
|
105
|
+
namespace = ns_defs[1]
|
106
|
+
assert_instance_of(XML::Namespace, namespace)
|
107
|
+
assert_equal('xsd', namespace.prefix)
|
108
|
+
assert_equal('http://www.w3.org/2001/XMLSchema', namespace.href)
|
109
|
+
|
110
|
+
namespace = ns_defs[2]
|
111
|
+
assert_instance_of(XML::Namespace, namespace)
|
112
|
+
assert_equal('xsi', namespace.prefix)
|
113
|
+
assert_equal('http://www.w3.org/2001/XMLSchema-instance', namespace.href)
|
114
|
+
|
115
|
+
node = @doc.root.find_first('//ns:getManufacturerNamesResponse',
|
116
|
+
:ns => 'http://services.somewhere.com')
|
117
|
+
ns_defs = node.namespaces.definitions
|
118
|
+
assert_equal(1, ns_defs.size)
|
119
|
+
|
120
|
+
namespace = ns_defs[0]
|
121
|
+
assert_instance_of(XML::Namespace, namespace)
|
122
|
+
assert_equal(nil, namespace.prefix)
|
123
|
+
assert_equal('http://services.somewhere.com', namespace.href)
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_find_by_prefix
|
127
|
+
node = @doc.find_first('//ns1:getManufacturerNamesResponse',
|
128
|
+
:ns1 => 'http://services.somewhere.com')
|
129
|
+
|
130
|
+
namespace = @doc.root.namespaces.find_by_prefix('soap')
|
131
|
+
|
132
|
+
assert_instance_of(XML::Namespace, namespace)
|
133
|
+
assert_equal('soap', namespace.prefix)
|
134
|
+
assert_equal('http://schemas.xmlsoap.org/soap/envelope/', namespace.href)
|
135
|
+
end
|
136
|
+
|
137
|
+
def test_find_default_ns
|
138
|
+
namespace = @doc.root.namespaces.find_by_prefix(nil)
|
139
|
+
assert_nil(namespace)
|
140
|
+
|
141
|
+
node = @doc.find_first('//ns1:getManufacturerNamesResponse',
|
142
|
+
:ns1 => 'http://services.somewhere.com')
|
143
|
+
namespace = node.namespaces.find_by_prefix(nil)
|
144
|
+
|
145
|
+
assert_instance_of(XML::Namespace, namespace)
|
146
|
+
assert_equal(nil, namespace.prefix)
|
147
|
+
assert_equal('http://services.somewhere.com', namespace.href)
|
148
|
+
end
|
149
|
+
|
150
|
+
def test_find_ns_by_href
|
151
|
+
node = @doc.find_first('//ns1:getManufacturerNamesResponse',
|
152
|
+
:ns1 => 'http://services.somewhere.com')
|
153
|
+
|
154
|
+
namespace = node.namespaces.find_by_href('http://schemas.xmlsoap.org/soap/envelope/')
|
155
|
+
|
156
|
+
assert_instance_of(XML::Namespace, namespace)
|
157
|
+
assert_equal('soap', namespace.prefix)
|
158
|
+
assert_equal('http://schemas.xmlsoap.org/soap/envelope/', namespace.href)
|
159
|
+
end
|
160
|
+
|
161
|
+
def test_default_namespace
|
162
|
+
doc = XML::Document.string('<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"/>')
|
163
|
+
ns = doc.root.namespaces.default
|
164
|
+
assert_equal(ns.href, 'http://schemas.xmlsoap.org/soap/envelope/')
|
165
|
+
end
|
166
|
+
|
167
|
+
def test_default_prefix
|
168
|
+
doc = XML::Document.string('<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"/>')
|
169
|
+
doc.root.namespaces.default_prefix = 'soap'
|
170
|
+
|
171
|
+
node = doc.root.find_first('/soap:Envelope')
|
172
|
+
assert_not_nil(node)
|
173
|
+
end
|
174
|
+
end
|