Class: XML::LibXMLSax2wrapper

Inherits:
Object
  • Object
show all
Includes:
LibXML::XML::SaxParser::Callbacks
Defined in:
lib/rtm/activerecord/io/from_xtm2_libxml.rb

Overview

Acts as Callback structure for the LibXML-Ruby SAX Parser and calls a REXML SAX2Listener API.

Instance Method Summary collapse

Constructor Details

#initialize(rexml_sax2listener) ⇒ LibXMLSax2wrapper



43
44
45
46
# File 'lib/rtm/activerecord/io/from_xtm2_libxml.rb', line 43

def initialize(rexml_sax2listener)
  @dest = rexml_sax2listener
  @ns = Hash.new("http://www.topicmaps.org/xtm/")
end

Instance Method Details

#on_cdata_block(content) ⇒ Object



76
77
78
# File 'lib/rtm/activerecord/io/from_xtm2_libxml.rb', line 76

def on_cdata_block(content)
  @dest.cdata(content)
end

#on_characters(text) ⇒ Object



73
74
75
# File 'lib/rtm/activerecord/io/from_xtm2_libxml.rb', line 73

def on_characters(text)
  @dest.characters(text)
end

#on_end_documentObject



50
51
52
# File 'lib/rtm/activerecord/io/from_xtm2_libxml.rb', line 50

def on_end_document
  @dest.end_document
end

#on_end_element(qname) ⇒ Object



63
64
65
66
67
68
69
70
71
72
# File 'lib/rtm/activerecord/io/from_xtm2_libxml.rb', line 63

def on_end_element(qname)
  prefix, localname = qname.split(":")
  unless localname
    localname = prefix
    uri = @ns.default
  else
    uri = @ns[prefix]
  end
  @dest.end_element(uri, localname, qname)
end

#on_parser_error(msg) ⇒ Object



79
80
81
# File 'lib/rtm/activerecord/io/from_xtm2_libxml.rb', line 79

def on_parser_error(msg)
 warn("SAX Parser Error: #{msg}")
end

#on_parser_fatal_error(msg) ⇒ Object



85
86
87
# File 'lib/rtm/activerecord/io/from_xtm2_libxml.rb', line 85

def on_parser_fatal_error(msg)
  warn("SAX Parser Fatal Error: #{msg}")
end

#on_parser_warning(*msg) ⇒ Object



82
83
84
# File 'lib/rtm/activerecord/io/from_xtm2_libxml.rb', line 82

def on_parser_warning(*msg)
  warn("SAX Parser Warning: #{msg}")
end

#on_start_documentObject



47
48
49
# File 'lib/rtm/activerecord/io/from_xtm2_libxml.rb', line 47

def on_start_document
  @dest.start_document
end

#on_start_element(qname, attr) ⇒ Object



53
54
55
56
57
58
59
60
61
62
# File 'lib/rtm/activerecord/io/from_xtm2_libxml.rb', line 53

def on_start_element(qname, attr)
  prefix, localname = qname.split(":")
  unless localname
    localname = prefix
    uri = @ns.default
  else
    uri = @ns[prefix]
  end
  @dest.start_element(uri, localname, qname, attr)
end