class XSD::XMLParser::Parser

Attributes

charset[RW]

Public Class Methods

add_factory(factory) click to toggle source
# File lib/xsd/xmlparser/parser.rb, line 40
def self.add_factory(factory)
  if $DEBUG
    puts "Set #{ factory } as XML processor."
  end
  @@parser_factory = factory
end
create_parser(host, opt = {}) click to toggle source
# File lib/xsd/xmlparser/parser.rb, line 33
def self.create_parser(host, opt = {})
  unless @@parser_factory
    raise ParserError.new("illegal XML parser configuration")
  end
  @@parser_factory.new(host, opt)
end
factory() click to toggle source
# File lib/xsd/xmlparser/parser.rb, line 29
def self.factory
  @@parser_factory
end
new(host, opt = {}) click to toggle source
# File lib/xsd/xmlparser/parser.rb, line 51
def initialize(host, opt = {})
  @host = host
  @charset = opt[:charset] || nil
end

Public Instance Methods

parse(string_or_readable) click to toggle source
# File lib/xsd/xmlparser/parser.rb, line 56
def parse(string_or_readable)
  @textbuf = ''
  prologue
  do_parse(string_or_readable)
  epilogue
end

Private Instance Methods

characters(text) click to toggle source
# File lib/xsd/xmlparser/parser.rb, line 74
def characters(text)
  @host.characters(text)
end
do_parse(string_or_readable) click to toggle source
# File lib/xsd/xmlparser/parser.rb, line 65
def do_parse(string_or_readable)
  raise ParserError.new(
    'Method do_parse must be defined in derived class.')
end
end_element(name) click to toggle source
# File lib/xsd/xmlparser/parser.rb, line 78
def end_element(name)
  @host.end_element(name)
end
epilogue() click to toggle source
# File lib/xsd/xmlparser/parser.rb, line 85
def epilogue
end
prologue() click to toggle source
# File lib/xsd/xmlparser/parser.rb, line 82
def prologue
end
start_element(name, attrs) click to toggle source
# File lib/xsd/xmlparser/parser.rb, line 70
def start_element(name, attrs)
  @host.start_element(name, attrs)
end
xmldecl_encoding=(charset) click to toggle source
# File lib/xsd/xmlparser/parser.rb, line 88
def xmldecl_encoding=(charset)
  if @charset.nil?
    @charset = charset
    p "encoding definition: #{ charset } is configured." if $DEBUG
  else
    # Definition in a stream (like HTTP) has a priority.
    p "encoding definition: #{ charset } is ignored." if $DEBUG
  end
end