{
    "mode": "perldoc",
    "parameter": "XML::Handler::XMLWriter",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/XML%3A%3AHandler%3A%3AXMLWriter/json",
    "generated": "2026-06-11T14:51:12Z",
    "synopsis": "use XML::Parser::PerlSAX;\nuse XML::Handler::XMLWriter;\n$myhandler = XML::Handler::XMLWriter->new( I<OPTIONS> );\nXML::Parser::PerlSAX->new->parse(Source => { SystemId => 'REC-xml-19980210.xml' },\nHandler => $myhandler);",
    "sections": {
        "NAME": {
            "content": "XML::Handler::XMLWriter - a PerlSAX handler for writing readable XML\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use XML::Parser::PerlSAX;\nuse XML::Handler::XMLWriter;\n\n$myhandler = XML::Handler::XMLWriter->new( I<OPTIONS> );\n\nXML::Parser::PerlSAX->new->parse(Source => { SystemId => 'REC-xml-19980210.xml' },\nHandler => $myhandler);\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "\"XML::Handler::XMLWriter\" is a PerlSAX handler for writing readable XML (in contrast to\nCanonical XML, for example). XML::Handler::XMLWriter can be used with a parser to reformat XML,\nwith XML::DOM or XML::Grove to write out XML, or with other PerlSAX modules that generate\nevents.\n\n\"XML::Handler::XMLWriter\" is intended to be used with PerlSAX event generators and does not\nperform any checking itself (for example, matching start and end element events). If you want to\ngenerate XML directly from your Perl code, use the XML::Writer module. XML::Writer has an easy\nto use interface and performs many checks to make sure that the XML you generate is well-formed.\n\n\"XML::Handler::XMLWriter\" is a subclass of \"XML::Handler::Subs\". \"XML::Handler::XMLWriter\" can\nbe further subclassed to alter it's behavior or to add element-specific handling. In the\nsubclass, each time an element starts, a method by that name prefixed with `s' is called with\nthe element to be processed. Each time an element ends, a method with that name prefixed with\n`e' is called. Any special characters in the element name are replaced by underscores. If there\nisn't a start or end method for an element, the default action is to write the start or end tag.\nStart and end methods can use the `\"printstartelement()\"' and `\"printendelement()\"' methods\nto print start or end tags. Subclasses can call the `\"print()\"' method to write additional\noutput.\n\nSubclassing XML::Handler::XMLWriter in this way is similar to XML::Parser's Stream style.\n\nXML::Handler::Subs maintains a stack of element names, `\"$self-\"{Names}', and a stack of element\nnodes, `\"$self-\"{Nodes}>' that can be used by subclasses. The current element is pushed on the\nstacks before calling an element-name start method and popped off the stacks after calling the\nelement-name end method.\n\nSee XML::Handler::Subs for additional methods.\n\nIn addition to the standard PerlSAX handler methods (see PerlSAX for descriptions),\nXML::Handler::XMLWriter supports the following methods:\n",
            "subsections": [
                {
                    "name": "new",
                    "content": "Creates and returns a new instance of XML::Handler::XMLWriter with the given *OPTIONS*.\nOptions may be changed at any time by modifying them directly in the hash returned.\n*OPTIONS* can be a list of key, value pairs or a hash. The following *OPTIONS* are\nsupported:\n\nOutput\nAn IO::Handle or one of it's subclasses (such as IO::File), if this parameter is not\npresent and the AsString option is not used, the module will write to standard output.\n\nAsString\nReturn the generated XML as a string from the `\"parse()\"' method of the PerlSAX event\ngenerator.\n\nNewlines\nA true or false value; if this parameter is present and its value is true, then the\nmodule will insert an extra newline before the closing delimiter of start, end, and\nempty tags to guarantee that the document does not end up as a single, long line. If the\nparameter is not present, the module will not insert the newlines.\n\nIsSGML\nA true or false value; if this parameter is present and its value is true, then the\nmodule will generate SGML rather than XML.\n"
                },
                {
                    "name": "print_start_element",
                    "content": "Print a start tag for `$element'. This is the default action for the PerlSAX\n`\"startelement()\"' handler, but subclasses may use this if they define a start method for\nan element.\n"
                },
                {
                    "name": "print_end_element",
                    "content": "Prints an end tag for `$element'. This is the default action for the PerlSAX\n`\"endelement()\"' handler, but subclasses may use this if they define a start method for an\nelement.\n\nprint($output)\nWrite `$output' to Output and/or append it to the string to be returned. Subclasses may use\nthis to write additional output.\n"
                }
            ]
        },
        "TODO": {
            "content": "*   An Elements option that provides finer control over newlines than the Newlines option, where\nyou can choose before and after newline for element start and end tags. Inspired by the\nPython XMLWriter.\n\n*   Support Doctype and XML declarations.\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "Ken MacLeod, ken@bitsko.slc.ut.us This module is partially derived from XML::Writer by David\nMegginson.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "",
            "subsections": [
                {
                    "name": "perl",
                    "content": ""
                }
            ]
        }
    },
    "summary": "XML::Handler::XMLWriter - a PerlSAX handler for writing readable XML",
    "flags": [],
    "examples": [],
    "see_also": []
}