Module: Canon::Xml::Sax

Defined in:
lib/canon/xml/sax.rb,
lib/canon/xml/sax/moxml_driver.rb,
lib/canon/xml/sax/nokogiri_driver.rb

Overview

SAX engine selection and driving for the data-model builder.

The builder (SaxBuilder) owns tree construction and speaks a single engine-neutral event protocol (Nokogiri-shaped: qname + attribute pairs with xmlns entries inline). Each driver adapts one engine's SAX API to that protocol. OCP: a new engine is a new driver plus one line here; the builder never changes.

Engine choice: the leptris SAX flip is armed but blocked twice over. The batch-attribute corruption (leptris-ruby#95) is answered by a correctness-first path in leptris 1.9.36 — attributes are correct, but that path DROPS namespace declarations from SAX events entirely (raw ["<root xmlns:a=.../>", []] — xmlns pairs vanish), blinding namespace comparison. Until xmlns reporting is restored (and then the fast path returns with the C fix), CRuby keeps the Nokogiri driver; the flip is the one-line change below. With leptris absent (moxml resolving nokogiri) the driver calls Nokogiri directly — the wrapper layer only adds overhead there.

Defined Under Namespace

Classes: MoxmlDriver, NokogiriDriver

Class Method Summary collapse

Class Method Details

.parse(xml_string, builder) ⇒ Object

Drive builder with the runtime's SAX engine.



29
30
31
32
33
34
35
36
# File 'lib/canon/xml/sax.rb', line 29

def parse(xml_string, builder)
  if RUBY_ENGINE == "opal"
    MoxmlDriver.new(builder).parse(xml_string)
  else
    NokogiriDriver.new(builder).parse(xml_string)
  end
  nil
end