# File rss/parser.rb, line 267
def initialize
@rss = nil
@ignore_unknown_element = true
@do_validate = true
@ns_stack = [{"xml" => :xml}]
@tag_stack = [[]]
@text_stack = ['']
@proc_stack = []
@last_element = nil
@version = @encoding = @standalone = nil
@xml_stylesheets = []
@xml_child_mode = false
@xml_element = nil
@last_xml_element = nil
end
# File rss/parser.rb, line 288
def instruction(name, content)
if name == "xml-stylesheet"
params = parse_pi_content(content)
if params.has_key?("href")
@xml_stylesheets << XMLStyleSheet.new(params)
end
end
end
# File rss/parser.rb, line 350
def tag_end(name)
if DEBUG
p "end tag #{name}"
p @tag_stack
end
text = @text_stack.pop
tags = @tag_stack.pop
pr = @proc_stack.pop
pr.call(text, tags) unless pr.nil?
@ns_stack.pop
end
# File rss/parser.rb, line 297
def tag_start(name, attributes)
@text_stack.push('')
ns = @ns_stack.last.dup
attrs = {}
attributes.each do |n, v|
if /\Axmlns(?:\z|:)/ =~ n
ns[$POSTMATCH] = v
else
attrs[n] = v
end
end
@ns_stack.push(ns)
prefix, local = split_name(name)
@tag_stack.last.push([_ns(ns, prefix), local])
@tag_stack.push([])
if @xml_child_mode
previous = @last_xml_element
element_attrs = attributes.dup
unless previous
ns.each do |ns_prefix, value|
next if ns_prefix == "xml"
key = ns_prefix.empty? ? "xmlns" : "xmlns:#{ns_prefix}"
element_attrs[key] ||= value
end
end
next_element = XML::Element.new(local,
prefix.empty? ? nil : prefix,
_ns(ns, prefix),
element_attrs)
previous << next_element if previous
@last_xml_element = next_element
pr = Proc.new do |text, tags|
if previous
@last_xml_element = previous
else
@xml_element = @last_xml_element
@last_xml_element = nil
end
end
@proc_stack.push(pr)
else
if @rss.nil? and respond_to?("initial_start_#{local}", true)
__send__("initial_start_#{local}", local, prefix, attrs, ns.dup)
elsif respond_to?("start_#{local}", true)
__send__("start_#{local}", local, prefix, attrs, ns.dup)
else
start_else_element(local, prefix, attrs, ns.dup)
end
end
end
Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.
If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.
If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.
If you want to help improve the Ruby documentation, please see Improve the docs, or visit Documenting-ruby.org.