class

KXML::Parser

Inherits Reference < Object

Strict, pure-Crystal XML 1.0 (Fifth Edition) parser.

Implemented directly from W3C REC-xml-20081126 (well-formedness only, no DTD validation). Raises KXML::Error on any well-formedness violation, mirroring lxml's non-recovering behavior.

Constants

MAX_ELEMENT_DEPTH = 2048

Element nesting is recursive (parse_element <-> parse_content), so the limit must stay low enough that the guard raises KXML::Error before the call stack overflows. Stack overflow testing shows nesting dies around depth ~6,000 on an 8 MB stack; 2,048 (libxml2's XML_MAX_DEPTH) leaves a wide safety margin across platforms.

MAX_ENTITY_DEPTH = 64
MAX_EXPANDED_BYTES = 10000000
PREDEFINED_ENTITIES = {"lt" => "&#60;", "gt" => "&#62;", "amp" => "&#38;", "apos" => "&#39;", "quot" => "&#34;"}

Predefined entities (4.6). Stored as their spec-required replacement texts: char references to the respective character (double escaping REQUIRED for lt/amp so references re-expand to data, never markup).

Constructors

new(source : String)
Source

Class methods

normalize_eol(source : String) : String

2.11: #xD#xA and any lone #xD become #xA on input, before parsing. Single pass; the gsub pair this replaces allocated two intermediates.

Source
parse(source : String) : Document
Source
valid_codepoint?(cp : Int32) : Bool
Source

Instance methods

normalize_att_value(raw : String, type : String) : String
Source
parse
Source