Module: Leptris::XML::Pull
- Defined in:
- lib/leptris/xml/pull.rb
Overview
Pull parsing (libleptris v1.6.0): a StAX-style cursor over a document. Each #next advances one event; attributes are readable only during the start_element event just returned.
Leptris::XML::Pull.parse(xml).each do |event|
case event.type
when :start_element then handle(event.name, event.attrs)
when :text then handle(event.text)
end
end
Defined Under Namespace
Constant Summary collapse
- TYPES =
{ Leptris::XML::FFI::PULL_START_ELEMENT => :start_element, Leptris::XML::FFI::PULL_END_ELEMENT => :end_element, Leptris::XML::FFI::PULL_TEXT => :text, Leptris::XML::FFI::PULL_COMMENT => :comment, Leptris::XML::FFI::PULL_CDATA => :cdata, Leptris::XML::FFI::PULL_PI => :pi, Leptris::XML::FFI::PULL_END_DOCUMENT => :end_document, Leptris::XML::FFI::PULL_ERROR => :error, }.freeze
Class Method Summary collapse
Class Method Details
.parse(xml_or_io, &block) ⇒ Object
161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/leptris/xml/pull.rb', line 161 def self.parse(xml_or_io, &block) parser = Parser.parse(xml_or_io) if block begin parser.each(&block) ensure parser.free end else parser end end |
.parse_file(path, &block) ⇒ Object
174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/leptris/xml/pull.rb', line 174 def self.parse_file(path, &block) parser = Parser.parse_file(path) if block begin parser.each(&block) ensure parser.free end else parser end end |