{
    "mode": "perldoc",
    "parameter": "XML::SAX",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/XML%3A%3ASAX/json",
    "generated": "2026-06-09T20:35:44Z",
    "synopsis": "use XML::SAX;\n# get a list of known parsers\nmy $parsers = XML::SAX->parsers();\n# add/update a parser\nXML::SAX->addparser(q(XML::SAX::PurePerl));\n# remove parser\nXML::SAX->removeparser(q(XML::SAX::Foodelberry));\n# save parsers\nXML::SAX->saveparsers();",
    "sections": {
        "NAME": {
            "content": "XML::SAX - Simple API for XML\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use XML::SAX;\n\n# get a list of known parsers\nmy $parsers = XML::SAX->parsers();\n\n# add/update a parser\nXML::SAX->addparser(q(XML::SAX::PurePerl));\n\n# remove parser\nXML::SAX->removeparser(q(XML::SAX::Foodelberry));\n\n# save parsers\nXML::SAX->saveparsers();\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "XML::SAX is a SAX parser access API for Perl. It includes classes and APIs required for\nimplementing SAX drivers, along with a factory class for returning any SAX parser installed on\nthe user's system.\n",
            "subsections": []
        },
        "USING A SAX2 PARSER": {
            "content": "The factory class is XML::SAX::ParserFactory. Please see the documentation of that module for\nhow to instantiate a SAX parser: XML::SAX::ParserFactory. However if you don't want to load up\nanother manual page, here's a short synopsis:\n\nuse XML::SAX::ParserFactory;\nuse XML::SAX::XYZHandler;\nmy $handler = XML::SAX::XYZHandler->new();\nmy $p = XML::SAX::ParserFactory->parser(Handler => $handler);\n$p->parseuri(\"foo.xml\");\n# or $p->parsestring(\"<foo/>\") or $p->parsefile($fh);\n\nThis will automatically load a SAX2 parser (defaulting to XML::SAX::PurePerl if no others are\nfound) and return it to you.\n\nIn order to learn how to use SAX to parse XML, you will need to read XML::SAX::Intro and for\nreference, XML::SAX::Specification.\n",
            "subsections": []
        },
        "WRITING A SAX2 PARSER": {
            "content": "The first thing to remember in writing a SAX2 parser is to subclass XML::SAX::Base. This will\nmake your life infinitely easier, by providing a number of methods automagically for you. See\nXML::SAX::Base for more details.\n\nWhen writing a SAX2 parser that is compatible with XML::SAX, you need to inform XML::SAX of the\npresence of that driver when you install it. In order to do that, XML::SAX contains methods for\nsaving the fact that the parser exists on your system to a \"INI\" file, which is then loaded to\ndetermine which parsers are installed.\n\nThe best way to do this is to follow these rules:\n\n*   Add XML::SAX as a prerequisite in Makefile.PL:\n\nWriteMakefile(\n...\nPREREQPM => { 'XML::SAX' => 0 },\n...\n);\n\nAlternatively you may wish to check for it in other ways that will cause more than just a\nwarning.\n\n*   Add the following code snippet to your Makefile.PL:\n\nsub MY::install {\npackage MY;\nmy $script = shift->SUPER::install(@);\nif (ExtUtils::MakeMaker::prompt(\n\"Do you want to modify ParserDetails.ini?\", 'Y')\n=~ /^y/i) {\n$script =~ s/install :: (.*)$/install :: $1 installsaxdriver/m;\n$script .= <<\"INSTALL\";\n\ninstallsaxdriver :\n\\t\\@\\$(PERL) -MXML::SAX -e \"XML::SAX->addparser(q(\\$(NAME)))->saveparsers()\"\n\nINSTALL\n}\nreturn $script;\n}\n\nNote that you should check the output of this - \\$(NAME) will use the name of your\ndistribution, which may not be exactly what you want. For example XML::LibXML has a driver\ncalled XML::LibXML::SAX::Generator, which is used in place of \\$(NAME) in the above.\n\n*   Add an XML::SAX test:\n\nA test file should be added to your t/ directory containing something like the following:\n\nuse Test;\nBEGIN { plan tests => 3 }\nuse XML::SAX;\nuse XML::SAX::PurePerl::DebugHandler;\nXML::SAX->addparser(q(XML::SAX::MyDriver));\nlocal $XML::SAX::ParserPackage = 'XML::SAX::MyDriver';\neval {\nmy $handler = XML::SAX::PurePerl::DebugHandler->new();\nok($handler);\nmy $parser = XML::SAX::ParserFactory->parser(Handler => $handler);\nok($parser);\nok($parser->isa('XML::SAX::MyDriver');\n$parser->parsestring(\"<tag/>\");\nok($handler->{seen}{startelement});\n};\n",
            "subsections": []
        },
        "EXPORTS": {
            "content": "By default, XML::SAX exports nothing into the caller's namespace. However you can request the\nsymbols \"Namespaces\" and \"Validation\" which are the URIs for those features, allowing an easier\nway to request those features via ParserFactory:\n\nuse XML::SAX qw(Namespaces Validation);\nmy $factory = XML::SAX::ParserFactory->new();\n$factory->requirefeature(Namespaces);\n$factory->requirefeature(Validation);\nmy $parser = $factory->parser();\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "Current maintainer: Grant McLean, grantm@cpan.org\n\nOriginally written by:\n\nMatt Sergeant, matt@sergeant.org\n\nKip Hampton, khampton@totalcinema.com\n\nRobin Berjon, robin@knowscape.com\n",
            "subsections": []
        },
        "LICENSE": {
            "content": "This is free software, you may use it and distribute it under the same terms as Perl itself.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "XML::SAX::Base for writing SAX Filters and Parsers\n\nXML::SAX::PurePerl for an XML parser written in 100% pure perl.\n\nXML::SAX::Exception for details on exception handling\n",
            "subsections": []
        }
    },
    "summary": "XML::SAX - Simple API for XML",
    "flags": [],
    "examples": [],
    "see_also": []
}