XML::Parser::Expat#

📦 max

XML::Parser::Expat - the low-level interface of XML::Parser.

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('<doc><item id="1">hello</item></doc>');

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): αναλύει από ένα handle, μέχρι μια γραμμή που περιέχει μόνο το $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.