XML::Ha...MLWriter(3)
π NAME π
okay bestie, this is the manual page for XML::Handler::XMLWriter(3) β the header got chopped to XML::Ha...MLWriter(3) because terminal columns are haters, but we know her. From the User Contributed Perl Documentation crew: XML::Handler::XMLWriter is a PerlSAX handler for writing readable XML. periodt. π
β¨ SYNOPSIS β¨
use XML::Parser::PerlSAX;
use XML::Handler::XMLWriter;
$my_handler = XML::Handler::XMLWriter->new( I<OPTIONS> );
XML::Parser::PerlSAX->new->parse(Source => { SystemId => 'REC-xml-19980210.xml' },
Handler => $my_handler);
that I<OPTIONS> is literally where the options go, bestie. no cap. π
πΈ DESCRIPTION πΈ
XML::Handler::XMLWriter is a PerlSAX handler for writing readable XML β like, the opposite vibe of Canonical XML, for example. It can be used with a parser to reformat XML, with XML::DOM or XML::Grove to write out XML, or with other PerlSAX modules that generate events. it's giving versatility. β¨
vibe check: XML::Handler::XMLWriter is intended to be used with PerlSAX event generators and does not perform any checking itself (for example, matching start and end element events). π If you want to generate XML directly from your Perl code, use the XML::Writer module instead. XML::Writer has an easy to use interface and performs many checks to make sure that the XML you generate is well-formed. that's the responsible bestie.
XML::Handler::XMLWriter is a subclass of XML::Handler::Subs. XML::Handler::XMLWriter can be further subclassed to alter its behavior or to add element-specific handling. In the subclass, each time an element starts, a method by that name prefixed with s_ is called with the element to be processed. Each time an element ends, a method with that name prefixed with e_ is called. Any special characters in the element name are replaced by underscores. If there isn't a start or end method for an element, the default action is to write the start or end tag. Start and end methods can use the print_start_element() and print_end_element() methods to print start or end tags. Subclasses can call the print() method to write additional output. iconic behavior, honestly.
Subclassing XML::Handler::XMLWriter in this way is similar to XML::Parser's Stream style.
XML::Handler::Subs maintains a stack of element names, "$self-"{Names}', and a stack of element nodes, "$self-"{Nodes}>', that can be used by subclasses. The current element is pushed on the stacks before calling an element-name start method and popped off the stacks after calling the element-name end method.
See XML::Handler::Subs for additional methods. π«Ά
In addition to the standard PerlSAX handler methods (see PerlSAX for descriptions), XML::Handler::XMLWriter supports the following methods:
new( OPTIONS )β Creates and returns a new instance ofXML::Handler::XMLWriterwith the given OPTIONS. Options may be changed at any time by modifying them directly in the hash returned. OPTIONS can be a list of key, value pairs or a hash. The following OPTIONS are supported:Outputβ AnIO::Handleor one of it's subclasses (such asIO::File). If this parameter is not present and theAsStringoption is not used, the module will write to standard output.AsStringβ Return the generated XML as a string from theparse()method of the PerlSAX event generator.Newlinesβ A true or false value. If this parameter is present and its value is true, then the module will insert an extra newline before the closing delimiter of start, end, and empty tags to guarantee that the document does not end up as a single, long line. If the paramter is not present, the module will not insert the newlines. (typo not mine, I'm just reading the page π)IsSGMLβ A true or false value. If this parameter is present and its value is true, then the module will generate SGML rather than XML.
print_start_element($element)β Print a start tag for$element. This is the default action for the PerlSAXstart_element()handler, but subclasses may use this if they define a start method for an element.print_end_element($element)β Prints an end tag for$element. This is the default action for the PerlSAXend_element()handler, but subclasses may use this if they define a start method for an element. (yes, it says start method here, we're not gonna fight the manpage)print($output)β Write$outputtoOutputand/or append it to the string to be returned. Subclasses may use this to write additional output.
π TODO π
- An
Elementsoption that provides finer control over newlines than theNewlinesoption, where you can choose before and after newline for element start and end tags. Inspired by the PythonXMLWriter. - Support
Doctypeand XML declarations.
π AUTHOR π
Ken MacLeod, ken@bitsko.slc.ut.us. This module is partially derived from XML::Writer by David Megginson. king behavior. π
π¦ SEE ALSO π¦
peep perl(1) and PerlSAX.pod(3) β iykyk. π¦
okay that's the whole page, bestie! this one comes to you from perl v5.42.0, dated 2024-03-04 β mwah πβ¨
π¦ 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