class XML::SAX::Handlers

Direct Known Subclasses

Defined in:

sax/handlers.cr

Instance Method Summary

Instance Method Detail

def attlist_decl(element_name : String, name : String, type : Symbol, names : Array(String) | Nil, default : Symbol, value : String | Nil) : Nil #

Called for attribute declarations in a DTD.

Called for every attribute in attlist declaration: if an attlist has multiple attribute declarations, the method will be called for each one.

  • element_name is the element name the attribute is declared for.
  • name is the attribute name.
  • type is the attribute type as a symbol, for example :CDATA, :IDREFS, :NOTATION or :ENUMERATION.
  • names an array of names if type is :NOTATION or :ENUMERATION, nil otherwise.
  • default can be :REQUIRED, :IMPLIED or :FIXED.
  • value is the default value when default is :FIXED, nil otherwise.

[View source]
def cdata_section(data : String) : Nil #

Called for CDATA sections.

  • data is all the text inside the data section.

[View source]
def character_data(data : String) : Nil #

Called for text.

It might be called multiple times for a single contiguous text in a XML document (for example because we processed an entity). You might have to concatenate data when searching for some pattern in text, or to build a single text node in a DOM tree.


[View source]
def comment(data : String) : Nil #

Called for comments.

  • data is all the text inside the comment.

[View source]
def element_decl(name : String, content : ElementDecl) : Nil #

Called for element declarations in a DTD.

  • name is the declared element name.
  • content is the declared element model.

[View source]
def empty_element(name : String, attributes : Array(Tuple(String, String))) : Nil #

Called for an empty element tag.

See #start_element for details.

Unless overridden, calls #start_element then #end_element by default.


[View source]
def end_doctype_decl : Nil #

Called at the and of a DOCTYPE declaration.


[View source]
def end_element(name : String) : Nil #

Called at the end of an element tag.


[View source]
def entity_decl(entity : Entity) : Nil #

Called for entity declarations in a DTD.

  • entity is the declared entity definition.

[View source]
def entity_reference(name : String) #

Called when trying to expand an undeclared or invalid entity within character data.


[View source]
def error(message : String, location : Location) #

Called when a recoverable error happens.

  • message details the error.
  • location is the line/column where the parser reached the error.

Unless overridden, raises an Error by default.


[View source]
def notation_decl(name : String, public_id : String | Nil, system_id : String | Nil) : Nil #

Called for notation declarations in a DTD.

  • name is the declared notation name.
  • system_id and public_id will be nil when unspecified.

[View source]
def open_external(base : String | Nil, uri : String, & : String, IO -> ) : Nil #

Called when trying to open an external entity or doctype.

The IO should be closed after the block has returned.


[View source]
def open_external(base : String | Nil, uri : String) : Tuple(String, IO) | Nil #

[View source]
def processing_instruction(target : String, data : String) : Nil #

Called for processing instructions.

  • target is the first word in the processing instruction.
  • data is the rest of the instruction.

[View source]
def start_doctype_decl(name : String, system_id : String | Nil, public_id : String | Nil, intsubset : Bool) #

Called at the start of a DOCTYPE declaration.

  • name is the root element name.
  • system_id and public_id will be nil when unspecified.
  • intsubset is true when the doctype has an internal subset declaration.

[View source]
def start_element(name : String, attributes : Array(Tuple(String, String))) : Nil #

Called at the start of an element tag.

  • name is the tag name.
  • attributes is an array of attribute name/value tuples.

The attributes array presents the attributes in the order they have been parsed. If an attribute is present twice with the same name, there will be two entries in the array.


[View source]
def text_decl(version : String, encoding : String | Nil) : Nil #

Called for text declarations in parsed external entities.

  • version defaults to "1.0".
  • encoding may be nil, in which case the parser assumes UTF-8 or the detected encoding.

[View source]
def xml_decl(version : String, encoding : String | Nil, standalone : Bool | Nil) : Nil #

Called for XML declarations.

  • version defaults to "1.0".
  • encoding may be nil, in which case the parser assumes UTF-8 or the detected encoding.
  • standalone will be nil when unspecified.

[View source]