Class: XMLUtils::XMLStreamParser
- Inherits:
-
Nokogiri::XML::SAX::Document
- Object
- Nokogiri::XML::SAX::Document
- XMLUtils::XMLStreamParser
- Defined in:
- lib/stream_parser.rb
Instance Attribute Summary collapse
-
#contents ⇒ Object
readonly
Returns the value of attribute contents.
Instance Method Summary collapse
- #characters(text) ⇒ Object
- #consume ⇒ Object
- #content ⇒ Object
- #end_element(name) ⇒ Object
-
#initialize(listener = nil) ⇒ XMLStreamParser
constructor
A new instance of XMLStreamParser.
- #new_element_id ⇒ Object
- #parse(text) ⇒ Object
- #start_element(name, attrs) ⇒ Object
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 |
Instance Attribute Details
#contents ⇒ Object (readonly)
Returns the value of attribute contents.
59 60 61 |
# File 'lib/stream_parser.rb', line 59 def contents @contents end |
Instance Method Details
#characters(text) ⇒ Object
85 86 87 |
# File 'lib/stream_parser.rb', line 85 def characters(text) @contents << XMLCodec::XMLUtils.escape_xml(text) end |
#consume ⇒ Object
101 102 103 |
# File 'lib/stream_parser.rb', line 101 def consume @contents.erase_from(@elements[-1].elstart) end |
#content ⇒ Object
97 98 99 |
# File 'lib/stream_parser.rb', line 97 def content @contents.text_from(@elements[-1].elstart) end |
#end_element(name) ⇒ Object
89 90 91 92 93 94 95 |
# File 'lib/stream_parser.rb', line 89 def end_element(name) @contents << "</"+name+">" if @listener.respond_to? 'el_'+name @listener.send('el_'+name, @elements[-1]) end @elements.pop() end |
#new_element_id ⇒ Object
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 77 |
# File 'lib/stream_parser.rb', line 74 def parse(text) parser = Nokogiri::XML::SAX::Parser.new(self) parser.parse(text) end |
#start_element(name, attrs) ⇒ Object
79 80 81 82 83 |
# File 'lib/stream_parser.rb', line 79 def start_element(name, attrs) @elements << XMLSParserElement.new(name, @contents.size, self, @elements[-1]) @contents << XMLCodec::XMLUtils.create_open_tag(name, attrs) end |