# XML::Parser::Expat
๐Ÿ“ฆ max
`XML::Parser::Expat` - the low-level interface of `XML::Parser`. ```perl use XML::Parser; my $p = XML::Parser->new(Handlers => { Start => sub { my ($expat, $elem, %attr) = @_; print "<$elem>\n" }, Char => sub { my ($expat, $text) = @_; print $text }, }); $p->parse('hello'); ``` Most programs use `XML::Parser` (or a module built on it such as `XML::Twig`, `XML::Simple` or `XML::Dumper`) and never call this module directly. It parses with pperlโ€™s XML engine over libxml2, the one XML::LibXML uses too; libxml2 2.15 or newer is required, and the module fails to load with a message saying so when it is older or missing. This is a native implementation of the CPAN distribution XML-Parser 2.59, which parses with the expat library; its `XML/Parser.pm`, `XML/Parser/Expat.pm` and the `XML::Parser::Style::*` modules are used unchanged. Every handler sees what it sees under expat: the same calls with the same arguments, character data split where expat splits it, and the same text, positions and lengths from `recognized_string`, `original_string`, `current_byte`, `current_line`, `current_column` and `current_length`. Errors carry expatโ€™s messages and positions. ## ื”ื‘ื“ืœื™ื ืžึพupstream `expat_version` reports the expat release whose interface this module provides, `expat_2.6.0`, since no expat is loaded. A document with `standalone="yes"` has the parameter entities of its internal subset expanded, as XML 1.0 requires; expat leaves them unread, and then refuses an entity reference they declare as undefined. ## ืคื•ื ืงืฆื™ื•ืช ### ืคื•ื ืงืฆื™ื•ืช ืื—ืจื•ืช #### `ParserCreate` `ParserCreate($self, $encoding, $namespaces)`: a new parser for the XML::Parser::Expat object $self, as an integer handle. #### `ParserRelease` `ParserRelease($parser)`: ื”ืฉืžื˜ืช ื”ื”ืคื ื™ื” ืฉืœ ื”ืžื ืชื— ืœืขืฆื ืฉืœื•, ืชื•ืš ืฉื‘ื™ืจืช ื”ืžืขื’ืœ ื›ื“ื™ ืฉืืคืฉืจ ื™ื”ื™ื” ืœืฉื—ืจืจ ืืช ื”ืขืฆื. #### `ParserFree` `ParserFree($parser)`: ืฉื—ืจื•ืจ ื”ืžื ืชื— ื•ื›ืœ ืžื˜ืคืœ ืฉื”ื•ื ืžื—ื–ื™ืง. #### `ParseString` `ParseString($parser, $string)`: ื ื™ืชื•ื— ืžืกืžืš ืฉืœื. #### `ParseStream` `ParseStream($parser, $handle, $delim)`: ื ื™ืชื•ื— ืžืžื˜ืคืœ, ืขื“ ืฉื•ืจื” ื”ืžื›ื™ืœื” ืจืง ืืช `$delim` ื›ืืฉืจ ื”ื•ื ืžื•ื’ื“ืจ. #### `ParsePartial` `ParsePartial($parser, $chunk)`: ื ื™ืชื•ื— ื ืชื— ื ื•ืกืฃ ืฉืœ ืžืกืžืš. #### `ParseDone` `ParseDone($parser)`: ืกื™ื•ื ืžืกืžืš ืฉื ื•ืชื— ื‘ืืžืฆืขื•ืช ParsePartial. #### `UnsetAllHandlers` `UnsetAllHandlers($parser)`: expatโ€™s handlers go, the element ones and the namespace ones included; what is left is the Default handler. #### `SetBase` `SetBase($parser, $base)`. #### `GetBase` `GetBase($parser)`: ื”ื‘ืกื™ืก, ืื• undef. #### `PositionContext` `PositionContext($parser, $lines)`: ื”ืงืœื˜ ืฉืกื‘ื™ื‘ ื”ืžื™ืงื•ื ื”ื ื•ื›ื—ื™, `$lines` ืฉื•ืจื•ืช ืžื›ืœ ืฆื“, ื•ื”ื”ื™ืกื˜ ืฉืœ ื”ืžื™ืงื•ื ื‘ืชื•ื›ื•. #### `GenerateNSName` `GenerateNSName($name, $namespace, \%table, \@list)`: ืขืฆื ื”ืฉื ืขื‘ื•ืจ `$name` ื‘ึพ`$namespace`, ื›ืคื™ ืฉื”ืžื ืชื— ื™ื•ืฆืจ ืื•ืชื. #### `DefaultCurrent` `DefaultCurrent($parser)`: ื”ืขื‘ืจืช ื”ื˜ืงืกื˜ ืฉืœ ื”ืื™ืจื•ืข ื”ื ื•ื›ื—ื™ ืœืžื˜ืคืœ ื”ึพDefault. #### `RecognizedString` `RecognizedString($parser)`: ื”ื˜ืงืกื˜ ืฉืœ ื”ืื™ืจื•ืข ื”ื ื•ื›ื—ื™. #### `GetErrorCode` `GetErrorCode($parser)`. #### `GetCurrentLineNumber` `GetCurrentLineNumber($parser)`. #### `GetCurrentColumnNumber` `GetCurrentColumnNumber($parser)`. #### `GetCurrentByteIndex` `GetCurrentByteIndex($parser)`. #### `GetCurrentByteCount` `GetCurrentByteCount($parser)`. #### `GetSpecifiedAttributeCount` `GetSpecifiedAttributeCount($parser)`. #### `ErrorString` `ErrorString($code)`: ื”ื”ื•ื“ืขื” ืขื‘ื•ืจ ืงื•ื“ ืฉื’ื™ืื”. #### `ExpatVersion` `ExpatVersion()`: โ€expat_X.Y.Zโ€œ, the interface this module provides. #### `ExpatVersionInfo` `ExpatVersionInfo()`: `(major => X, minor => Y, micro => Z)`. #### `LoadEncoding` `LoadEncoding($data, $size)`: ืจื™ืฉื•ื ืžืคืช ืงื™ื“ื•ื“ ื‘ื™ื ืืจื™ืช (ื”ืชื•ื›ืŸ ืฉืœ ืงื•ื‘ืฅ .enc) ื‘ึพ%Encoding_Table; ืžื—ื–ื™ืจื” ืืช ืฉืžื”, ืื• undef ื›ืืฉืจ ื”ื ืชื•ื ื™ื ืื™ื ื ืžืคื”. #### `FreeEncoding` `FreeEncoding($encinfo)`: ืฉื—ืจื•ืจ ืžืคื” ืฉึพLoadEncoding ื™ืฆืจื”. #### `OriginalString` `OriginalString($parser)`: ื˜ืงืกื˜ ื”ืงืœื˜ ืฉืœ ื”ืื™ืจื•ืข ื”ื ื•ื›ื—ื™. #### `ElementIndex` `ElementIndex($parser)`: ื”ืžืกืคืจ ื”ืกื™ื“ื•ืจื™ ืฉืœ ื”ืืœืžื ื˜ ื”ื ื•ื›ื—ื™. #### `SkipUntil` `SkipUntil($parser, $index)`: ื”ืฉืขื™ื™ืช ืจื•ื‘ ื”ืžื˜ืคืœื™ื ืขื“ ืฉื”ืืœืžื ื˜ ื‘ืขืœ ื”ืžืกืคืจ ื”ืกื™ื“ื•ืจื™ `$index` ืžืชื—ื™ืœ. #### `Do_External_Parse` `Do_External_Parse($parser, $result)`: the ExternEnt handlerโ€™s result is read by the loader that called the handler, so outside one there is nothing to parse into. #### `SetReparseDeferralEnabled` `SetReparseDeferralEnabled($parser, $enabled)`: expatโ€™s deferral of reparsing a token split across buffers (`parse_buffer`); XML_TRUE.