nokogiri 1.12.5-arm64-darwin → 1.13.0-arm64-darwin
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.
- checksums.yaml +4 -4
- data/Gemfile +2 -0
- data/README.md +9 -7
- data/bin/nokogiri +63 -50
- data/dependencies.yml +5 -6
- data/ext/nokogiri/extconf.rb +47 -35
- data/ext/nokogiri/include/libxml2/libxml/xmlerror.h +1 -0
- data/ext/nokogiri/include/libxslt/xsltconfig.h +1 -1
- data/ext/nokogiri/xml_document.c +35 -35
- data/ext/nokogiri/xml_document_fragment.c +0 -2
- data/ext/nokogiri/xml_dtd.c +2 -2
- data/ext/nokogiri/xml_encoding_handler.c +25 -11
- data/ext/nokogiri/xml_node.c +638 -333
- data/ext/nokogiri/xml_reader.c +37 -11
- data/ext/nokogiri/xml_xpath_context.c +72 -49
- data/lib/nokogiri/2.6/nokogiri.bundle +0 -0
- data/lib/nokogiri/2.7/nokogiri.bundle +0 -0
- data/lib/nokogiri/3.0/nokogiri.bundle +0 -0
- data/lib/nokogiri/{2.5 → 3.1}/nokogiri.bundle +0 -0
- data/lib/nokogiri/class_resolver.rb +67 -0
- data/lib/nokogiri/css/node.rb +9 -8
- data/lib/nokogiri/css/parser.rb +11 -3
- data/lib/nokogiri/css/parser.y +10 -2
- data/lib/nokogiri/css/parser_extras.rb +20 -20
- data/lib/nokogiri/css/syntax_error.rb +1 -0
- data/lib/nokogiri/css/tokenizer.rb +2 -1
- data/lib/nokogiri/css/tokenizer.rex +2 -1
- data/lib/nokogiri/css/xpath_visitor.rb +174 -75
- data/lib/nokogiri/css.rb +38 -6
- data/lib/nokogiri/decorators/slop.rb +8 -7
- data/lib/nokogiri/extension.rb +1 -1
- data/lib/nokogiri/gumbo.rb +1 -0
- data/lib/nokogiri/html.rb +16 -10
- data/lib/nokogiri/html4/builder.rb +1 -0
- data/lib/nokogiri/html4/document.rb +84 -75
- data/lib/nokogiri/html4/document_fragment.rb +11 -7
- data/lib/nokogiri/html4/element_description.rb +1 -0
- data/lib/nokogiri/html4/element_description_defaults.rb +426 -520
- data/lib/nokogiri/html4/entity_lookup.rb +2 -1
- data/lib/nokogiri/html4/sax/parser.rb +2 -1
- data/lib/nokogiri/html4/sax/parser_context.rb +1 -0
- data/lib/nokogiri/html4/sax/push_parser.rb +7 -7
- data/lib/nokogiri/html4.rb +11 -5
- data/lib/nokogiri/html5/document.rb +24 -10
- data/lib/nokogiri/html5/document_fragment.rb +5 -2
- data/lib/nokogiri/html5/node.rb +6 -3
- data/lib/nokogiri/html5.rb +68 -64
- data/lib/nokogiri/jruby/dependencies.rb +10 -9
- data/lib/nokogiri/syntax_error.rb +1 -0
- data/lib/nokogiri/version/constant.rb +2 -1
- data/lib/nokogiri/version/info.rb +19 -13
- data/lib/nokogiri/version.rb +1 -0
- data/lib/nokogiri/xml/attr.rb +5 -3
- data/lib/nokogiri/xml/attribute_decl.rb +2 -1
- data/lib/nokogiri/xml/builder.rb +32 -32
- data/lib/nokogiri/xml/cdata.rb +2 -1
- data/lib/nokogiri/xml/character_data.rb +1 -0
- data/lib/nokogiri/xml/document.rb +139 -103
- data/lib/nokogiri/xml/document_fragment.rb +41 -38
- data/lib/nokogiri/xml/dtd.rb +3 -2
- data/lib/nokogiri/xml/element_content.rb +1 -0
- data/lib/nokogiri/xml/element_decl.rb +2 -1
- data/lib/nokogiri/xml/entity_decl.rb +3 -2
- data/lib/nokogiri/xml/entity_reference.rb +1 -0
- data/lib/nokogiri/xml/namespace.rb +2 -0
- data/lib/nokogiri/xml/node/save_options.rb +6 -3
- data/lib/nokogiri/xml/node.rb +512 -348
- data/lib/nokogiri/xml/node_set.rb +46 -54
- data/lib/nokogiri/xml/notation.rb +12 -0
- data/lib/nokogiri/xml/parse_options.rb +11 -7
- data/lib/nokogiri/xml/pp/character_data.rb +8 -6
- data/lib/nokogiri/xml/pp/node.rb +24 -26
- data/lib/nokogiri/xml/pp.rb +1 -0
- data/lib/nokogiri/xml/processing_instruction.rb +2 -1
- data/lib/nokogiri/xml/reader.rb +17 -19
- data/lib/nokogiri/xml/relax_ng.rb +1 -0
- data/lib/nokogiri/xml/sax/document.rb +20 -19
- data/lib/nokogiri/xml/sax/parser.rb +36 -34
- data/lib/nokogiri/xml/sax/parser_context.rb +7 -3
- data/lib/nokogiri/xml/sax/push_parser.rb +5 -5
- data/lib/nokogiri/xml/sax.rb +1 -0
- data/lib/nokogiri/xml/schema.rb +7 -6
- data/lib/nokogiri/xml/searchable.rb +42 -22
- data/lib/nokogiri/xml/syntax_error.rb +4 -4
- data/lib/nokogiri/xml/text.rb +1 -0
- data/lib/nokogiri/xml/xpath/syntax_error.rb +2 -1
- data/lib/nokogiri/xml/xpath.rb +12 -0
- data/lib/nokogiri/xml/xpath_context.rb +2 -3
- data/lib/nokogiri/xml.rb +3 -3
- data/lib/nokogiri/xslt/stylesheet.rb +1 -0
- data/lib/nokogiri/xslt.rb +3 -2
- data/lib/nokogiri.rb +19 -16
- data/lib/xsd/xmlparser/nokogiri.rb +25 -24
- metadata +124 -52
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module Nokogiri
|
3
4
|
module XML
|
4
5
|
####
|
@@ -12,10 +13,10 @@ module Nokogiri
|
|
12
13
|
# The Document this NodeSet is associated with
|
13
14
|
attr_accessor :document
|
14
15
|
|
15
|
-
|
16
|
+
alias_method :clone, :dup
|
16
17
|
|
17
18
|
# Create a NodeSet with +document+ defaulting to +list+
|
18
|
-
def initialize
|
19
|
+
def initialize(document, list = [])
|
19
20
|
@document = document
|
20
21
|
document.decorate(self)
|
21
22
|
list.each { |x| self << x }
|
@@ -24,7 +25,7 @@ module Nokogiri
|
|
24
25
|
|
25
26
|
###
|
26
27
|
# Get the first element of the NodeSet.
|
27
|
-
def first
|
28
|
+
def first(n = nil)
|
28
29
|
return self[0] unless n
|
29
30
|
list = []
|
30
31
|
[n, length].min.times { |i| list << self[i] }
|
@@ -47,7 +48,7 @@ module Nokogiri
|
|
47
48
|
# Returns the index of the first node in self that is == to +node+ or meets the given block. Returns nil if no match is found.
|
48
49
|
def index(node = nil)
|
49
50
|
if node
|
50
|
-
warn
|
51
|
+
warn("given block not used") if block_given?
|
51
52
|
each_with_index { |member, j| return j if member == node }
|
52
53
|
elsif block_given?
|
53
54
|
each_with_index { |member, j| return j if yield(member) }
|
@@ -57,18 +58,18 @@ module Nokogiri
|
|
57
58
|
|
58
59
|
###
|
59
60
|
# Insert +datum+ before the first Node in this NodeSet
|
60
|
-
def before
|
61
|
-
first.before
|
61
|
+
def before(datum)
|
62
|
+
first.before(datum)
|
62
63
|
end
|
63
64
|
|
64
65
|
###
|
65
66
|
# Insert +datum+ after the last Node in this NodeSet
|
66
|
-
def after
|
67
|
-
last.after
|
67
|
+
def after(datum)
|
68
|
+
last.after(datum)
|
68
69
|
end
|
69
70
|
|
70
|
-
|
71
|
-
|
71
|
+
alias_method :<<, :push
|
72
|
+
alias_method :remove, :unlink
|
72
73
|
|
73
74
|
###
|
74
75
|
# call-seq: css *rules, [namespace-bindings, custom-pseudo-class]
|
@@ -77,7 +78,7 @@ module Nokogiri
|
|
77
78
|
# selectors. For example:
|
78
79
|
#
|
79
80
|
# For more information see Nokogiri::XML::Searchable#css
|
80
|
-
def css
|
81
|
+
def css(*args)
|
81
82
|
rules, handler, ns, _ = extract_params(args)
|
82
83
|
paths = css_rules_to_xpath(rules, ns)
|
83
84
|
|
@@ -93,7 +94,7 @@ module Nokogiri
|
|
93
94
|
# queries.
|
94
95
|
#
|
95
96
|
# For more information see Nokogiri::XML::Searchable#xpath
|
96
|
-
def xpath
|
97
|
+
def xpath(*args)
|
97
98
|
paths, handler, ns, binds = extract_params(args)
|
98
99
|
|
99
100
|
inject(NodeSet.new(document)) do |set, node|
|
@@ -101,13 +102,6 @@ module Nokogiri
|
|
101
102
|
end
|
102
103
|
end
|
103
104
|
|
104
|
-
###
|
105
|
-
# Search this NodeSet's nodes' immediate children using CSS selector +selector+
|
106
|
-
def > selector
|
107
|
-
ns = document.root.namespaces
|
108
|
-
xpath CSS.xpath_for(selector, :prefix => "./", :ns => ns).first
|
109
|
-
end
|
110
|
-
|
111
105
|
###
|
112
106
|
# call-seq: search *paths, [namespace-bindings, xpath-variable-bindings, custom-handler-class]
|
113
107
|
#
|
@@ -120,18 +114,18 @@ module Nokogiri
|
|
120
114
|
#
|
121
115
|
# node_set.at(3) # same as node_set[3]
|
122
116
|
#
|
123
|
-
def at
|
117
|
+
def at(*args)
|
124
118
|
if args.length == 1 && args.first.is_a?(Numeric)
|
125
119
|
return self[args.first]
|
126
120
|
end
|
127
121
|
|
128
122
|
super(*args)
|
129
123
|
end
|
130
|
-
|
124
|
+
alias_method :%, :at
|
131
125
|
|
132
126
|
###
|
133
127
|
# Filter this list for nodes that match +expr+
|
134
|
-
def filter
|
128
|
+
def filter(expr)
|
135
129
|
find_all { |node| node.matches?(expr) }
|
136
130
|
end
|
137
131
|
|
@@ -140,7 +134,7 @@ module Nokogiri
|
|
140
134
|
# NodeSet.
|
141
135
|
#
|
142
136
|
# See Nokogiri::XML::Node#add_class for more information.
|
143
|
-
def add_class
|
137
|
+
def add_class(name)
|
144
138
|
each do |el|
|
145
139
|
el.add_class(name)
|
146
140
|
end
|
@@ -152,7 +146,7 @@ module Nokogiri
|
|
152
146
|
# NodeSet.
|
153
147
|
#
|
154
148
|
# See Nokogiri::XML::Node#append_class for more information.
|
155
|
-
def append_class
|
149
|
+
def append_class(name)
|
156
150
|
each do |el|
|
157
151
|
el.append_class(name)
|
158
152
|
end
|
@@ -164,7 +158,7 @@ module Nokogiri
|
|
164
158
|
# NodeSet.
|
165
159
|
#
|
166
160
|
# See Nokogiri::XML::Node#remove_class for more information.
|
167
|
-
def remove_class
|
161
|
+
def remove_class(name = nil)
|
168
162
|
each do |el|
|
169
163
|
el.remove_class(name)
|
170
164
|
end
|
@@ -204,31 +198,31 @@ module Nokogiri
|
|
204
198
|
#
|
205
199
|
# node_set.attr("class") { |node| node.name }
|
206
200
|
#
|
207
|
-
def attr
|
201
|
+
def attr(key, value = nil, &block)
|
208
202
|
unless key.is_a?(Hash) || (key && (value || block))
|
209
203
|
return first ? first.attribute(key) : nil
|
210
204
|
end
|
211
205
|
|
212
206
|
hash = key.is_a?(Hash) ? key : { key => value }
|
213
207
|
|
214
|
-
hash.each do |k,v|
|
208
|
+
hash.each do |k, v|
|
215
209
|
each do |node|
|
216
|
-
node[k] = v ||
|
210
|
+
node[k] = v || yield(node)
|
217
211
|
end
|
218
212
|
end
|
219
213
|
|
220
214
|
self
|
221
215
|
end
|
222
|
-
|
223
|
-
|
216
|
+
alias_method :set, :attr
|
217
|
+
alias_method :attribute, :attr
|
224
218
|
|
225
219
|
###
|
226
220
|
# Remove the attributed named +name+ from all Node objects in the NodeSet
|
227
|
-
def remove_attr
|
228
|
-
each { |el| el.delete
|
221
|
+
def remove_attr(name)
|
222
|
+
each { |el| el.delete(name) }
|
229
223
|
self
|
230
224
|
end
|
231
|
-
|
225
|
+
alias_method :remove_attribute, :remove_attr
|
232
226
|
|
233
227
|
###
|
234
228
|
# Iterate over each node, yielding to +block+
|
@@ -255,20 +249,20 @@ module Nokogiri
|
|
255
249
|
#
|
256
250
|
# See Nokogiri::XML::Node#content for more information.
|
257
251
|
def inner_text
|
258
|
-
collect(&:inner_text).join(
|
252
|
+
collect(&:inner_text).join("")
|
259
253
|
end
|
260
|
-
|
254
|
+
alias_method :text, :inner_text
|
261
255
|
|
262
256
|
###
|
263
257
|
# Get the inner html of all contained Node objects
|
264
|
-
def inner_html
|
265
|
-
collect{|j| j.inner_html(*args) }.join(
|
258
|
+
def inner_html(*args)
|
259
|
+
collect { |j| j.inner_html(*args) }.join("")
|
266
260
|
end
|
267
261
|
|
268
262
|
###
|
269
263
|
# Wrap this NodeSet with +html+
|
270
|
-
def wrap
|
271
|
-
map { |node| node.wrap
|
264
|
+
def wrap(html)
|
265
|
+
map { |node| node.wrap(html) }
|
272
266
|
end
|
273
267
|
|
274
268
|
###
|
@@ -279,10 +273,10 @@ module Nokogiri
|
|
279
273
|
|
280
274
|
###
|
281
275
|
# Convert this NodeSet to HTML
|
282
|
-
def to_html
|
276
|
+
def to_html(*args)
|
283
277
|
if Nokogiri.jruby?
|
284
278
|
options = args.first.is_a?(Hash) ? args.shift : {}
|
285
|
-
|
279
|
+
unless options[:save_with]
|
286
280
|
options[:save_with] = Node::SaveOptions::NO_DECLARATION | Node::SaveOptions::NO_EMPTY_TAGS | Node::SaveOptions::AS_HTML
|
287
281
|
end
|
288
282
|
args.insert(0, options)
|
@@ -292,25 +286,25 @@ module Nokogiri
|
|
292
286
|
|
293
287
|
###
|
294
288
|
# Convert this NodeSet to XHTML
|
295
|
-
def to_xhtml
|
289
|
+
def to_xhtml(*args)
|
296
290
|
map { |x| x.to_xhtml(*args) }.join
|
297
291
|
end
|
298
292
|
|
299
293
|
###
|
300
294
|
# Convert this NodeSet to XML
|
301
|
-
def to_xml
|
295
|
+
def to_xml(*args)
|
302
296
|
map { |x| x.to_xml(*args) }.join
|
303
297
|
end
|
304
298
|
|
305
|
-
|
306
|
-
|
299
|
+
alias_method :size, :length
|
300
|
+
alias_method :to_ary, :to_a
|
307
301
|
|
308
302
|
###
|
309
303
|
# Removes the last element from set and returns it, or +nil+ if
|
310
304
|
# the set is empty
|
311
305
|
def pop
|
312
306
|
return nil if length == 0
|
313
|
-
delete
|
307
|
+
delete(last)
|
314
308
|
end
|
315
309
|
|
316
310
|
###
|
@@ -318,14 +312,14 @@ module Nokogiri
|
|
318
312
|
# +nil+ if the set is empty.
|
319
313
|
def shift
|
320
314
|
return nil if length == 0
|
321
|
-
delete
|
315
|
+
delete(first)
|
322
316
|
end
|
323
317
|
|
324
318
|
###
|
325
319
|
# Equality -- Two NodeSets are equal if the contain the same number
|
326
320
|
# of elements and if each element is equal to the corresponding
|
327
321
|
# element in the other NodeSet
|
328
|
-
def ==
|
322
|
+
def ==(other)
|
329
323
|
return false unless other.is_a?(Nokogiri::XML::NodeSet)
|
330
324
|
return false unless length == other.length
|
331
325
|
each_with_index do |node, i|
|
@@ -351,7 +345,7 @@ module Nokogiri
|
|
351
345
|
def reverse
|
352
346
|
node_set = NodeSet.new(document)
|
353
347
|
(length - 1).downto(0) do |x|
|
354
|
-
node_set.push
|
348
|
+
node_set.push(self[x])
|
355
349
|
end
|
356
350
|
node_set
|
357
351
|
end
|
@@ -359,14 +353,12 @@ module Nokogiri
|
|
359
353
|
###
|
360
354
|
# Return a nicely formated string representation
|
361
355
|
def inspect
|
362
|
-
"[#{map(&:inspect).join
|
356
|
+
"[#{map(&:inspect).join(", ")}]"
|
363
357
|
end
|
364
358
|
|
365
|
-
|
366
|
-
|
367
|
-
# @private
|
368
|
-
IMPLIED_XPATH_CONTEXTS = [ './/'.freeze, 'self::'.freeze ].freeze # :nodoc:
|
359
|
+
alias_method :+, :|
|
369
360
|
|
361
|
+
IMPLIED_XPATH_CONTEXTS = [".//", "self::"].freeze # :nodoc:
|
370
362
|
end
|
371
363
|
end
|
372
364
|
end
|
@@ -1,7 +1,19 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module Nokogiri
|
3
4
|
module XML
|
5
|
+
# Struct representing an {XML Schema Notation}[https://www.w3.org/TR/xml/#Notations]
|
4
6
|
class Notation < Struct.new(:name, :public_id, :system_id)
|
7
|
+
# dead comment to ensure rdoc processing
|
8
|
+
|
9
|
+
# :attr: name (String)
|
10
|
+
# The name for the element.
|
11
|
+
|
12
|
+
# :attr: public_id (String)
|
13
|
+
# The URI corresponding to the public identifier
|
14
|
+
|
15
|
+
# :attr: system_id (String,nil)
|
16
|
+
# The URI corresponding to the system identifier
|
5
17
|
end
|
6
18
|
end
|
7
19
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module Nokogiri
|
3
4
|
module XML
|
4
5
|
###
|
@@ -68,18 +69,21 @@ module Nokogiri
|
|
68
69
|
NOBASEFIX = 1 << 18
|
69
70
|
# relax any hardcoded limit from the parser
|
70
71
|
HUGE = 1 << 19
|
72
|
+
# line numbers stored as long int (instead of a short int)
|
73
|
+
BIG_LINES = 1 << 22
|
71
74
|
|
72
75
|
# the default options used for parsing XML documents
|
73
|
-
DEFAULT_XML = RECOVER | NONET
|
76
|
+
DEFAULT_XML = RECOVER | NONET | BIG_LINES
|
74
77
|
# the default options used for parsing XSLT stylesheets
|
75
|
-
DEFAULT_XSLT = RECOVER | NONET | NOENT | DTDLOAD | DTDATTR | NOCDATA
|
78
|
+
DEFAULT_XSLT = RECOVER | NONET | NOENT | DTDLOAD | DTDATTR | NOCDATA | BIG_LINES
|
76
79
|
# the default options used for parsing HTML documents
|
77
|
-
DEFAULT_HTML = RECOVER | NOERROR | NOWARNING | NONET
|
80
|
+
DEFAULT_HTML = RECOVER | NOERROR | NOWARNING | NONET | BIG_LINES
|
78
81
|
# the default options used for parsing XML schemas
|
79
|
-
DEFAULT_SCHEMA = NONET
|
82
|
+
DEFAULT_SCHEMA = NONET | BIG_LINES
|
80
83
|
|
81
84
|
attr_accessor :options
|
82
|
-
|
85
|
+
|
86
|
+
def initialize(options = STRICT)
|
83
87
|
@options = options
|
84
88
|
end
|
85
89
|
|
@@ -115,14 +119,14 @@ module Nokogiri
|
|
115
119
|
other.to_i == to_i
|
116
120
|
end
|
117
121
|
|
118
|
-
|
122
|
+
alias_method :to_i, :options
|
119
123
|
|
120
124
|
def inspect
|
121
125
|
options = []
|
122
126
|
self.class.constants.each do |k|
|
123
127
|
options << k.downcase if send(:"#{k.downcase}?")
|
124
128
|
end
|
125
|
-
super.sub(/>$/, " " + options.join(
|
129
|
+
super.sub(/>$/, " " + options.join(", ") + ">")
|
126
130
|
end
|
127
131
|
end
|
128
132
|
end
|
@@ -1,17 +1,19 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module Nokogiri
|
3
4
|
module XML
|
5
|
+
# :nodoc: all
|
4
6
|
module PP
|
5
7
|
module CharacterData
|
6
|
-
def pretty_print
|
7
|
-
nice_name = self.class.name.split(
|
8
|
-
pp.group(2, "#(#{nice_name} ",
|
9
|
-
pp.pp
|
8
|
+
def pretty_print(pp)
|
9
|
+
nice_name = self.class.name.split("::").last
|
10
|
+
pp.group(2, "#(#{nice_name} ", ")") do
|
11
|
+
pp.pp(text)
|
10
12
|
end
|
11
13
|
end
|
12
14
|
|
13
|
-
def inspect
|
14
|
-
"#<#{self.class.name}:#{
|
15
|
+
def inspect
|
16
|
+
"#<#{self.class.name}:#{format("0x%x", object_id)} #{text.inspect}>"
|
15
17
|
end
|
16
18
|
end
|
17
19
|
end
|
data/lib/nokogiri/xml/pp/node.rb
CHANGED
@@ -1,54 +1,52 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module Nokogiri
|
3
4
|
module XML
|
5
|
+
# :nodoc: all
|
4
6
|
module PP
|
5
7
|
module Node
|
6
|
-
def inspect
|
7
|
-
attributes = inspect_attributes.reject
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
}.join ' '
|
17
|
-
"#<#{self.class.name}:#{sprintf("0x%x", object_id)} #{attributes}>"
|
8
|
+
def inspect
|
9
|
+
attributes = inspect_attributes.reject do |x|
|
10
|
+
attribute = send(x)
|
11
|
+
!attribute || (attribute.respond_to?(:empty?) && attribute.empty?)
|
12
|
+
rescue NoMethodError
|
13
|
+
true
|
14
|
+
end.map do |attribute|
|
15
|
+
"#{attribute.to_s.sub(/_\w+/, "s")}=#{send(attribute).inspect}"
|
16
|
+
end.join(" ")
|
17
|
+
"#<#{self.class.name}:#{format("0x%x", object_id)} #{attributes}>"
|
18
18
|
end
|
19
19
|
|
20
|
-
def pretty_print
|
21
|
-
nice_name = self.class.name.split(
|
22
|
-
pp.group(2, "#(#{nice_name}:#{
|
23
|
-
|
20
|
+
def pretty_print(pp)
|
21
|
+
nice_name = self.class.name.split("::").last
|
22
|
+
pp.group(2, "#(#{nice_name}:#{format("0x%x", object_id)} {", "})") do
|
24
23
|
pp.breakable
|
25
|
-
attrs = inspect_attributes.map
|
24
|
+
attrs = inspect_attributes.map do |t|
|
26
25
|
[t, send(t)] if respond_to?(t)
|
27
|
-
|
26
|
+
end.compact.find_all do |x|
|
28
27
|
if x.last
|
29
|
-
if [:attribute_nodes, :children].include?
|
28
|
+
if [:attribute_nodes, :children].include?(x.first)
|
30
29
|
!x.last.empty?
|
31
30
|
else
|
32
31
|
true
|
33
32
|
end
|
34
33
|
end
|
35
|
-
|
34
|
+
end
|
36
35
|
|
37
36
|
pp.seplist(attrs) do |v|
|
38
|
-
if [:attribute_nodes, :children].include?
|
39
|
-
pp.group(2, "#{v.first.to_s.sub(/_\w+$/,
|
37
|
+
if [:attribute_nodes, :children].include?(v.first)
|
38
|
+
pp.group(2, "#{v.first.to_s.sub(/_\w+$/, "s")} = [", "]") do
|
40
39
|
pp.breakable
|
41
40
|
pp.seplist(v.last) do |item|
|
42
|
-
pp.pp
|
41
|
+
pp.pp(item)
|
43
42
|
end
|
44
43
|
end
|
45
44
|
else
|
46
|
-
pp.text
|
47
|
-
pp.pp
|
45
|
+
pp.text("#{v.first} = ")
|
46
|
+
pp.pp(v.last)
|
48
47
|
end
|
49
48
|
end
|
50
49
|
pp.breakable
|
51
|
-
|
52
50
|
end
|
53
51
|
end
|
54
52
|
end
|
data/lib/nokogiri/xml/pp.rb
CHANGED
data/lib/nokogiri/xml/reader.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module Nokogiri
|
3
4
|
module XML
|
4
5
|
###
|
@@ -8,18 +9,18 @@ module Nokogiri
|
|
8
9
|
#
|
9
10
|
# Here is an example of usage:
|
10
11
|
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
12
|
+
# reader = Nokogiri::XML::Reader(<<-eoxml)
|
13
|
+
# <x xmlns:tenderlove='http://tenderlovemaking.com/'>
|
14
|
+
# <tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
|
15
|
+
# </x>
|
16
|
+
# eoxml
|
16
17
|
#
|
17
|
-
#
|
18
|
+
# reader.each do |node|
|
18
19
|
#
|
19
|
-
#
|
20
|
-
#
|
20
|
+
# # node is an instance of Nokogiri::XML::Reader
|
21
|
+
# puts node.name
|
21
22
|
#
|
22
|
-
#
|
23
|
+
# end
|
23
24
|
#
|
24
25
|
# Note that Nokogiri::XML::Reader#each can only be called once!! Once
|
25
26
|
# the cursor moves through the entire document, you must parse the
|
@@ -70,28 +71,25 @@ module Nokogiri
|
|
70
71
|
# A list of errors encountered while parsing
|
71
72
|
attr_accessor :errors
|
72
73
|
|
73
|
-
# The encoding for the document
|
74
|
-
attr_reader :encoding
|
75
|
-
|
76
74
|
# The XML source
|
77
75
|
attr_reader :source
|
78
76
|
|
79
|
-
|
77
|
+
alias_method :self_closing?, :empty_element?
|
80
78
|
|
81
|
-
def initialize
|
79
|
+
def initialize(source, url = nil, encoding = nil) # :nodoc:
|
82
80
|
@source = source
|
83
81
|
@errors = []
|
84
82
|
@encoding = encoding
|
85
83
|
end
|
86
84
|
private :initialize
|
87
85
|
|
88
|
-
###
|
89
86
|
# Get the attributes of the current node as a Hash
|
90
|
-
#
|
87
|
+
#
|
88
|
+
# [Returns] (Hash<String, String>) Attribute names and values
|
91
89
|
def attributes
|
92
90
|
attrs_hash = attribute_nodes.each_with_object({}) do |node, hash|
|
93
|
-
|
94
|
-
|
91
|
+
hash[node.name] = node.to_s
|
92
|
+
end
|
95
93
|
ns = namespaces
|
96
94
|
attrs_hash.merge!(ns) if ns
|
97
95
|
attrs_hash
|
@@ -100,7 +98,7 @@ module Nokogiri
|
|
100
98
|
###
|
101
99
|
# Move the cursor through the document yielding the cursor to the block
|
102
100
|
def each
|
103
|
-
while cursor =
|
101
|
+
while (cursor = read)
|
104
102
|
yield cursor
|
105
103
|
end
|
106
104
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module Nokogiri
|
3
4
|
module XML
|
4
5
|
###
|
@@ -65,7 +66,7 @@ module Nokogiri
|
|
65
66
|
class Document
|
66
67
|
###
|
67
68
|
# Called when an XML declaration is parsed
|
68
|
-
def xmldecl
|
69
|
+
def xmldecl(version, encoding, standalone)
|
69
70
|
end
|
70
71
|
|
71
72
|
###
|
@@ -83,13 +84,13 @@ module Nokogiri
|
|
83
84
|
# * +name+ is the name of the tag
|
84
85
|
# * +attrs+ are an assoc list of namespaces and attributes, e.g.:
|
85
86
|
# [ ["xmlns:foo", "http://sample.net"], ["size", "large"] ]
|
86
|
-
def start_element
|
87
|
+
def start_element(name, attrs = [])
|
87
88
|
end
|
88
89
|
|
89
90
|
###
|
90
91
|
# Called at the end of an element
|
91
92
|
# +name+ is the tag name
|
92
|
-
def end_element
|
93
|
+
def end_element(name)
|
93
94
|
end
|
94
95
|
|
95
96
|
###
|
@@ -99,16 +100,16 @@ module Nokogiri
|
|
99
100
|
# +prefix+ is the namespace prefix for the element
|
100
101
|
# +uri+ is the associated namespace URI
|
101
102
|
# +ns+ is a hash of namespace prefix:urls associated with the element
|
102
|
-
def start_element_namespace
|
103
|
+
def start_element_namespace(name, attrs = [], prefix = nil, uri = nil, ns = [])
|
103
104
|
###
|
104
105
|
# Deal with SAX v1 interface
|
105
|
-
name = [prefix, name].compact.join(
|
106
|
-
attributes = ns.map
|
107
|
-
[[
|
108
|
-
|
109
|
-
[[attr.prefix, attr.localname].compact.join(
|
110
|
-
|
111
|
-
start_element
|
106
|
+
name = [prefix, name].compact.join(":")
|
107
|
+
attributes = ns.map do |ns_prefix, ns_uri|
|
108
|
+
[["xmlns", ns_prefix].compact.join(":"), ns_uri]
|
109
|
+
end + attrs.map do |attr|
|
110
|
+
[[attr.prefix, attr.localname].compact.join(":"), attr.value]
|
111
|
+
end
|
112
|
+
start_element(name, attributes)
|
112
113
|
end
|
113
114
|
|
114
115
|
###
|
@@ -116,10 +117,10 @@ module Nokogiri
|
|
116
117
|
# +name+ is the element's name
|
117
118
|
# +prefix+ is the namespace prefix associated with the element
|
118
119
|
# +uri+ is the associated namespace URI
|
119
|
-
def end_element_namespace
|
120
|
+
def end_element_namespace(name, prefix = nil, uri = nil)
|
120
121
|
###
|
121
122
|
# Deal with SAX v1 interface
|
122
|
-
end_element
|
123
|
+
end_element([prefix, name].compact.join(":"))
|
123
124
|
end
|
124
125
|
|
125
126
|
###
|
@@ -127,38 +128,38 @@ module Nokogiri
|
|
127
128
|
# times given one contiguous string of characters.
|
128
129
|
#
|
129
130
|
# +string+ contains the character data
|
130
|
-
def characters
|
131
|
+
def characters(string)
|
131
132
|
end
|
132
133
|
|
133
134
|
###
|
134
135
|
# Called when comments are encountered
|
135
136
|
# +string+ contains the comment data
|
136
|
-
def comment
|
137
|
+
def comment(string)
|
137
138
|
end
|
138
139
|
|
139
140
|
###
|
140
141
|
# Called on document warnings
|
141
142
|
# +string+ contains the warning
|
142
|
-
def warning
|
143
|
+
def warning(string)
|
143
144
|
end
|
144
145
|
|
145
146
|
###
|
146
147
|
# Called on document errors
|
147
148
|
# +string+ contains the error
|
148
|
-
def error
|
149
|
+
def error(string)
|
149
150
|
end
|
150
151
|
|
151
152
|
###
|
152
153
|
# Called when cdata blocks are found
|
153
154
|
# +string+ contains the cdata content
|
154
|
-
def cdata_block
|
155
|
+
def cdata_block(string)
|
155
156
|
end
|
156
157
|
|
157
158
|
###
|
158
159
|
# Called when processing instructions are found
|
159
160
|
# +name+ is the target of the instruction
|
160
161
|
# +content+ is the value of the instruction
|
161
|
-
def processing_instruction
|
162
|
+
def processing_instruction(name, content)
|
162
163
|
end
|
163
164
|
end
|
164
165
|
end
|