nokogiri 1.5.0.beta.1 → 1.5.0.beta.2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of nokogiri might be problematic. Click here for more details.
- data/CHANGELOG.ja.rdoc +28 -8
- data/CHANGELOG.rdoc +23 -0
- data/Manifest.txt +63 -1
- data/README.ja.rdoc +1 -1
- data/README.rdoc +22 -4
- data/Rakefile +6 -2
- data/ext/java/nokogiri/EncodingHandler.java +92 -0
- data/ext/java/nokogiri/HtmlDocument.java +116 -0
- data/ext/java/nokogiri/HtmlElementDescription.java +111 -0
- data/ext/java/nokogiri/HtmlEntityLookup.java +45 -0
- data/ext/java/nokogiri/HtmlSaxParserContext.java +218 -0
- data/ext/java/nokogiri/NokogiriService.java +370 -0
- data/ext/java/nokogiri/XmlAttr.java +147 -0
- data/ext/java/nokogiri/XmlAttributeDecl.java +98 -0
- data/ext/java/nokogiri/XmlCdata.java +50 -0
- data/ext/java/nokogiri/XmlComment.java +47 -0
- data/ext/java/nokogiri/XmlDocument.java +463 -0
- data/ext/java/nokogiri/XmlDocumentFragment.java +207 -0
- data/ext/java/nokogiri/XmlDtd.java +427 -0
- data/ext/java/nokogiri/XmlElement.java +172 -0
- data/ext/java/nokogiri/XmlElementContent.java +350 -0
- data/ext/java/nokogiri/XmlElementDecl.java +115 -0
- data/ext/java/nokogiri/XmlEntityDecl.java +129 -0
- data/ext/java/nokogiri/XmlEntityReference.java +42 -0
- data/ext/java/nokogiri/XmlNamespace.java +77 -0
- data/ext/java/nokogiri/XmlNode.java +1399 -0
- data/ext/java/nokogiri/XmlNodeSet.java +248 -0
- data/ext/java/nokogiri/XmlProcessingInstruction.java +70 -0
- data/ext/java/nokogiri/XmlReader.java +373 -0
- data/ext/java/nokogiri/XmlRelaxng.java +166 -0
- data/ext/java/nokogiri/XmlSaxParserContext.java +308 -0
- data/ext/java/nokogiri/XmlSaxPushParser.java +146 -0
- data/ext/java/nokogiri/XmlSchema.java +142 -0
- data/ext/java/nokogiri/XmlSyntaxError.java +84 -0
- data/ext/java/nokogiri/XmlText.java +96 -0
- data/ext/java/nokogiri/XmlXpathContext.java +130 -0
- data/ext/java/nokogiri/XsltStylesheet.java +126 -0
- data/ext/java/nokogiri/internals/HtmlDomParserContext.java +181 -0
- data/ext/java/nokogiri/internals/NokogiriDocumentCache.java +39 -0
- data/ext/java/nokogiri/internals/NokogiriErrorHandler.java +42 -0
- data/ext/java/nokogiri/internals/NokogiriHandler.java +251 -0
- data/ext/java/nokogiri/internals/NokogiriHelpers.java +526 -0
- data/ext/java/nokogiri/internals/NokogiriNamespaceCache.java +136 -0
- data/ext/java/nokogiri/internals/NokogiriNamespaceContext.java +80 -0
- data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler.java +37 -0
- data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler4NekoHtml.java +54 -0
- data/ext/java/nokogiri/internals/NokogiriStrictErrorHandler.java +49 -0
- data/ext/java/nokogiri/internals/NokogiriXPathFunction.java +88 -0
- data/ext/java/nokogiri/internals/NokogiriXPathFunctionResolver.java +23 -0
- data/ext/java/nokogiri/internals/ParserContext.java +235 -0
- data/ext/java/nokogiri/internals/PushInputStream.java +381 -0
- data/ext/java/nokogiri/internals/ReaderNode.java +431 -0
- data/ext/java/nokogiri/internals/SaveContext.java +249 -0
- data/ext/java/nokogiri/internals/SchemaErrorHandler.java +35 -0
- data/ext/java/nokogiri/internals/XmlDeclHandler.java +10 -0
- data/ext/java/nokogiri/internals/XmlDomParser.java +45 -0
- data/ext/java/nokogiri/internals/XmlDomParserContext.java +201 -0
- data/ext/java/nokogiri/internals/XmlSaxParser.java +33 -0
- data/ext/nokogiri/depend +32 -0
- data/ext/nokogiri/extconf.rb +61 -32
- data/ext/nokogiri/nokogiri.c +0 -5
- data/ext/nokogiri/nokogiri.h +2 -2
- data/ext/nokogiri/xml_document.c +5 -0
- data/ext/nokogiri/xml_libxml2_hacks.c +112 -0
- data/ext/nokogiri/xml_libxml2_hacks.h +12 -0
- data/ext/nokogiri/xml_node.c +56 -16
- data/ext/nokogiri/xml_node_set.c +7 -7
- data/ext/nokogiri/xml_reader.c +20 -1
- data/ext/nokogiri/xml_relax_ng.c +0 -7
- data/ext/nokogiri/xml_xpath_context.c +2 -0
- data/lib/isorelax.jar +0 -0
- data/lib/jing.jar +0 -0
- data/lib/nekodtd.jar +0 -0
- data/lib/nekohtml.jar +0 -0
- data/lib/nokogiri.rb +1 -2
- data/lib/nokogiri/css/generated_parser.rb +155 -148
- data/lib/nokogiri/css/generated_tokenizer.rb +2 -1
- data/lib/nokogiri/css/parser.y +3 -0
- data/lib/nokogiri/css/xpath_visitor.rb +1 -7
- data/lib/nokogiri/html.rb +2 -2
- data/lib/nokogiri/html/document_fragment.rb +7 -4
- data/lib/nokogiri/nokogiri.jar +0 -0
- data/lib/nokogiri/version.rb +3 -6
- data/lib/nokogiri/xml/builder.rb +1 -1
- data/lib/nokogiri/xml/document.rb +1 -2
- data/lib/nokogiri/xml/document_fragment.rb +7 -0
- data/lib/nokogiri/xml/node.rb +5 -3
- data/lib/nokogiri/xml/node_set.rb +25 -0
- data/lib/nokogiri/xml/reader.rb +2 -0
- data/lib/nokogiri/xml/sax/document.rb +3 -1
- data/lib/xercesImpl.jar +0 -0
- data/spec/helper.rb +3 -0
- data/spec/xml/reader_spec.rb +307 -0
- data/tasks/test.rb +1 -1
- data/test/css/test_parser.rb +11 -1
- data/test/html/sax/test_parser_context.rb +2 -2
- data/test/html/test_document.rb +2 -2
- data/test/html/test_document_fragment.rb +34 -6
- data/test/test_memory_leak.rb +2 -2
- data/test/test_reader.rb +28 -6
- data/test/test_xslt_transforms.rb +2 -3
- data/test/xml/test_attr.rb +31 -4
- data/test/xml/test_builder.rb +5 -5
- data/test/xml/test_cdata.rb +3 -3
- data/test/xml/test_document.rb +8 -8
- data/test/xml/test_document_fragment.rb +4 -12
- data/test/xml/test_node.rb +1 -1
- data/test/xml/test_node_reparenting.rb +26 -11
- data/test/xml/test_node_set.rb +38 -2
- data/test/xml/test_text.rb +11 -2
- data/test/xml/test_unparented_node.rb +1 -1
- data/test/xml/test_xpath.rb +11 -7
- metadata +68 -5
- data/lib/nokogiri/version_warning.rb +0 -14
@@ -1,6 +1,6 @@
|
|
1
1
|
#--
|
2
2
|
# DO NOT MODIFY!!!!
|
3
|
-
# This file is automatically generated by rex 1.0.
|
3
|
+
# This file is automatically generated by rex 1.0.5.beta1
|
4
4
|
# from lexical definition file "lib/nokogiri/css/tokenizer.rex".
|
5
5
|
#++
|
6
6
|
|
@@ -29,6 +29,7 @@ class GeneratedTokenizer < GeneratedParser
|
|
29
29
|
scan_setup(str)
|
30
30
|
do_parse
|
31
31
|
end
|
32
|
+
alias :scan :scan_str
|
32
33
|
|
33
34
|
def load_file( filename )
|
34
35
|
@filename = filename
|
data/lib/nokogiri/css/parser.y
CHANGED
@@ -48,13 +48,6 @@ module Nokogiri
|
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
|
-
def visit_preceding_selector node
|
52
|
-
node.value.last.accept(self) +
|
53
|
-
'[preceding-sibling::' +
|
54
|
-
node.value.first.accept(self) +
|
55
|
-
']'
|
56
|
-
end
|
57
|
-
|
58
51
|
def visit_id node
|
59
52
|
node.value.first =~ /^#(.*)$/
|
60
53
|
"@id = '#{$1}'"
|
@@ -126,6 +119,7 @@ module Nokogiri
|
|
126
119
|
{
|
127
120
|
'combinator' => ' and ',
|
128
121
|
'direct_adjacent_selector' => "/following-sibling::*[1]/self::",
|
122
|
+
'preceding_selector' => "/following-sibling::",
|
129
123
|
'descendant_selector' => '//',
|
130
124
|
'child_selector' => '/',
|
131
125
|
}.each do |k,v|
|
data/lib/nokogiri/html.rb
CHANGED
@@ -2,11 +2,14 @@ module Nokogiri
|
|
2
2
|
module HTML
|
3
3
|
class DocumentFragment < Nokogiri::XML::DocumentFragment
|
4
4
|
####
|
5
|
-
# Create a Nokogiri::XML::DocumentFragment from +tags+
|
6
|
-
def self.parse tags
|
5
|
+
# Create a Nokogiri::XML::DocumentFragment from +tags+, using +encoding+
|
6
|
+
def self.parse tags, encoding = nil
|
7
7
|
doc = HTML::Document.new
|
8
|
-
|
9
|
-
|
8
|
+
|
9
|
+
encoding ||= tags.respond_to?(:encoding) ? tags.encoding.name : 'UTF-8'
|
10
|
+
doc.encoding = encoding
|
11
|
+
|
12
|
+
new(doc, tags)
|
10
13
|
end
|
11
14
|
|
12
15
|
def initialize document, tags = nil, ctx = nil
|
Binary file
|
data/lib/nokogiri/version.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Nokogiri
|
2
2
|
# The version of Nokogiri you are using
|
3
|
-
VERSION = '1.5.0.beta.
|
3
|
+
VERSION = '1.5.0.beta.2'
|
4
4
|
|
5
5
|
# More complete version information about libxml
|
6
6
|
VERSION_INFO = {}
|
@@ -9,7 +9,8 @@ module Nokogiri
|
|
9
9
|
VERSION_INFO['ruby'] = {}
|
10
10
|
VERSION_INFO['ruby']['version'] = ::RUBY_VERSION
|
11
11
|
VERSION_INFO['ruby']['platform'] = ::RUBY_PLATFORM
|
12
|
-
|
12
|
+
VERSION_INFO['ruby']['engine'] = defined?(RUBY_ENGINE) ? RUBY_ENGINE : 'mri'
|
13
|
+
|
13
14
|
VERSION_INFO['ruby']['jruby'] = ::JRUBY_VERSION if RUBY_PLATFORM == "java"
|
14
15
|
if defined?(LIBXML_VERSION)
|
15
16
|
VERSION_INFO['libxml'] = {}
|
@@ -31,8 +32,4 @@ module Nokogiri
|
|
31
32
|
def self.jruby?
|
32
33
|
!Nokogiri::VERSION_INFO['ruby']['jruby'].nil?
|
33
34
|
end
|
34
|
-
|
35
|
-
def self.is_2_6_16? # :nodoc:
|
36
|
-
Nokogiri::VERSION_INFO['ruby']['platform'] !~ /java/ && Nokogiri::VERSION_INFO['libxml']['loaded'] <= '2.6.16'
|
37
|
-
end
|
38
35
|
end
|
data/lib/nokogiri/xml/builder.rb
CHANGED
@@ -7,7 +7,7 @@ module Nokogiri
|
|
7
7
|
#
|
8
8
|
# For searching a Document, see Nokogiri::XML::Node#css and
|
9
9
|
# Nokogiri::XML::Node#xpath
|
10
|
-
class Document < Node
|
10
|
+
class Document < Nokogiri::XML::Node
|
11
11
|
##
|
12
12
|
# Parse an XML file. +thing+ may be a String, or any object that
|
13
13
|
# responds to _read_ and _close_ such as an IO, or StringIO.
|
@@ -172,7 +172,6 @@ module Nokogiri
|
|
172
172
|
undef_method :swap, :parent, :namespace, :default_namespace=
|
173
173
|
undef_method :add_namespace_definition, :attributes
|
174
174
|
undef_method :namespace_definitions, :line, :add_namespace
|
175
|
-
undef_method :parse, :in_context
|
176
175
|
|
177
176
|
def add_child child
|
178
177
|
raise "Document already has a root node" if root
|
data/lib/nokogiri/xml/node.rb
CHANGED
@@ -316,7 +316,7 @@ module Nokogiri
|
|
316
316
|
if node_or_tags.is_a?(XML::NodeSet)
|
317
317
|
node_or_tags.each { |n| add_child_node n }
|
318
318
|
else
|
319
|
-
|
319
|
+
add_child_node node_or_tags
|
320
320
|
end
|
321
321
|
self
|
322
322
|
end
|
@@ -376,8 +376,10 @@ module Nokogiri
|
|
376
376
|
|
377
377
|
####
|
378
378
|
# Returns a hash containing the node's attributes. The key is
|
379
|
-
# the attribute name, the value is a Nokogiri::XML::Attr
|
379
|
+
# the attribute name without any namespace, the value is a Nokogiri::XML::Attr
|
380
380
|
# representing the attribute.
|
381
|
+
# If you need to distinguish attributes with the same name, with different namespaces
|
382
|
+
# use #attribute_nodes instead.
|
381
383
|
def attributes
|
382
384
|
Hash[*(attribute_nodes.map { |node|
|
383
385
|
[node.node_name, node]
|
@@ -771,7 +773,7 @@ module Nokogiri
|
|
771
773
|
|
772
774
|
private
|
773
775
|
|
774
|
-
def coerce
|
776
|
+
def coerce data # :nodoc:
|
775
777
|
return data if data.is_a?(XML::NodeSet)
|
776
778
|
return data.children if data.is_a?(XML::DocumentFragment)
|
777
779
|
return fragment(data).children if data.is_a?(String)
|
@@ -138,6 +138,13 @@ module Nokogiri
|
|
138
138
|
sub_set
|
139
139
|
end
|
140
140
|
|
141
|
+
###
|
142
|
+
# Search this NodeSet's nodes' immediate children using CSS selector +selector+
|
143
|
+
def > selector
|
144
|
+
ns = document.root.namespaces
|
145
|
+
xpath CSS.xpath_for(selector, :prefix => "./", :ns => ns).first
|
146
|
+
end
|
147
|
+
|
141
148
|
###
|
142
149
|
# If path is a string, search this document for +path+ returning the
|
143
150
|
# first Node. Otherwise, index in to the array with +path+.
|
@@ -147,6 +154,24 @@ module Nokogiri
|
|
147
154
|
end
|
148
155
|
alias :% :at
|
149
156
|
|
157
|
+
##
|
158
|
+
# Search this NodeSet for the first occurrence of XPath +paths+.
|
159
|
+
# Equivalent to <tt>xpath(paths).first</tt>
|
160
|
+
# See NodeSet#xpath for more information.
|
161
|
+
#
|
162
|
+
def at_xpath *paths
|
163
|
+
xpath(*paths).first
|
164
|
+
end
|
165
|
+
|
166
|
+
##
|
167
|
+
# Search this NodeSet for the first occurrence of CSS +rules+.
|
168
|
+
# Equivalent to <tt>css(rules).first</tt>
|
169
|
+
# See NodeSet#css for more information.
|
170
|
+
#
|
171
|
+
def at_css *rules
|
172
|
+
css(*rules).first
|
173
|
+
end
|
174
|
+
|
150
175
|
###
|
151
176
|
# Filter this list for nodes that match +expr+
|
152
177
|
def filter expr
|
data/lib/nokogiri/xml/reader.rb
CHANGED
@@ -126,7 +126,9 @@ module Nokogiri
|
|
126
126
|
end
|
127
127
|
|
128
128
|
###
|
129
|
-
# Characters read between a tag
|
129
|
+
# Characters read between a tag. This method might be called multiple
|
130
|
+
# times given one contiguous string of characters.
|
131
|
+
#
|
130
132
|
# +string+ contains the character data
|
131
133
|
def characters string
|
132
134
|
end
|
data/lib/xercesImpl.jar
ADDED
Binary file
|
data/spec/helper.rb
ADDED
@@ -0,0 +1,307 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'helper')
|
2
|
+
|
3
|
+
include Nokogiri::XML
|
4
|
+
|
5
|
+
describe Nokogiri::XML::Reader do
|
6
|
+
|
7
|
+
it "should return the correct local_names" do
|
8
|
+
xml = <<-oexml
|
9
|
+
<x xmlns:tenderlove='http://tenderlovemaking.com/'>
|
10
|
+
<tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
|
11
|
+
</x>
|
12
|
+
oexml
|
13
|
+
r = Nokogiri::XML::Reader.from_memory(xml)
|
14
|
+
r.should_not be_nil
|
15
|
+
r.local_name.should be_nil
|
16
|
+
r.map{|x| x.local_name}.should == ["x","#text","foo","#text","foo","#text","x"]
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should return the correct names" do
|
20
|
+
reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
|
21
|
+
<x xmlns:edi='http://ecommerce.example.org/schema'>
|
22
|
+
<edi:foo>hello</edi:foo>
|
23
|
+
</x>
|
24
|
+
eoxml
|
25
|
+
reader.should_not be_nil
|
26
|
+
reader.name.should be_nil
|
27
|
+
reader.map{|x| x.name}.should == ["x", "#text", "edi:foo", "#text", "edi:foo", "#text", "x"]
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should set io as source when called from_io method" do
|
31
|
+
io = StringIO.new(<<-eoxml)
|
32
|
+
<x xmlns:tenderlove='http://tenderlovemaking.com/'>
|
33
|
+
<tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
|
34
|
+
</x>
|
35
|
+
eoxml
|
36
|
+
reader = Nokogiri::XML::Reader.from_io(io)
|
37
|
+
reader.source.should be_equal(io)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should raise ArgumentError if nil is passed" do
|
41
|
+
lambda{
|
42
|
+
Nokogiri::XML::Reader.from_memory(nil)
|
43
|
+
}.should raise_error(ArgumentError)
|
44
|
+
lambda{
|
45
|
+
Nokogiri::XML::Reader.from_io(nil)
|
46
|
+
}.should raise_error(ArgumentError)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should parse from_io" do
|
50
|
+
io = StringIO.new(<<-eoxml)
|
51
|
+
<x xmlns:tenderlove='http://tenderlovemaking.com/'>
|
52
|
+
<tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
|
53
|
+
</x>
|
54
|
+
eoxml
|
55
|
+
reader = Nokogiri::XML::Reader.from_io(io)
|
56
|
+
reader.should_not be_default
|
57
|
+
reader.map{ |x| x.default? }.should == [false, false, false, false, false, false, false]
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should parse when passed an io object" do
|
61
|
+
io = StringIO.new(<<-eoxml)
|
62
|
+
<x xmlns:tenderlove='http://tenderlovemaking.com/'>
|
63
|
+
<tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
|
64
|
+
</x>
|
65
|
+
eoxml
|
66
|
+
reader = Nokogiri::XML::Reader(io)
|
67
|
+
reader.should_not be_default
|
68
|
+
reader.map{ |x| x.default? }.should == [false, false, false, false, false, false, false]
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should set string as source when called from_memory" do
|
72
|
+
xml = <<-eoxml
|
73
|
+
<x xmlns:tenderlove='http://tenderlovemaking.com/'>
|
74
|
+
<tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
|
75
|
+
</x>
|
76
|
+
eoxml
|
77
|
+
reader = Nokogiri::XML::Reader(xml)
|
78
|
+
reader.source.should be_equal(xml)
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should return false for default" do # Sorry for the description. Couldn't avoid to.
|
82
|
+
reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
|
83
|
+
<x xmlns:tenderlove='http://tenderlovemaking.com/'>
|
84
|
+
<tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
|
85
|
+
</x>
|
86
|
+
eoxml
|
87
|
+
reader.should_not be_default
|
88
|
+
reader.map { |x| x.default? }.should == [false, false, false, false, false, false, false]
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should return the correct boolean value when asked for value?" do
|
92
|
+
reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
|
93
|
+
<x xmlns:tenderlove='http://tenderlovemaking.com/'>
|
94
|
+
<tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
|
95
|
+
</x>
|
96
|
+
eoxml
|
97
|
+
|
98
|
+
reader.value?.should == false # Look for how should I do this in RSpec.
|
99
|
+
reader.map {|x| x.value? }.should == [false, true, false, true, false, true, false]
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should be able to deal with errors" do
|
103
|
+
reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
|
104
|
+
<x xmlns:tenderlove='http://tenderlovemaking.com/'>
|
105
|
+
<tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
|
106
|
+
<foo>
|
107
|
+
</x>
|
108
|
+
eoxml
|
109
|
+
|
110
|
+
reader.errors.should have(0).items
|
111
|
+
|
112
|
+
lambda {
|
113
|
+
reader.each { |node| }
|
114
|
+
}.should raise_error(Nokogiri::XML::SyntaxError)
|
115
|
+
|
116
|
+
reader.errors.should have(1).item
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should retrieve the right arguments" do
|
120
|
+
reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
|
121
|
+
<x xmlns:tenderlove='http://tenderlovemaking.com/'
|
122
|
+
xmlns='http://mothership.connection.com/'
|
123
|
+
>
|
124
|
+
<tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
|
125
|
+
</x>
|
126
|
+
eoxml
|
127
|
+
reader.attributes.should be_empty
|
128
|
+
reader.map { |x| x.attributes }.should == [{'xmlns:tenderlove'=>'http://tenderlovemaking.com/',
|
129
|
+
'xmlns'=>'http://mothership.connection.com/'},
|
130
|
+
{}, {"awesome"=>"true"}, {}, {"awesome"=>"true"}, {},
|
131
|
+
{'xmlns:tenderlove'=>'http://tenderlovemaking.com/',
|
132
|
+
'xmlns'=>'http://mothership.connection.com/'}]
|
133
|
+
end
|
134
|
+
|
135
|
+
it "should be able to acces the same attribute through both attribute and attributes method" do
|
136
|
+
reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
|
137
|
+
<x xmlns:tenderlove='http://tenderlovemaking.com/'
|
138
|
+
xmlns='http://mothership.connection.com/'
|
139
|
+
>
|
140
|
+
<tenderlove:foo awesome='true' size='giant'>snuggles!</tenderlove:foo>
|
141
|
+
</x>
|
142
|
+
eoxml
|
143
|
+
|
144
|
+
reader.attribute(nil).should be_nil
|
145
|
+
|
146
|
+
reader.each do |node|
|
147
|
+
node.attributes.each do |key, value|
|
148
|
+
node.attribute(key).should == value
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
it "should be able to retrieve an attribute given an index" do
|
154
|
+
reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
|
155
|
+
<x xmlns:tenderlove='http://tenderlovemaking.com/'>
|
156
|
+
<tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
|
157
|
+
</x>
|
158
|
+
eoxml
|
159
|
+
|
160
|
+
reader.attribute_at(nil).should be_nil
|
161
|
+
reader.attribute_at(0).should be_nil
|
162
|
+
|
163
|
+
reader.map {|x| x.attribute_at(0) }.should == ['http://tenderlovemaking.com/', nil, 'true', nil, 'true', nil, 'http://tenderlovemaking.com/']
|
164
|
+
end
|
165
|
+
|
166
|
+
it "should be able to access an attribute value by its name" do # I should get this test for free
|
167
|
+
reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
|
168
|
+
<x xmlns:tenderlove='http://tenderlovemaking.com/'>
|
169
|
+
<tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
|
170
|
+
</x>
|
171
|
+
eoxml
|
172
|
+
|
173
|
+
reader.attribute(nil).should be_nil
|
174
|
+
reader.attribute('awesome').should be_nil
|
175
|
+
|
176
|
+
reader.map {|x| x.attribute('awesome') }.should ==[nil, nil, 'true', nil, 'true', nil, nil]
|
177
|
+
end
|
178
|
+
|
179
|
+
it "should retrieve the correct number of attributes" do
|
180
|
+
reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
|
181
|
+
<x xmlns:tenderlove='http://tenderlovemaking.com/'>
|
182
|
+
<tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
|
183
|
+
</x>
|
184
|
+
eoxml
|
185
|
+
|
186
|
+
reader.attribute_count.should == 0
|
187
|
+
reader.map {|x| x.attribute_count}.should == [1, 0, 1, 0, 0, 0, 0]
|
188
|
+
end
|
189
|
+
|
190
|
+
it "should return the depth of the current node" do
|
191
|
+
reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
|
192
|
+
<x xmlns:tenderlove='http://tenderlovemaking.com/'>
|
193
|
+
<tenderlove:foo>snuggles!</tenderlove:foo>
|
194
|
+
</x>
|
195
|
+
eoxml
|
196
|
+
|
197
|
+
reader.depth.should == 0
|
198
|
+
|
199
|
+
reader.map {|x| x.depth}.should == [0,1,1,2,1,1,0]
|
200
|
+
end
|
201
|
+
|
202
|
+
it "should return the right encoding" do
|
203
|
+
string = <<-eoxml
|
204
|
+
<awesome>
|
205
|
+
<p xml:lang="en">The quick brown fox jumps over the lazy dog.</p>
|
206
|
+
<p xml:lang="ja">日本語が上手です</p>
|
207
|
+
</awesome>
|
208
|
+
eoxml
|
209
|
+
reader = Nokogiri::XML::Reader.from_memory(string, nil, 'UTF-8')
|
210
|
+
reader.map { |x| x.encoding }.uniq.should == ['UTF-8']
|
211
|
+
end
|
212
|
+
|
213
|
+
it "should return the right xml version" do
|
214
|
+
reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
|
215
|
+
<x xmlns:tenderlove='http://tenderlovemaking.com/'>
|
216
|
+
<tenderlove:foo>snuggles!</tenderlove:foo>
|
217
|
+
</x>
|
218
|
+
eoxml
|
219
|
+
|
220
|
+
reader.xml_version.should be_nil
|
221
|
+
|
222
|
+
reader.map { |x| x.xml_version }.uniq.should == ['1.0']
|
223
|
+
end
|
224
|
+
|
225
|
+
it "should retrieve the correct lang" do
|
226
|
+
reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
|
227
|
+
<awesome>
|
228
|
+
<p xml:lang="en">The quick brown fox jumps over the lazy dog.</p>
|
229
|
+
<p xml:lang="ja">日本語が上手です</p>
|
230
|
+
</awesome>
|
231
|
+
eoxml
|
232
|
+
|
233
|
+
reader.lang.should be_nil
|
234
|
+
|
235
|
+
reader.map {|x| x.lang}.should == [nil, nil, "en", "en", "en", nil, "ja", "ja", "ja", nil, nil]
|
236
|
+
end
|
237
|
+
|
238
|
+
it "should retrieve the correct value" do
|
239
|
+
reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
|
240
|
+
<x xmlns:tenderlove='http://tenderlovemaking.com/'>
|
241
|
+
<tenderlove:foo>snuggles!</tenderlove:foo>
|
242
|
+
</x>
|
243
|
+
eoxml
|
244
|
+
|
245
|
+
reader.value.should be_nil
|
246
|
+
|
247
|
+
reader.map {|x| x.value }.should == [nil, "\n ", nil, "snuggles!", nil, "\n ", nil]
|
248
|
+
end
|
249
|
+
|
250
|
+
it "should return the node's prefix" do
|
251
|
+
reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
|
252
|
+
<x xmlns:edi='http://ecommerce.example.org/schema'>
|
253
|
+
<edi:foo>hello</edi:foo>
|
254
|
+
</x>
|
255
|
+
eoxml
|
256
|
+
|
257
|
+
reader.prefix.should be_nil
|
258
|
+
|
259
|
+
reader.map { |n| n.prefix }.should == [nil, nil, "edi", nil, "edi", nil, nil]
|
260
|
+
end
|
261
|
+
|
262
|
+
it "should return the reader state, whatever it is" do
|
263
|
+
reader = Nokogiri::XML::Reader.from_memory('<foo>bar</bar>')
|
264
|
+
reader.state.should_not be_nil
|
265
|
+
end
|
266
|
+
|
267
|
+
it "should return the namespace's uri" do
|
268
|
+
reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
|
269
|
+
<x xmlns:edi='http://ecommerce.example.org/schema'>
|
270
|
+
<edi:foo>hello</edi:foo>
|
271
|
+
</x>
|
272
|
+
eoxml
|
273
|
+
reader.namespace_uri.should be_nil
|
274
|
+
|
275
|
+
reader.map { |n| n.namespace_uri }.should == [nil,
|
276
|
+
nil,
|
277
|
+
"http://ecommerce.example.org/schema",
|
278
|
+
nil,
|
279
|
+
"http://ecommerce.example.org/schema",
|
280
|
+
nil,
|
281
|
+
nil]
|
282
|
+
end
|
283
|
+
|
284
|
+
it "should return the node's local_name" do
|
285
|
+
reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
|
286
|
+
<x xmlns:edi='http://ecommerce.example.org/schema'>
|
287
|
+
<edi:foo>hello</edi:foo>
|
288
|
+
</x>
|
289
|
+
eoxml
|
290
|
+
|
291
|
+
reader.local_name.should be_nil
|
292
|
+
|
293
|
+
reader.map {|n| n.local_name }.should == ["x", "#text", "foo", "#text", "foo", "#text", "x"]
|
294
|
+
end
|
295
|
+
|
296
|
+
it "should return node's name" do
|
297
|
+
reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
|
298
|
+
<x xmlns:edi='http://ecommerce.example.org/schema'>
|
299
|
+
<edi:foo>hello</edi:foo>
|
300
|
+
</x>
|
301
|
+
eoxml
|
302
|
+
|
303
|
+
reader.name.should be_nil
|
304
|
+
|
305
|
+
reader.map { |n| n.name }.should ==["x", "#text", "edi:foo", "#text", "edi:foo", "#text", "x"]
|
306
|
+
end
|
307
|
+
end
|