Class: Moxml::SAX::Handler

Inherits:
Object
  • Object
show all
Defined in:
lib/moxml/sax/handler.rb

Overview

Abstract base class for SAX event handlers

This class defines the interface for handling SAX parsing events. Subclass this and override the event methods you need to handle.

All event methods have default implementations that do nothing, so you only need to override the events you care about.

Examples:

Create a custom handler

class BookHandler < Moxml::SAX::Handler
  def on_start_element(name, attributes = {}, namespaces = {})
    puts "Found element: #{name}"
  end
end

Direct Known Subclasses

BlockHandler, ElementHandler

Instance Method Summary collapse

Instance Method Details

#on_cdata(text) ⇒ void

This method returns an undefined value.

Called when a CDATA section is encountered

Parameters:

  • text (String)

    CDATA content



68
69
70
# File 'lib/moxml/sax/handler.rb', line 68

def on_cdata(text)
  # Override in subclass if needed
end

#on_characters(text) ⇒ void

This method returns an undefined value.

Called when character data is encountered

Note: This may be called multiple times for a single text node if the parser breaks it into chunks. Concatenate if needed.

Parameters:

  • text (String)

    Character data



60
61
62
# File 'lib/moxml/sax/handler.rb', line 60

def on_characters(text)
  # Override in subclass if needed
end

#on_comment(text) ⇒ void

This method returns an undefined value.

Called when a comment is encountered

Parameters:

  • text (String)

    Comment content



76
77
78
# File 'lib/moxml/sax/handler.rb', line 76

def on_comment(text)
  # Override in subclass if needed
end

#on_end_documentvoid

This method returns an undefined value.

Called when parsing completes successfully



31
32
33
# File 'lib/moxml/sax/handler.rb', line 31

def on_end_document
  # Override in subclass if needed
end

#on_end_element(name) ⇒ void

This method returns an undefined value.

Called when a closing tag is encountered

Parameters:

  • name (String)

    Element name



49
50
51
# File 'lib/moxml/sax/handler.rb', line 49

def on_end_element(name)
  # Override in subclass if needed
end

#on_error(error) ⇒ void

This method returns an undefined value.

Called when a fatal parsing error occurs

Default implementation raises the error. Override to handle errors differently.

Parameters:

Raises:



97
98
99
# File 'lib/moxml/sax/handler.rb', line 97

def on_error(error)
  raise error
end

#on_processing_instruction(target, data) ⇒ void

This method returns an undefined value.

Called when a processing instruction is encountered

Parameters:

  • target (String)

    PI target

  • data (String)

    PI data/content



85
86
87
# File 'lib/moxml/sax/handler.rb', line 85

def on_processing_instruction(target, data)
  # Override in subclass if needed
end

#on_start_documentvoid

This method returns an undefined value.

Called when parsing begins



24
25
26
# File 'lib/moxml/sax/handler.rb', line 24

def on_start_document
  # Override in subclass if needed
end

#on_start_element(name, attributes = {}, namespaces = {}) ⇒ void

This method returns an undefined value.

Called when an opening tag is encountered

Parameters:

  • name (String)

    Element name (with namespace prefix if present)

  • attributes (Hash<String, String>) (defaults to: {})

    Element attributes

  • namespaces (Hash<String, String>) (defaults to: {})

    Namespace declarations on this element



41
42
43
# File 'lib/moxml/sax/handler.rb', line 41

def on_start_element(name, attributes = {}, namespaces = {})
  # Override in subclass if needed
end

#on_warning(message) ⇒ void

This method returns an undefined value.

Called when a non-fatal warning occurs

Default implementation ignores warnings. Override to handle warnings (e.g., log them).

Parameters:

  • message (String)

    Warning message



108
109
110
# File 'lib/moxml/sax/handler.rb', line 108

def on_warning(message)
  # Override in subclass if needed
end