1
libxml의 SAX 파서 (illustrated here)를 사용하려고하지만 정의되지 않은 메서드 오류가 발생합니다.libxml의 색소폰 파서를 사용할 때 정의되지 않은 메서드 오류
내가 그것을 실행하면 내 코드와
$domain_topics = Hash.new { |h,d| h[d] = [] }
parser = LibXML::XML::SaxParser.io(
File.open("content.rdf.u8", "r:UTF-8")
)
class Callbacks
include LibXML::XML::SaxParser::Callbacks
def initialize
@state = :top
@topics = nil
end
def on_start_element(element, attributes)
case @state
when :top
return unless element == 'ExternalPage'
@state = :ExternalPage
domain = attributes['about'].sub(%r!^\w+://([^"/]*)(?:/[^"]*)?$!, '\1')
@topics = $domain_topics[domain]
when :ExternalPage
return unless element == 'topic'
@state = :topic
end
end
def on_characters(characters)
if @state == :topic and @topics
@topics << characters
end
end
def on_end_element(element)
case @state
when :ExternalPage
@state = :top
@topics = nil
when :topic
@state = :ExternalPage
end
end
end
parser.callbacks = Callbacks
parser.parse
입니다 : 내가 잘못 여기서 뭐하는 거지
% ./my_awesome_code.rb
./my_awesome_code.rb:1337:in `parse': undefined method `on_start_document' for Callbacks:Class (NoMethodError)
? include LibXML::XML::SaxParser::Callbacks
에 on_start_document
에 대한 기본 정의를 지정하면 안됩니까?
IRB 내 직감 확인하는 것 같다
1.9.3p194 :009 > Callbacks.instance_methods.include? :on_start_document
=> true