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
@@ -0,0 +1,41 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'hpricot'
|
5
|
+
require 'xml'
|
6
|
+
require 'rexml/document'
|
7
|
+
|
8
|
+
ITERATIONS = 3
|
9
|
+
NESTED_ITERATIONS = 5
|
10
|
+
|
11
|
+
def bm(name, filename, &block)
|
12
|
+
text = File.open(filename).read
|
13
|
+
length = text.length / 1024.0 / 1024.0
|
14
|
+
puts "#{filename}: #{name} (#{(length * 1024).round} kb)"
|
15
|
+
for j in 0 .. NESTED_ITERATIONS
|
16
|
+
s = Time.now.to_f
|
17
|
+
for i in 0 .. ITERATIONS
|
18
|
+
block.call(text)
|
19
|
+
end
|
20
|
+
timer = Time.now.to_f - s
|
21
|
+
puts "\t#{length * ITERATIONS / timer} MB/s"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def bm_suite(filenames)
|
26
|
+
filenames.each do |filename|
|
27
|
+
bm("LIBXML THROUGHPUT:", filename) do |text|
|
28
|
+
XML::Document.file(filename)
|
29
|
+
end
|
30
|
+
|
31
|
+
bm("HPRICOT THROUGHPUT:", filename) do |text|
|
32
|
+
Hpricot.XML(text)
|
33
|
+
end
|
34
|
+
|
35
|
+
bm("REXML THROUGHPUT:", filename) do |text|
|
36
|
+
REXML::Document.new(text)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
bm_suite("hamlet.xml")
|
data/script/test
ADDED
data/test/etc_doc_to_s.rb
CHANGED
@@ -1,19 +1,21 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
xml_doc
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require './test_helper'
|
4
|
+
|
5
|
+
1.times do |count|
|
6
|
+
|
7
|
+
xml_doc = XML::Document.new()
|
8
|
+
xml_doc.encoding = "UTF-8"
|
9
|
+
xml_doc.root = XML::Node.new("Request")
|
10
|
+
|
11
|
+
1000.times do |index|
|
12
|
+
xml_doc.root << node = XML::Node.new("row")
|
13
|
+
node["user_id"] = index.to_s
|
14
|
+
node << "600445"
|
15
|
+
end
|
16
|
+
|
17
|
+
xml_str = xml_doc.to_s
|
18
|
+
print "\r#{count}"
|
19
|
+
$stdout.flush
|
20
|
+
end
|
21
|
+
puts "\n"
|
data/test/ets_doc_file.rb
CHANGED
@@ -1,15 +1,17 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
(
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require './test_helper'
|
4
|
+
|
5
|
+
# This is related to bug 8337, complaint is on amd64/fbsd
|
6
|
+
# unknown if it happens on other amd64/os combos
|
7
|
+
|
8
|
+
Process.setrlimit(Process::RLIMIT_NOFILE,10005)
|
9
|
+
|
10
|
+
(1..10000).each{|time|
|
11
|
+
XML::Document.file(File.join(File.dirname(__FILE__),'ets_test.xml'))
|
12
|
+
if time % 100 == 0
|
13
|
+
print "\r#{time}"
|
14
|
+
$stdout.flush
|
15
|
+
end
|
16
|
+
}
|
17
|
+
puts "\n"
|
data/test/ets_doc_to_s.rb
CHANGED
@@ -1,21 +1,23 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
xml_doc
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require './test_helper'
|
4
|
+
|
5
|
+
100.times do |count|
|
6
|
+
|
7
|
+
xml_doc = XML::Document.new()
|
8
|
+
xml_doc.encoding = "UTF-8"
|
9
|
+
xml_doc.root = XML::Node.new("Request")
|
10
|
+
|
11
|
+
1000.times do |index|
|
12
|
+
|
13
|
+
xml_doc.root << node = XML::Node.new("row")
|
14
|
+
node["user_id"] = index.to_s
|
15
|
+
node << "600445"
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
xml_str = xml_doc.to_s
|
20
|
+
print "\r#{count}"
|
21
|
+
$stdout.flush
|
22
|
+
end
|
23
|
+
puts "\n"
|
data/test/ets_gpx.rb
CHANGED
@@ -1,26 +1,28 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
root
|
10
|
-
root['
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
trkpt
|
24
|
-
|
25
|
-
|
26
|
-
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'libxml'
|
4
|
+
|
5
|
+
100.times do
|
6
|
+
doc = XML::Document.new
|
7
|
+
doc.encoding = 'UTF-8'
|
8
|
+
|
9
|
+
root = XML::Node.new 'gpx'
|
10
|
+
root['version'] = '1.0'
|
11
|
+
root['creator'] = 'OpenStreetMap.org'
|
12
|
+
root['xmlns'] = "http://www.topografix.com/GPX/1/0/"
|
13
|
+
|
14
|
+
doc.root = root
|
15
|
+
|
16
|
+
track = XML::Node.new 'trk'
|
17
|
+
doc.root << track
|
18
|
+
|
19
|
+
trkseg = XML::Node.new 'trkseg'
|
20
|
+
track << trkseg
|
21
|
+
|
22
|
+
1.upto(1000) do |n|
|
23
|
+
trkpt = XML::Node.new 'trkpt'
|
24
|
+
trkpt['lat'] = n.to_s
|
25
|
+
trkpt['lon'] = n.to_s
|
26
|
+
trkseg << trkpt
|
27
|
+
end
|
28
|
+
end
|
data/test/ets_node_gc.rb
CHANGED
@@ -1,21 +1,23 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
end
|
20
|
-
garbage_collect
|
21
|
-
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require './test_helper'
|
4
|
+
|
5
|
+
# test of bug 13310, clears MEM2
|
6
|
+
|
7
|
+
include GC
|
8
|
+
|
9
|
+
inner = XML::Node.new('inner')
|
10
|
+
save = nil
|
11
|
+
1.times do
|
12
|
+
outer = XML::Node.new('outer')
|
13
|
+
outer.child = inner
|
14
|
+
1.times do
|
15
|
+
doc = XML::Document.new
|
16
|
+
doc.root = outer
|
17
|
+
# Uncomment the following line and it won't crash
|
18
|
+
save = doc
|
19
|
+
end
|
20
|
+
garbage_collect
|
21
|
+
end
|
22
|
+
garbage_collect
|
23
|
+
puts inner
|
data/test/ets_tsr.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require './test_helper'
|
4
|
+
|
5
|
+
10_000.times {|n|
|
6
|
+
j=XML::Node.new2(nil,"happy#{n}")
|
7
|
+
10.times {|r|
|
8
|
+
j1=XML::Node.new("happy#{r}","farts")
|
9
|
+
j.child=j1
|
10
|
+
}
|
11
|
+
}
|
@@ -0,0 +1,5 @@
|
|
1
|
+
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
|
+
<bands genre="metal">
|
3
|
+
<m�tley_cr�e country="us">M�tley Cr�e is an American heavy metal band formed in Los Angeles, California in 1981.</m�tley_cr�e>
|
4
|
+
<iron_maiden country="uk">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden>
|
5
|
+
</bands>
|
@@ -0,0 +1,5 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<bands genre="metal">
|
3
|
+
<mötley_crüe country="us">Mötley Crüe is an American heavy metal band formed in Los Angeles, California in 1981.</mötley_crüe>
|
4
|
+
<iron_maiden country="uk">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden>
|
5
|
+
</bands>
|
@@ -0,0 +1,33 @@
|
|
1
|
+
#!/usr/local/ruby/bin/ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
|
4
|
+
ARGV.reject! { |path| !File.file?(path) }
|
5
|
+
(puts DATA.read.gsub("$0", File.basename($0)); exit 1) if ARGV.empty?
|
6
|
+
|
7
|
+
ARGV.each do |path|
|
8
|
+
ls = IO.readlines(path)
|
9
|
+
ix = ls[0] !~ /^#!/ ? 0 : 1
|
10
|
+
next if ls[ix] =~ /#.*?coding\s*[:=]\s*\S/
|
11
|
+
ls.insert ix, "# encoding: UTF-8\n", ("\n" unless ls[ix] =~ /^#?\s*\n/)
|
12
|
+
open(path, 'w') { |f| f.write ls.join }
|
13
|
+
end
|
14
|
+
|
15
|
+
__END__
|
16
|
+
Add the unicode magic comment to ruby files.
|
17
|
+
|
18
|
+
* Files are modified in-place.
|
19
|
+
* If a file already contains a magic comment, it's skipped.
|
20
|
+
* Comment is added below the shebang if it exists, otherwise as the first line.
|
21
|
+
|
22
|
+
Usage:
|
23
|
+
$0 file-1 [file-2 ... file-n]
|
24
|
+
|
25
|
+
Examples:
|
26
|
+
# Add comment to standalone ruby files:
|
27
|
+
$0 foo.rb bar.rb
|
28
|
+
|
29
|
+
# Add comment to an entire ruby library or app:
|
30
|
+
find . -name '*.rb' -type f -print0 | xargs -0 $0
|
31
|
+
|
32
|
+
# Add comment to app files in a rails application:
|
33
|
+
find app config lib -name '*.rb' -type f -print0 | xargs -0 $0
|
data/test/tc_attr.rb
CHANGED
@@ -1,170 +1,181 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
xmlns
|
11
|
-
xmlns:
|
12
|
-
xmlns:
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
xlink:
|
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
|
-
attribute
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
assert_equal(
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
attribute
|
60
|
-
assert_equal('http://www.
|
61
|
-
end
|
62
|
-
|
63
|
-
def
|
64
|
-
attribute = city_member.attributes.get_attribute('name')
|
65
|
-
attribute.value
|
66
|
-
assert_equal(
|
67
|
-
|
68
|
-
attribute = city_member.attributes.get_attribute('href')
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
attribute =
|
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
|
-
attributes
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
assert_equal(5,
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
assert_equal(
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
assert_equal(
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
assert_equal(
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
attribute =
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
assert_equal('
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
assert_equal('
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
assert_equal(
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
assert_equal(
|
169
|
-
|
170
|
-
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require './test_helper'
|
4
|
+
require 'test/unit'
|
5
|
+
|
6
|
+
class AttrNodeTest < Test::Unit::TestCase
|
7
|
+
def setup
|
8
|
+
xp = XML::Parser.string(<<-EOS)
|
9
|
+
<CityModel
|
10
|
+
xmlns="http://www.opengis.net/examples"
|
11
|
+
xmlns:city="http://www.opengis.net/examples"
|
12
|
+
xmlns:gml="http://www.opengis.net/gml"
|
13
|
+
xmlns:xlink="http://www.w3.org/1999/xlink"
|
14
|
+
xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
|
15
|
+
xsi:schemaLocation="http://www.opengis.net/examples city.xsd">
|
16
|
+
<type>City</type>
|
17
|
+
<cityMember name="Cambridge"
|
18
|
+
xlink:type="simple"
|
19
|
+
xlink:title="Trinity Lane"
|
20
|
+
xlink:href="http://www.foo.net/cgi-bin/wfs?FeatureID=C10239"
|
21
|
+
gml:remoteSchema="city.xsd#xpointer(//complexType[@name='RoadType'])"/>
|
22
|
+
</CityModel>
|
23
|
+
EOS
|
24
|
+
|
25
|
+
@doc = xp.parse
|
26
|
+
end
|
27
|
+
|
28
|
+
def teardown
|
29
|
+
@doc = nil
|
30
|
+
end
|
31
|
+
|
32
|
+
def city_member
|
33
|
+
@doc.find('/city:CityModel/city:cityMember').first
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_doc
|
37
|
+
assert_not_nil(@doc)
|
38
|
+
assert_equal(XML::Encoding::NONE, @doc.encoding)
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_types
|
42
|
+
attribute = city_member.attributes.get_attribute('name')
|
43
|
+
assert_instance_of(XML::Attr, attribute)
|
44
|
+
assert_equal('attribute', attribute.node_type_name)
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_name
|
48
|
+
attribute = city_member.attributes.get_attribute('name')
|
49
|
+
assert_equal('name', attribute.name)
|
50
|
+
assert_equal(Encoding::ASCII_8BIT, attribute.name.encoding) if defined?(Encoding)
|
51
|
+
|
52
|
+
attribute = city_member.attributes.get_attribute('href')
|
53
|
+
assert_equal('href', attribute.name)
|
54
|
+
assert_equal('xlink', attribute.ns.prefix)
|
55
|
+
assert_equal('http://www.w3.org/1999/xlink', attribute.ns.href)
|
56
|
+
|
57
|
+
attribute = city_member.attributes.get_attribute_ns('http://www.w3.org/1999/xlink', 'href')
|
58
|
+
assert_equal('href', attribute.name)
|
59
|
+
assert_equal('xlink', attribute.ns.prefix)
|
60
|
+
assert_equal('http://www.w3.org/1999/xlink', attribute.ns.href)
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_value
|
64
|
+
attribute = city_member.attributes.get_attribute('name')
|
65
|
+
assert_equal('Cambridge', attribute.value)
|
66
|
+
assert_equal(Encoding::ASCII_8BIT, attribute.value.encoding) if defined?(Encoding)
|
67
|
+
|
68
|
+
attribute = city_member.attributes.get_attribute('href')
|
69
|
+
assert_equal('http://www.foo.net/cgi-bin/wfs?FeatureID=C10239', attribute.value)
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_set_value
|
73
|
+
attribute = city_member.attributes.get_attribute('name')
|
74
|
+
attribute.value = 'London'
|
75
|
+
assert_equal('London', attribute.value)
|
76
|
+
assert_equal(Encoding::ASCII_8BIT, attribute.value.encoding) if defined?(Encoding)
|
77
|
+
|
78
|
+
attribute = city_member.attributes.get_attribute('href')
|
79
|
+
attribute.value = 'http://i.have.changed'
|
80
|
+
assert_equal('http://i.have.changed', attribute.value)
|
81
|
+
assert_equal(Encoding::ASCII_8BIT, attribute.value.encoding) if defined?(Encoding)
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_set_nil
|
85
|
+
attribute = city_member.attributes.get_attribute('name')
|
86
|
+
assert_raise(TypeError) do
|
87
|
+
attribute.value = nil
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_create
|
92
|
+
attributes = city_member.attributes
|
93
|
+
assert_equal(5, attributes.length)
|
94
|
+
|
95
|
+
attr = XML::Attr.new(city_member, 'size', '50,000')
|
96
|
+
assert_instance_of(XML::Attr, attr)
|
97
|
+
|
98
|
+
attributes = city_member.attributes
|
99
|
+
assert_equal(6, attributes.length)
|
100
|
+
|
101
|
+
assert_equal(attributes['size'], '50,000')
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_create_on_node
|
105
|
+
attributes = city_member.attributes
|
106
|
+
assert_equal(5, attributes.length)
|
107
|
+
|
108
|
+
attributes['country'] = 'England'
|
109
|
+
|
110
|
+
attributes = city_member.attributes
|
111
|
+
assert_equal(6, attributes.length)
|
112
|
+
|
113
|
+
assert_equal(attributes['country'], 'England')
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_create_ns
|
117
|
+
assert_equal(5, city_member.attributes.length)
|
118
|
+
|
119
|
+
ns = XML::Namespace.new(city_member, 'my_namepace', 'http://www.mynamespace.com')
|
120
|
+
attr = XML::Attr.new(city_member, 'rating', 'rocks', ns)
|
121
|
+
assert_instance_of(XML::Attr, attr)
|
122
|
+
assert_equal('rating', attr.name)
|
123
|
+
assert_equal('rocks', attr.value)
|
124
|
+
|
125
|
+
attributes = city_member.attributes
|
126
|
+
assert_equal(6, attributes.length)
|
127
|
+
|
128
|
+
assert_equal('rocks', city_member['rating'])
|
129
|
+
end
|
130
|
+
|
131
|
+
def test_remove
|
132
|
+
attributes = city_member.attributes
|
133
|
+
assert_equal(5, attributes.length)
|
134
|
+
|
135
|
+
attribute = attributes.get_attribute('name')
|
136
|
+
assert_not_nil(attribute.parent)
|
137
|
+
assert(attribute.parent?)
|
138
|
+
|
139
|
+
attribute.remove!
|
140
|
+
assert_equal(4, attributes.length)
|
141
|
+
assert_nil(attribute.parent)
|
142
|
+
assert(!attribute.parent?)
|
143
|
+
end
|
144
|
+
|
145
|
+
def test_first
|
146
|
+
attribute = city_member.attributes.first
|
147
|
+
assert_instance_of(XML::Attr, attribute)
|
148
|
+
assert_equal('name', attribute.name)
|
149
|
+
assert_equal('Cambridge', attribute.value)
|
150
|
+
|
151
|
+
attribute = attribute.next
|
152
|
+
assert_instance_of(XML::Attr, attribute)
|
153
|
+
assert_equal('type', attribute.name)
|
154
|
+
assert_equal('simple', attribute.value)
|
155
|
+
|
156
|
+
attribute = attribute.next
|
157
|
+
assert_instance_of(XML::Attr, attribute)
|
158
|
+
assert_equal('title', attribute.name)
|
159
|
+
assert_equal('Trinity Lane', attribute.value)
|
160
|
+
|
161
|
+
attribute = attribute.next
|
162
|
+
assert_instance_of(XML::Attr, attribute)
|
163
|
+
assert_equal('href', attribute.name)
|
164
|
+
assert_equal('http://www.foo.net/cgi-bin/wfs?FeatureID=C10239', attribute.value)
|
165
|
+
|
166
|
+
attribute = attribute.next
|
167
|
+
assert_instance_of(XML::Attr, attribute)
|
168
|
+
assert_equal('remoteSchema', attribute.name)
|
169
|
+
assert_equal("city.xsd#xpointer(//complexType[@name='RoadType'])", attribute.value)
|
170
|
+
|
171
|
+
attribute = attribute.next
|
172
|
+
assert_nil(attribute)
|
173
|
+
end
|
174
|
+
|
175
|
+
def test_no_attributes
|
176
|
+
element = @doc.find('/city:CityModel/city:type').first
|
177
|
+
|
178
|
+
assert_not_nil(element.attributes)
|
179
|
+
assert_equal(0, element.attributes.length)
|
180
|
+
end
|
181
|
+
end
|