Class: XMLUtils::XMLStreamParser

Inherits:
Object
  • Object
show all
Defined in:
lib/stream_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(listener = nil) ⇒ XMLStreamParser

Returns a new instance of XMLStreamParser.



61
62
63
64
65
66
# File 'lib/stream_parser.rb', line 61

def initialize(listener=nil)
  @listener = listener
  @contents = XMLSParserContents.new
  @elid = 0
  @elements = [XMLSParserElement.root(self)]
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(methId, *args) ⇒ Object

Ignore everything except tags and text for now



105
106
# File 'lib/stream_parser.rb', line 105

def method_missing(methId, *args)
end

Instance Attribute Details

#contentsObject (readonly)

Returns the value of attribute contents.



59
60
61
# File 'lib/stream_parser.rb', line 59

def contents
  @contents
end

Instance Method Details

#consumeObject



100
101
102
# File 'lib/stream_parser.rb', line 100

def consume
  @contents.erase_from(@elements[-1].elstart)
end

#contentObject



96
97
98
# File 'lib/stream_parser.rb', line 96

def content
  @contents.text_from(@elements[-1].elstart)
end

#new_element_idObject



68
69
70
71
72
# File 'lib/stream_parser.rb', line 68

def new_element_id
  previous = @elid
  @elid += 1
  previous
end

#parse(text) ⇒ Object



74
75
76
# File 'lib/stream_parser.rb', line 74

def parse(text)
  REXML::Document.parse_stream(text, self)
end

#tag_end(name) ⇒ Object



88
89
90
91
92
93
94
# File 'lib/stream_parser.rb', line 88

def tag_end(name)
  @contents << "</"+name+">"
  if @listener.respond_to? 'el_'+name
    @listener.send('el_'+name, @elements[-1])
  end
  @elements.pop()
end

#tag_start(name, attrs) ⇒ Object



78
79
80
81
82
# File 'lib/stream_parser.rb', line 78

def tag_start(name, attrs)
  @elements << XMLSParserElement.new(name, @contents.size, 
                                          self, @elements[-1])
  @contents << XMLUtils.create_open_tag(name, attrs)
end

#text(text) ⇒ Object



84
85
86
# File 'lib/stream_parser.rb', line 84

def text(text)
  @contents << XMLUtils.escape_xml(text)
end