Note that parser options are dependant on which parser type is selected.
Attributes with a leading - are processed by SVG::Parser. Currently the only recognised attribute is -debug, which generates a simple but possibly useful debug trace of the parsing process to standard error. For example:
Because the parse() method differs in use beteen XML::Parser and XML::SAX, SVG::Parser provides its own parse() method. This calls the parent parser with the correct first argument when given either a filehandle or a string as input.
Additional arguments are passed to the parent parser class, but since XML::Parser and XML::SAX parsers take options in different formats this is of limited use. SVG::Parser does not currently provide any translation of parser options.
Since the parse_file() method (XML::SAX) and parsefile() method (XML::Parser) differ in both name and usage, SVG::Parser provides its own version of both methods that determines whether the passed argument is a filehandle or a file name and directs the call to the appropriate parent parser method.
Both methods will work equally well whichever parent parser class is in use:
None. However, a list of preferred parsers can be specified by passing the package name to SVG::Parser in the import list. This allows an SVG parser application to use the best parser available without knowing what XML parsers might be available on the target platform. SAX is generally preferred to Expat, but an Expat-based parser may be preferable to the slow Perl-based SAX parser XML::SAX::PurePerl. (See XML::SAX::PurePerl.)
Instead of specifying the full SVG parser name, Expat and SAX may be used as shorthand. For example:
use SVG::Parser qw(SAX Expat);
Both the above examples produce the default behaviour. To prefer Expat over SAX use either of:
To use Expat with a specific XML::Parser subclass:
To use SAX with the XML::LibXML SAX parser:
A number of specifications can be listed to have SVG::Parse try a number of possible parser alternatives in decreasing order of preference:
You can test different scenarios from the command line. For example:
perl -MSVG::Parser=SAX mysvgapp.pl perl -MSVG::Parser=Expat,SAX mysvgapp.pl perl -MSVG::Parser=SAX=XML::LibXML::SAX::Parser,Expat mysvgapp.pl
To pass additional items in the import list to the parent Expat or SAX parser class, use additional = separators in the parser specification. In the case of XML::SAX a minimum version number may be required this way:
Similarly, from the command line:
See svgparse, svgparse2, and svgparse3 in the examples directory of the distribution, along with svgexpatparse and svgsaxparse for examples of using the SVG::Parser::Expat and SVG::Parser::SAX modules directly.
Peter Wainwright, email@example.com
SVG, SVG::Parser::Expat, SVG::Parser::SAX, XML::Parser, XML::SAX
|perl v5.20.3||SVG::PARSER (3)||2016-03-17|