|
NAMESVG::Parser - XML Parser for SVG documentsSYNOPSIS#!/usr/bin/perl -w use strict; use SVG::Parser; die "Usage: $0 <file>\n" unless @ARGV; my $xml; { local $/=undef; $xml=<>; } my $parser=new SVG::Parser(-debug => 1); my $svg=$parser->parse($xml); print $svg->xmlify; and: #!/usr/bin/perl -w use strict; use SVG::Parser qw(SAX=XML::LibXML::Parser::SAX Expat SAX); die "Usage: $0 <file>\n" unless @ARGV; my $svg=SVG::Parser->new()->parsefile($ARGV[0]); print $svg->xmlify; DESCRIPTIONSVG::Parser is an XML parser for SVG Documents. It takes XML as input and produces an SVG object as its output.SVG::Parser supports both XML::SAX and XML::Parser (Expat) parsers, with SAX preferred by default. Only one of these needs to be installed for SVG::Parser to function. A list of preferred parsers may be specified in the import list - SVG::Parser will use the first parser that successfully loads. Some basic measures are taken to provide cross-compatability. Applications requiring more advanced parser features should use the relevant parser module directly; see SVG::Parser::Expat and SVG::Parser::SAX. METHODSSVG::Parser provides all methods supported by its parent parser class. In addition it provides the following:
EXPORTSNone. 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.)Each parser specification consists of one of the two supported SVG parsers, SVG::Parser::Expat or SVG::Parser::SAX, optionally followed by an '=' and an explicit parser package. For example: use SVG::Parser qw(SVG::Parser::SAX SVG::Parser::Expat); 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: use SVG::Parser qw(SVG::Parser::Expat SVG::Parser::SAX); use SVG::Parser qw(Expat SAX); To use Expat with a specific XML::Parser subclass: use SVG::Parser qw(SVG::Parser::Expat=My::XML::Parser::Subclass); To use SAX with the XML::LibXML SAX parser: use SVG::Parser qw(SVG::Parser::SAX=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: use SVG::Parser qw( SAX=My::SAXParser Expat=My::Best::ExpatParser SAX=XML::LibXML::SAX::Parser Expat=My::Other::ExpatParser Expat SAX ) 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: # require version 1.40+ of the LibXML SAX parser, otherwise use Perl use SVG::Parser qw( SAX=XML::LibXML::SAX::Parser=1.40 SAX=XML::SAX::PurePerl ); Similarly, from the command line: perl -MSVG::Parser=SAX=XML::LibXML::SAX::Parser=1.40,SAX=XML::SAX::PurePerl mysvgapp.pl EXAMPLESSee "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.AUTHORPeter Wainwright, peter.wainwright@cybrid.netSEE ALSOSVG, SVG::Parser::Expat, SVG::Parser::SAX, XML::Parser, XML::SAX
Visit the GSP FreeBSD Man Page Interface. |