Class: Arachni::Parser::SAX

Inherits:
Ox::Sax
  • Object
show all
Defined in:
lib/arachni/parser/sax.rb

Defined Under Namespace

Classes: Stop

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ SAX

Returns a new instance of SAX.



20
21
22
23
24
25
26
27
28
29
# File 'lib/arachni/parser/sax.rb', line 20

def initialize( options = {} )
    super()

    @document = Document.new

    @stop_on_first = Set.new
    @stop_on_first.merge( options[:stop_on_first] ) if options[:stop_on_first]

    @current_node = @document
end

Instance Attribute Details

#documentObject (readonly)

Returns the value of attribute document.



18
19
20
# File 'lib/arachni/parser/sax.rb', line 18

def document
  @document
end

Instance Method Details

#attr(name, value) ⇒ Object



51
52
53
54
55
# File 'lib/arachni/parser/sax.rb', line 51

def attr( name, value )
    return if !@current_node.respond_to?( :attributes )

    @current_node.attributes[name] = value
end

#comment(value) ⇒ Object



62
63
64
# File 'lib/arachni/parser/sax.rb', line 62

def comment( value )
    @current_node << Nodes::Comment.new( value )
end

#end_element(name) ⇒ Object



44
45
46
47
48
49
# File 'lib/arachni/parser/sax.rb', line 44

def end_element( name )
    # Finished parsing the desired element, abort.
    fail Stop if @stop

    @current_node = @current_node.parent
end

#start_element(name) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/arachni/parser/sax.rb', line 31

def start_element( name )
    # We were instructed to stop on the first sight of the previous element
    # but came across this one before it closed.
    fail Stop if @stop
    @stop = stop?( name )

    e = Nodes::Element.new( name )

    e.document     = @document
    @current_node << e
    @current_node  = e
end

#text(value) ⇒ Object



57
58
59
60
# File 'lib/arachni/parser/sax.rb', line 57

def text( value )
    return if value.strip.empty?
    @current_node << Nodes::Text.new( value )
end