Class: XML::LibXMLSax2wrapper

Inherits:
Object
  • Object
show all
Includes:
LibXML::XML::SaxParser::Callbacks
Defined in:
lib/rtm/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

Returns a new instance of LibXMLSax2wrapper.



38
39
40
41
# File 'lib/rtm/io/from_xtm2_libxml.rb', line 38

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

Instance Method Details

#on_cdata_block(content) ⇒ Object



71
72
73
# File 'lib/rtm/io/from_xtm2_libxml.rb', line 71

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

#on_characters(text) ⇒ Object



68
69
70
# File 'lib/rtm/io/from_xtm2_libxml.rb', line 68

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

#on_end_documentObject



45
46
47
# File 'lib/rtm/io/from_xtm2_libxml.rb', line 45

def on_end_document
  @dest.end_document
end

#on_end_element(qname) ⇒ Object



58
59
60
61
62
63
64
65
66
67
# File 'lib/rtm/io/from_xtm2_libxml.rb', line 58

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



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

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

#on_parser_fatal_error(msg) ⇒ Object



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

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

#on_parser_warning(*msg) ⇒ Object



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

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

#on_start_documentObject



42
43
44
# File 'lib/rtm/io/from_xtm2_libxml.rb', line 42

def on_start_document
  @dest.start_document
end

#on_start_element(qname, attr) ⇒ Object



48
49
50
51
52
53
54
55
56
57
# File 'lib/rtm/io/from_xtm2_libxml.rb', line 48

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