Class: Lutaml::Xml::Listener

Inherits:
Model::Listener show all
Defined in:
lib/lutaml/xml/listener.rb

Overview

XML-specific listener for the listener-based mapping model.

XML listeners respond to XML element names and can have custom handler blocks for complex deserialization logic.

Examples:

Adding a listener to a mapping class

class MyMapping < Lutaml::Xml::Mapping
  on_element "CustomElement" do |element, context|
    context[:custom] = CustomParser.parse(element)
  end
end

Listener with ID for override/omit support

class MyMapping < Lutaml::Xml::Mapping
  on_element "Documentation", id: :parse_docs do |element, context|
    context[:documentation] = Documentation.from_xml(element)
  end
end

Instance Attribute Summary

Attributes inherited from Model::Listener

#handler, #id, #options, #target

Instance Method Summary collapse

Methods inherited from Model::Listener

#call, #complex?, #eql?, #inspect, #simple?, #to_s

Constructor Details

#initialize(id:, target:, handler: nil) ⇒ Listener

Returns a new instance of Listener.

Parameters:

  • id (Symbol, String, nil)

    Unique identifier for override/omit.

  • target (String)

    XML element name this listener responds to.

  • handler (Proc, nil) (defaults to: nil)

    Custom block handler.

  • options (Hash)

    Additional options.



28
29
30
# File 'lib/lutaml/xml/listener.rb', line 28

def initialize(id:, target:, handler: nil, **)
  super
end