module Xlsxrb::Ooxml::XmlParser
Thin wrapper around REXML SAX2 parser for streaming XML processing. Unknown elements are captured as unmapped data hashes.
Constants
- MAX_ELEMENT_DEPTH
-
Elementsmay nest this deep. SpreadsheetML, DrawingML, and VML parts stay far below it, and REXML’s SAX2 parser takes time proportional to the depth for every tag, so that 20,000 nested elements (a 3 KB file) took 15 seconds.
Public Class Methods
(untyped xml_string, untyped listener) → untyped
Source
# File lib/xlsxrb/ooxml/xml_parser.rb, line 64 def self.parse(xml_string, listener) parser = sax2_parser(xml_string) parser.listen(listener) parser.parse end
Parses XML string using SAX2, calling the given listener.
(String xml_string, Array[untyped] listeners) → void
Source
# File lib/xlsxrb/ooxml/xml_parser.rb, line 72 def self.parse_listeners(xml_string, listeners) return if listeners.empty? parse(xml_string, MultiListener.new(listeners)) end
Parses XML string once using SAX2, forwarding events to all given listeners.
(String xml_string) → REXML::Parsers::SAX2Parser
Source
# File lib/xlsxrb/ooxml/xml_parser.rb, line 107 def self.sax2_parser(xml_string) DecodingSAX2Parser.new(xml_string) end
Returns a SAX2 parser whose listeners receive attribute values with XML entities decoded. REXML’s SAX2 parser decodes text but passes attribute values as written, so formatCode=“"$"0” would otherwise arrive with the " references.