Class: XmlEasy::EasyListener

Inherits:
Object
  • Object
show all
Includes:
REXML::StreamListener
Defined in:
lib/xml_easy.rb

Instance Method Summary collapse

Constructor Details

#initialize(doc) ⇒ EasyListener

Returns a new instance of EasyListener.



38
39
40
41
# File 'lib/xml_easy.rb', line 38

def initialize(doc)
  @doc = doc
  @current = doc.root
end

Instance Method Details

#attlistdecl(elm_name, attrs, content) ⇒ Object



43
# File 'lib/xml_easy.rb', line 43

def attlistdecl(elm_name, attrs, content); end

#cdata(content) ⇒ Object



44
# File 'lib/xml_easy.rb', line 44

def cdata(content); end

#comment(content) ⇒ Object



45
# File 'lib/xml_easy.rb', line 45

def comment(content); end

#doctype(name, pub_sys, long_name, uri) ⇒ Object



61
62
63
64
# File 'lib/xml_easy.rb', line 61

def doctype(name, pub_sys, long_name, uri)
  #TODO: temporary
  @doc.doc_type = "<!DOCTYPE window [<!ENTITY nl '&#38;#10;'>]>"
end

#doctype_endObject



69
70
# File 'lib/xml_easy.rb', line 69

def doctype_end
end

#elementdecl(content) ⇒ Object



46
# File 'lib/xml_easy.rb', line 46

def elementdecl(content); end

#entity(content) ⇒ Object



47
# File 'lib/xml_easy.rb', line 47

def entity(content); end

#entitydecl(content) ⇒ Object



66
67
# File 'lib/xml_easy.rb', line 66

def entitydecl(content)
end

#instruction(name, inst) ⇒ Object



48
# File 'lib/xml_easy.rb', line 48

def instruction(name, inst); end

#notationdecl(content) ⇒ Object



49
# File 'lib/xml_easy.rb', line 49

def notationdecl(content); end

#tag_end(name) ⇒ Object



79
80
81
82
83
84
85
# File 'lib/xml_easy.rb', line 79

def tag_end(name)
  if @current.name == name.to_sym
    @current = @current.parent
  else
    raise RuntimeError.new("unmatch end-tag: #{name.inspect}")
  end
end

#tag_start(name, attrs) ⇒ Object



72
73
74
75
76
77
# File 'lib/xml_easy.rb', line 72

def tag_start(name, attrs)
  element = Element.new name
  attrs.each{|k, v| element[k] = v.gsub('"', '&quot;').inspect}
  @current << element
  @current = element
end

#text(content) ⇒ Object



87
88
89
# File 'lib/xml_easy.rb', line 87

def text(content)
  @current.body = content
end

#xmldecl(version, encoding, standalone) ⇒ Object



51
52
53
54
55
56
57
58
59
# File 'lib/xml_easy.rb', line 51

def xmldecl(version, encoding, standalone)
  @doc.xml_dec = "<?xml#{
    version ? " version='#{version}'" : ''
  }#{
    encoding ? " encoding='#{encoding}'" : ''
  }#{
    standalone ? " standalone='#{standalone}'" : ''
  }?>"
end