1
# XSD4R - XML Instance parser library.
2
# Copyright (C) 2002, 2003 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
4
# This program is copyrighted free software by NAKAMURA, Hiroshi. You can
5
# redistribute it and/or modify it under the same terms of Ruby's license;
6
# either the dual license version in 2003, or any later version.
19
class ParseError < Error; end
20
class FormatDecodeError < ParseError; end
21
class UnknownElementError < FormatDecodeError; end
22
class UnknownAttributeError < FormatDecodeError; end
23
class UnexpectedElementError < FormatDecodeError; end
24
class ElementConstraintError < FormatDecodeError; end
26
@@parser_factory = nil
32
def self.create_parser(host, opt = {})
33
@@parser_factory.new(host, opt)
36
def self.add_factory(factory)
38
puts "Set #{ factory } as XML processor."
40
@@parser_factory = factory
45
attr_accessor :charset
47
def initialize(host, opt = {})
49
@charset = opt[:charset] || nil
52
def parse(string_or_readable)
55
do_parse(string_or_readable)
61
def do_parse(string_or_readable)
62
raise NotImplementError.new(
63
'Method do_parse must be defined in derived class.')
66
def start_element(name, attrs)
67
@host.start_element(name, attrs)
71
@host.characters(text)
75
@host.end_element(name)
84
def xmldecl_encoding=(charset)
88
# Definition in a stream (like HTTP) has a priority.
89
p "encoding definition: #{ charset } is ignored." if $DEBUG