Composer(3pm)
π Composer(3pm) π
okay bestie, gather round, because we're about to talk about Composer β part of the User Contributed Perl Documentation crew, and it's literally the XML printer/writer/generator. yes, that's the whole vibe. π
β¨ NAME β¨
XML::Handler::Composer β Another XML printer/writer/generator. another one. π
πΈ SYNOPSIS πΈ
use XML::Handler::Composer;
my $composer = new XML::Handler::Composer ( [OPTIONS] );
that's it. that's the whole entrance. main character energy fr fr. π
π¦ DESCRIPTION π¦
so XML::Handler::Composer is lowkey cousins with XML::Writer, XML::Handler::XMLWriter, XML::Handler::YAWriter etc. β they all generate XML output. same family, different vibe. π
ngl, this implementation may not be fast and it may not be the best solution for your particular problem, but bestie it has features that the other ones might be missing:
- Supports every output encoding that XML::UM supports π
XML::UMsupports every encoding for which there is a mapping file in theXML::Encodingdistribution. no cap.
- Pretty printing β¨
- When used with
XML::Filter::Reindent.
- When used with
- Fine control over which kind of quotes are used π
- See options below. iykyk.
π Constructor Options π
EndWithNewline(Default:1) β Whether to print a newline at the end of the file (i.e. after the root element). yeah, we close with a little flourish. π«Newline(Default:undef) β If defined, which newline to use for printing. (Note thatXML::Parseretc. convert newlines into"\x0A".)
If undef, newlines will not be converted and XML::Handler::Composer will use "\x0A" when printing.
A value of "\n" will convert the internal newlines into the platform specific line separator.
See the PreserveWS option in the characters event (below) for finer control over when newline conversion is active. π«Ά
DocTypeIndent(Default: a Newline and 2 spaces) β Newline plus indent that is used to separate lines inside the DTD.IndentAttList(Default: 8 spaces) β Indent used when printing an<!ATTLIST>declaration that has more than one attribute definition, e.g.
<!ATTLIST my_elem
attr1 CDATA "foo"
attr2 CDATA "bar"
>
Quote(Default:{ XMLDecl => '"', Attr => '"', Entity => '"', SystemLiteral => '"' }) βQuotecontains a reference to a hash that defines which quoting characters to use when printing XML declarations (XMLDecl), attribute values (Attr),<!ENTITY>values (Entity) and system/public literals (SystemLiteral) as found in<!DOCTYPE>,<!ENTITY>declarations etc. so many quotes, so little time. πΈPrintDefaultAttr(Default:0) β If1, prints attribute values regardless of whether they are default attribute values (as defined in<!ATTLIST>declarations.) Normally, default attributes are not printed.Encoding(Default:undef) β Defines the output encoding (if specified.) Note that future calls to thexml_decl()handler may override this setting (if they contain anEncodingdefinition.) sneaky little override, we love her. πEncodeUnmapped(Default:\&XML::UM::encode_unmapped_dec) β Defines how Unicode characters not found in the mapping file (of the specified encoding) are printed. By default, they are converted to decimal entity references, like'{'
Use \&XML::UM::encode_unmapped_hex for hexadecimal constants, like '«' β¨
Print(Default:sub { print @_ }, which prints to stdout) β The subroutine that is used to print the encoded XML output. The default prints the string to stdout.
π
Method: get_compressed_element_suffix ($event) π
Override this method to support the different styles for printing empty elements in compressed notation, e.g. <p/>, <p></p>, <p />, <p>.
The default returns "/>", which results in <p/>. Use " />" for XHTML style elements or ">" for certain HTML style elements.
The $event parameter is the hash reference that was received from the start_element() handler. π
π Extra PerlSAX event information π
XML::Handler::Composer relies on hints from previous SAX filters to format certain parts of the XML. These SAX filters (e.g. XML::Filter::Reindent) pass extra information by adding name/value pairs to the appropriate PerlSAX events (the events themselves are hash references.) π¦
entity_reference:Parameter => 1β IfParameteris1, it means that it is a parameter entity reference. A parameter entity is referenced with%ent;instead of&ent;and the entity declaration starts with<!ENTITY % ent ...>instead of<!ENTITY ent ...>
NOTE: This should be added to the PerlSAX interface! π
start_element/end_element:Compress => 1β IfCompressis1in both thestart_elementandend_elementevent, the element will be printed in compressed form, e.g.<a/>instead of<a></a>.start_element:PreserveWS => 1β If newline conversion is active (i.e.Newlinewas defined in the constructor), then newlines will NOT be converted in text (character events) within this element. protect the whitespace bestie, it's sacred π«Άattlist_decl:First,MoreFollowβ TheFirstandMoreFollowoptions can be used to force successive<!ATTLIST>declarations for the same element to be merged, e.g.
<!ATTLIST my_elem
attr1 CDATA "foo"
attr2 CDATA "bar"
attr3 CDATA "quux"
>
In this example, the attlist_decl event for foo should contain (First => 1, MoreFollow => 1) and the event for bar should contain (MoreFollow => 1). The quux event should have no extra info.
'First' indicates that the event is the first of a sequence. 'MoreFollow' indicates that more events will follow in this sequence.
If neither option is set by the preceding PerlSAX filter, each attribute definition will be printed as a separate <!ATTLIST> line. πΈ
β οΈ CAVEATS β οΈ
This code is highly experimental! It has not been tested well and the API may change. π proceed with the caution of someone texting their ex at 2am, bestie.
π AUTHOR π
Enno Derksen is the original author. π
Send bug reports, hints, tips, suggestions to T.J. Mather at <tjmather@tjmather.com>. π«Ά (yes, actually email them, they want to hear from you)
and that's the whole page, bestie! β¨
this was Composer(3pm) from perl v5.34.0, dated 2022-06-28 β mwah, iconic, no notes. π
ππΈ
π¦ where this page comes from
- debian bookworm: libxml-handler-composer-perl 0.01-10 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libxml-handler-composer-perl 0.01-10 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libxml-handler-composer-perl 0.01-10 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libxml-handler-composer-perl 0.01-10 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libxml-handler-composer-perl 0.01-10 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms