Class: Risu::Parsers::Nessus::NessusSaxListener
- Inherits:
-
Object
- Object
- Risu::Parsers::Nessus::NessusSaxListener
- Includes:
- LibXML::XML::SaxParser::Callbacks
- Defined in:
- lib/risu/parsers/nessus/nessus_sax_listener.rb
Overview
NessusSaxListener
Instance Attribute Summary collapse
-
#new_tags ⇒ Object
Returns the value of attribute new_tags.
Instance Method Summary collapse
-
#initialize ⇒ NessusSaxListener
constructor
vals tracks state for elements encountered during parsing.
-
#on_characters(text) ⇒ Object
Called when the inner text of a element is reached.
-
#on_end_element(element) ⇒ Object
Called when the end of the XML element is reached.
-
#on_start_element(element, attributes) ⇒ Object
Callback for when the start of a XML element is reached.
Constructor Details
#initialize ⇒ NessusSaxListener
vals tracks state for elements encountered during parsing
155 156 157 158 |
# File 'lib/risu/parsers/nessus/nessus_sax_listener.rb', line 155 def initialize @vals = Hash.new @new_tags = Array.new end |
Instance Attribute Details
#new_tags ⇒ Object
Returns the value of attribute new_tags.
34 35 36 |
# File 'lib/risu/parsers/nessus/nessus_sax_listener.rb', line 34 def @new_tags end |
Instance Method Details
#on_characters(text) ⇒ Object
Called when the inner text of a element is reached
182 183 184 185 186 187 188 |
# File 'lib/risu/parsers/nessus/nessus_sax_listener.rb', line 182 def on_characters(text) if @vals[@tag] == nil then @vals[@tag] = text else @vals[@tag] << text end end |
#on_end_element(element) ⇒ Object
Called when the end of the XML element is reached
193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/risu/parsers/nessus/nessus_sax_listener.rb', line 193 def on_end_element(element) @tag = nil if DYNAMIC_END_METHOD_NAMES.key?(element) # Dynamic dispatch to private instance methods in the const hash # DYNAMIC_END_METHOD_NAMES where {"element" => :end_element} send(DYNAMIC_END_METHOD_NAMES[element], element) elsif VALID_REFERENCES.include?(element) end_valid_reference(element) end end |
#on_start_element(element, attributes) ⇒ Object
Callback for when the start of a XML element is reached
164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/risu/parsers/nessus/nessus_sax_listener.rb', line 164 def on_start_element(element, attributes) @tag = element @vals[@tag] = "" if !VALID_ELEMENTS.include?(element) @new_tags << "New XML element detected: #{element}. Please report this at #{Risu::GITHUB}/issues/new or via email to #{Risu::EMAIL}" end if DYNAMIC_START_METHOD_NAMES.key?(element) # Dynamic dispatch to private instance "policyComments"methods in the const hash # DYNAMIC_START_METHOD_NAMES where {"element" => :start_element} send(DYNAMIC_START_METHOD_NAMES[element], element, attributes) end end |