XML::Pa...PerlSAX(3)
π NAME π
Bestie, welcome to XML::Pa...PerlSAX(3) from User Contributed Perl Documentation. This page is all about XML::Parser::PerlSAX β a Perl SAX parser using XML::Parser. π
β¨ SYNOPSIS β¨
use XML::Parser::PerlSAX;
$parser = XML::Parser::PerlSAX->new( [OPTIONS] );
$result = $parser->parse( [OPTIONS] );
$result = $parser->parse($string);
π¦ DESCRIPTION π¦
XML::Parser::PerlSAX is a PerlSAX parser using the XML::Parser module. This man page summarizes the specific options, handlers, and properties supported by XML::Parser::PerlSAX; please refer to the PerlSAX standard in "PerlSAX.pod" for general usage information. π
πΈ METHODS πΈ
new
Creates a new parser object. Default options for parsing, described below, are passed as key-value pairs or as a single hash. Options may be changed directly in the parser object unless stated otherwise. Options passed to parse() override the default options in the parser object for the duration of the parse. π οΈ
parse
Parses a document. Options, described below, are passed as key-value pairs or as a single hash. Options passed to parse() override default options in the parser object. π
location
Returns the location as a hash:
ColumnNumberβ tells you the column number of the parse. πLineNumberβ tells you the line number of the parse. π§΅BytePositionβ the current byte position of the parse. π’PublicIdβ a string containing the public identifier, orundefif none is available. π«₯SystemIdβ a string containing the system identifier, orundefif none is available. π«₯Baseβ the current value of the base for resolving relative URIs. π§
ALPHA WARNING: The"SystemId"and"PublicId"properties returned are the system and public identifiers of the document passed toparse(), not the identifiers of the currently parsing external entity. The column, line, and byte positions are of the current entity being parsed. π¨
π OPTIONS π
The following options are supported by XML::Parser::PerlSAX:
Handlerβ the default handler that receives events. π§DocumentHandlerβ handler that receives document events. πDTDHandlerβ handler that receives DTD events. πErrorHandlerβ handler that receives error events. π¨EntityResolverβ handler that resolves entities. π§©Localeβ locale to provide localisation for errors. πSourceβ hash containing the input source for parsing. π¦UseAttributeOrderβ set to true to provideAttributeOrderandDefaultedproperties instart_element(). π’
If no handlers are provided then all events will be silently ignored, except for fatal_error() which will cause a die() to be called after calling end_document(). π
If a single string argument is passed to the parse() method, it is treated as if a "Source" option was given with a "String" parameter. π§΅
The "Source" hash may contain the following parameters:
ByteStreamβ the raw byte stream (file handle) containing the document. π₯Stringβ a string containing the document. π§΅SystemIdβ the system identifier (URI) of the document. πPublicIdβ the public identifier. πͺͺEncodingβ a string describing the character encoding. π€
If more than one of "ByteStream", "String", or "SystemId", then preference is given first to "ByteStream", then "String", then "SystemId". π₯
π₯ HANDLERS π₯
The following handlers and properties are supported by XML::Parser::PerlSAX:
DocumentHandler methods
start_document
Ping! You get the notification that a document is beginning. π
No properties defined. π«Ά
end_document
Ping! You get the notification that a document is ending. π
No properties defined. π«Ά
start_element
Ping! You get the notification that an element is beginning. π§±
Nameβ the element type name. π·οΈAttributesβ a hash containing the attributes attached to the element, if any. π
The "Attributes" hash contains only string values. π€
If the "UseAttributeOrder" parser option is true, the following properties are also passed to "start_element":
AttributeOrderβ an array of attribute names in the order they were specified, followed by the defaulted attribute names. πDefaultedβ the index number of the first defaulted attribute inAttributeOrder. If this index is equal to the length ofAttributeOrder, there were no defaulted values. π’
Note to "XML::Parser" users: "Defaulted" will be half the value of "XML::Parser::Expat"'s specified_attr() function because only attribute names are provided, not their values. π§
end_element
Ping! You get the notification that an element is ending. π§±
Nameβ the element type name. π·οΈ
characters
Ping! You get the notification for character data. π‘
Dataβ the characters from the XML document. π
processing_instruction
Ping! You get the notification for a processing instruction. π§Ύ
Targetβ the processing instruction target. π―Dataβ the processing instruction data, if any. π
comment
Ping! You get the notification for a comment. π¬
Dataβ the comment data, if any. π
start_cdata
Ping! You get the notification that a CDATA section is starting. π’
No properties defined. π«Ά
end_cdata
Ping! You get the notification that a CDATA section is ending. π΄
No properties defined. π«Ά
entity_reference
Ping! You get the notification for an internal entity reference. If this handler is defined, internal entities will not be expanded and not passed to the characters() handler. If this handler is not defined, internal entities will be expanded if possible and passed to the characters() handler. π§©
Nameβ the entity reference name. π·οΈValueβ the entity reference value. π
DTDHandler methods
notation_decl
You get pinged for a notation declaration event. π
Nameβ the notation name. π·οΈPublicIdβ the notation's public identifier, if any. πͺͺSystemIdβ the notation's system identifier, if any. πBaseβ the base for resolving a relative URI, if any. π§
unparsed_entity_decl
You get pinged for an unparsed entity declaration event. π
Nameβ the unparsed entity's name. π·οΈSystemIdβ the entity's system identifier. πPublicIdβ the entity's public identifier, if any. πͺͺBaseβ the base for resolving a relative URI, if any. π§
entity_decl
You get pinged for an entity declaration event. π
Nameβ the entity name. π·οΈValueβ the entity value, if any. πPublicIdβ the notation's public identifier, if any. πͺͺSystemIdβ the notation's system identifier, if any. πNotationβ the notation declared for this entity, if any. π
For internal entities, the "Value" parameter will contain the value and the "PublicId", "SystemId", and "Notation" will be undefined. For external entities, the "Value" parameter will be undefined, the "SystemId" parameter will have the system id, the "PublicId" parameter will have the public id if it was provided (it will be undefined otherwise), the "Notation" parameter will contain the notation name for unparsed entities. If this is a parameter entity declaration, then a % will be prefixed to the entity name. π§
Note that entity_decl() and unparsed_entity_decl() overlap. If both methods are implemented by a handler, then this handler will not be called for unparsed entities. β οΈ
element_decl
You get pinged for an element declaration event. π
Nameβ the element type name. π·οΈModelβ the content model as a string. π§±
attlist_decl
You get pinged for an attribute list declaration event. π
This handler is called for each attribute in an ATTLIST declaration found in the internal subset. So an ATTLIST declaration that has multiple attributes will generate multiple calls to this handler. π
ElementNameβ the element type name. π·οΈAttributeNameβ the attribute name. πTypeβ the attribute type. π§¬Fixedβ true if this is a fixed attribute. π
The default for "Type" is the default value, which will either be "#REQUIRED", "#IMPLIED" or a quoted string (i.e. the returned string will begin and end with a quote character). π―
doctype_decl
You get pinged for a DOCTYPE declaration event. π
Nameβ the document type name. π·οΈSystemIdβ the document's system identifier. πPublicIdβ the document's public identifier, if any. πͺͺInternalβ the internal subset as a string, if any. π¦
Internal will contain all whitespace, comments, processing instructions, and declarations seen in the internal subset. The declarations will be there whether or not they have been processed by another handler (except for unparsed entities processed by the Unparsed handler). However, comments and processing instructions will not appear if they've been processed by their respective handlers. π§
xml_decl
You get pinged for an XML declaration event. π
Versionβ the version. π·οΈEncodingβ the encoding string, if any. π€Standaloneβ true, false, or undefined if not declared. ποΈ
EntityResolver
resolve_entity
Lets the handler resolve external entities. π§©
Nameβ the notation name. π·οΈSystemIdβ the notation's system identifier. πPublicIdβ the notation's public identifier, if any. πͺͺBaseβ the base for resolving a relative URI, if any. π§
resolve_entity() should return undef to request that the parser open a regular URI connection to the system identifier or a hash describing the new input source. This hash has the same properties as the "Source" parameter to parse():
PublicIdβ the public identifier of the external entity being referenced, orundefif none was supplied. πͺͺSystemIdβ the system identifier of the external entity being referenced. πStringβ String containing XML text. π§΅ByteStreamβ an open file handle. π₯CharacterStreamβ an open file handle. π₯Encodingβ the character encoding, if known. π€
π AUTHOR π
Ken MacLeod, ken@bitsko.slc.ut.us π
π SEE ALSO π
ok so if you wanna keep going down the rabbit hole (and honestly? you should, bestie, this is the lore), go check these out:
perl(1)β the mothership herself, the blueprint, the original main character πPerlSAX.pod(3)β the parent doc, the one who raised this whole API family tree π«Ά
and then the external stuff, which is giving "required reading for the syllabus":
- Extensible Markup Language (XML) <http://www.w3c.org/XML/> β the W3C's official XML page, the source of truth, no cap β¨
- SAX 1.0: The Simple API for XML <http://www.megginson.com/SAX/> β the OG SAX spec, the blueprint for everything this module is doing, iconic behavior fr fr π
ngl, the URLs are written out here exactly as they appear in the original doc, angle brackets and all β that's just how they're listed, so don't come for me π
π POD ERRORS π
ok bestie this is the part where the docs themselves get a vibe check and, uh... they did not pass π
Straight from the pod parser, verbatim energy: Hey! The above document had some coding errors, which are explained below:
- Around line
528:- You forgot a
'=back'before'=head1'
- You forgot a
so yeah β somewhere around line 528 the POD formatting is missing its closing =back before the next =head1 heading. Not a code bug in the module itself, just a formatting oopsie in the documentation, but the parser is not letting it slide π it's giving "teacher who circles your mistake in red pen" energy.
fr fr, this is a genuine documented error in the original page β I'm not being dramatic, it's literally listed under POD ERRORS π
πΈ and that's a wrap, bestie!! πΈ
this lil slice of documentation magic was brought to you by perl v5.42.0, dated 2024-03-04 β so yes, she's from March 2024, she's a real one, and she's still serving β¨ go forth, parse some XML, and remember: the options are exact, the handlers are real, and the pod errors are, unfortunately, also real ππ periodt π«Ά
π¦ where this page comes from
- opensuse-leap 16.0: perl-libxml-perl 0.08-160000.2.2 Β· Artistic-1.0 OR GPL-2.0-or-later
- opensuse-leap 16.0: perl-libxml-perl 0.08-160000.2.2 Β· Artistic-1.0 OR GPL-2.0-or-later
- opensuse-leap 16.0: perl-libxml-perl 0.08-160000.2.2 Β· Artistic-1.0 OR GPL-2.0-or-later
- opensuse-leap 16.0: perl-libxml-perl 0.08-160000.2.2 Β· Artistic-1.0 OR GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms