{"id":6731,"date":"2022-12-20T19:33:32","date_gmt":"2022-12-20T22:33:32","guid":{"rendered":"http:\/\/lode.uno\/linux-man\/index.php\/2022\/12\/20\/xmlsax-man3\/"},"modified":"2022-12-20T19:33:32","modified_gmt":"2022-12-20T22:33:32","slug":"xmlsax-man3","status":"publish","type":"post","link":"https:\/\/lode.uno\/linux-man\/2022\/12\/20\/xmlsax-man3\/","title":{"rendered":"XML::SAX (man3)"},"content":{"rendered":"<h1 align=\"center\">XML::SAX<\/h1>\n<p> <a href=\"#NAME\">NAME<\/a><br \/> <a href=\"#SYNOPSIS\">SYNOPSIS<\/a><br \/> <a href=\"#DESCRIPTION\">DESCRIPTION<\/a><br \/> <a href=\"#USING A SAX2 PARSER\">USING A SAX2 PARSER<\/a><br \/> <a href=\"#WRITING A SAX2 PARSER\">WRITING A SAX2 PARSER<\/a><br \/> <a href=\"#EXPORTS\">EXPORTS<\/a><br \/> <a href=\"#AUTHOR\">AUTHOR<\/a><br \/> <a href=\"#LICENSE\">LICENSE<\/a><br \/> <a href=\"#SEE ALSO\">SEE ALSO<\/a> <\/p>\n<hr>\n<h2>NAME <a name=\"NAME\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">XML::SAX \u2212 Simple API for XML<\/p>\n<h2>SYNOPSIS <a name=\"SYNOPSIS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">use XML::SAX; <br \/> # get a list of known parsers <br \/> my $parsers = XML::SAX\u2212>parsers(); <br \/> # add\/update a parser <br \/> XML::SAX\u2212>add_parser(q(XML::SAX::PurePerl)); <br \/> # remove parser <br \/> XML::SAX\u2212>remove_parser(q(XML::SAX::Foodelberry)); <br \/> # save parsers <br \/> XML::SAX\u2212>save_parsers();<\/p>\n<h2>DESCRIPTION <a name=\"DESCRIPTION\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><small>XML::SAX<\/small> is a <small>SAX<\/small> parser access <small>API<\/small> for Perl. It includes classes and APIs required for implementing <small>SAX<\/small> drivers, along with a factory class for returning any <small>SAX<\/small> parser installed on the user\u2019s system.<\/p>\n<h2>USING A SAX2 PARSER <a name=\"USING A SAX2 PARSER\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The factory class is XML::SAX::ParserFactory. Please see the documentation of that module for how to instantiate a <small>SAX<\/small> parser: XML::SAX::ParserFactory. However if you don\u2019t want to load up another manual page, here\u2019s a short synopsis:<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">use XML::SAX::ParserFactory; <br \/> use XML::SAX::XYZHandler; <br \/> my $handler = XML::SAX::XYZHandler\u2212>new(); <br \/> my $p = XML::SAX::ParserFactory\u2212>parser(Handler => $handler); <br \/> $p\u2212>parse_uri(&#8220;foo.xml&#8221;); <br \/> # or $p\u2212>parse_string(&#8220;<foo\/>&#8220;) or $p\u2212>parse_file($fh);<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">This will automatically load a <small>SAX2<\/small> parser (defaulting to XML::SAX::PurePerl if no others are found) and return it to you.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">In order to learn how to use <small>SAX<\/small> to parse <small>XML,<\/small> you will need to read XML::SAX::Intro and for reference, XML::SAX::Specification.<\/p>\n<h2>WRITING A SAX2 PARSER <a name=\"WRITING A SAX2 PARSER\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The first thing to remember in writing a <small>SAX2<\/small> parser is to subclass XML::SAX::Base. This will make your life infinitely easier, by providing a number of methods automagically for you. See XML::SAX::Base for more details.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">When writing a <small>SAX2<\/small> parser that is compatible with <small>XML::SAX,<\/small> you need to inform <small>XML::SAX<\/small> of the presence of that driver when you install it. In order to do that, <small>XML::SAX<\/small> contains methods for saving the fact that the parser exists on your system to a &#8221; <small>INI&#8221;<\/small> file, which is then loaded to determine which parsers are installed.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The best way to do this is to follow these rules:<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"1%\">\n<p>\u2022<\/p>\n<\/td>\n<td width=\"5%\"><\/td>\n<td width=\"71%\">\n<p>Add <small>XML::SAX<\/small> as a prerequisite in Makefile.PL:<\/p>\n<\/td>\n<td width=\"12%\"> <\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:17%; margin-top: 1em\">WriteMakefile( <br \/> &#8230; <br \/> PREREQ_PM => { &#8216;XML::SAX&#8217; => 0 }, <br \/> &#8230; <br \/> );<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">Alternatively you may wish to check for it in other ways that will cause more than just a warning.<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"1%\">\n<p style=\"margin-top: 1em\">\u2022<\/p>\n<\/td>\n<td width=\"5%\"><\/td>\n<td width=\"78%\">\n<p style=\"margin-top: 1em\">Add the following code snippet to your Makefile.PL:<\/p>\n<\/td>\n<td width=\"5%\"> <\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:17%; margin-top: 1em\">sub MY::install { <br \/> package MY; <br \/> my $script = shift\u2212>SUPER::install(@_); <br \/> if (ExtUtils::MakeMaker::prompt( <br \/> &#8220;Do you want to modify ParserDetails.ini?&#8221;, &#8216;Y&#8217;) <br \/> =~ \/^y\/i) { <br \/> $script =~ s\/install :: (.*)$\/install :: $1 install_sax_driver\/m; <br \/> $script .= <<\"INSTALL\"; <br \/> install_sax_driver : <br \/> t@$(PERL) \u2212MXML::SAX \u2212e &#8220;XML::SAX\u2212>add_parser(q($(NAME)))\u2212>save_parsers()&#8221; <br \/> INSTALL <br \/> } <br \/> return $script; <br \/> }<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">Note that you should check the output of this \u2212 $( <small>NAME<\/small> ) will use the name of your distribution, which may not be exactly what you want. For example XML::LibXML has a driver called XML::LibXML::SAX::Generator, which is used in place of $( <small>NAME<\/small> ) in the above.<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"1%\">\n<p style=\"margin-top: 1em\">\u2022<\/p>\n<\/td>\n<td width=\"5%\"><\/td>\n<td width=\"32%\">\n<p style=\"margin-top: 1em\">Add an <small>XML::SAX<\/small> test:<\/p>\n<\/td>\n<td width=\"51%\"> <\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:17%; margin-top: 1em\">A test file should be added to your t\/ directory containing something like the following:<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">use Test; <br \/> BEGIN { plan tests => 3 } <br \/> use XML::SAX; <br \/> use XML::SAX::PurePerl::DebugHandler; <br \/> XML::SAX\u2212>add_parser(q(XML::SAX::MyDriver)); <br \/> local $XML::SAX::ParserPackage = &#8216;XML::SAX::MyDriver&#8217;; <br \/> eval { <br \/> my $handler = XML::SAX::PurePerl::DebugHandler\u2212>new(); <br \/> ok($handler); <br \/> my $parser = XML::SAX::ParserFactory\u2212>parser(Handler => $handler); <br \/> ok($parser); <br \/> ok($parser\u2212>isa(&#8216;XML::SAX::MyDriver&#8217;); <br \/> $parser\u2212>parse_string(&#8220;<tag\/>&#8220;); <br \/> ok($handler\u2212>{seen}{start_element}); <br \/> };<\/p>\n<h2>EXPORTS <a name=\"EXPORTS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">By default, <small>XML::SAX<\/small> exports nothing into the caller\u2019s namespace. However you can request the symbols &#8220;Namespaces&#8221; and &#8220;Validation&#8221; which are the URIs for those features, allowing an easier way to request those features via ParserFactory:<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">use XML::SAX qw(Namespaces Validation); <br \/> my $factory = XML::SAX::ParserFactory\u2212>new(); <br \/> $factory\u2212>require_feature(Namespaces); <br \/> $factory\u2212>require_feature(Validation); <br \/> my $parser = $factory\u2212>parser();<\/p>\n<h2>AUTHOR <a name=\"AUTHOR\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Current maintainer: Grant McLean, grantm@cpan.org<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Originally written by:<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Matt Sergeant, matt@sergeant.org<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Kip Hampton, khampton@totalcinema.com<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Robin Berjon, robin@knowscape.com<\/p>\n<h2>LICENSE <a name=\"LICENSE\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">This is free software, you may use it and distribute it under the same terms as Perl itself.<\/p>\n<h2>SEE ALSO <a name=\"SEE ALSO\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">XML::SAX::Base for writing <small>SAX<\/small> Filters and Parsers<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">XML::SAX::PurePerl for an <small>XML<\/small> parser written in 100% pure perl.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">XML::SAX::Exception for details on exception handling<\/p>\n<hr>\n","protected":false},"excerpt":{"rendered":"<p>  XML::SAX \u2212 Simple API for XML <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[3007,3105],"class_list":["post-6731","post","type-post","status-publish","format-standard","hentry","category-sin-categoria","tag-man3","tag-xmlsax"],"gutentor_comment":0,"_links":{"self":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/6731","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/comments?post=6731"}],"version-history":[{"count":0,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/6731\/revisions"}],"wp:attachment":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/media?parent=6731"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/categories?post=6731"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/tags?post=6731"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}