NAME

SVG::Parser - XML Parser for SVG documents

SYNOPSIS

#!/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;

my $svg=$parser->parse($xml);

print $svg->xmlify;

DESCRIPTION

SVG::Parser is an XML parser for SVG Documents. It takes XML as input, and produces an SVG object as its output. XML::Parser is used to perform the basic parsing; a subclass of XML::Parser that permits Stream mode may also be used (see below).

METHODS

SVG::Parser provides all methods supported by XML::Parser. In particular:

  • new([%attrs])

    Create a new SVG::Parser object. Optional attributes may be passed as arguments; all attributes without a leading '-' prefix are passed to the parent constructor (by default XML::Parser). For example:

       my $parser=new SVG::Parser(
    	ErrorContext => 2,
            NoExpand => 1,
       );

    (NB: SVG::Parser expects the parser style to be 'Stream'. Changing this is probably unhelpful.)

    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:

    my $parser=new SVG::Parser(debug => 1);

    or:

    my $parser=SVG::Parser->new(debug => 1);
  • parse($xml)

    Parse an XML document and return an SVG object which may then be used to manipulate the SVG content before regenerating the output XML. For example:

    my $svg=$parser->parse($svgxml);

    See XML::Parser for other ways to parse input XML.

EXPORTS

None. However, an alternative parent class (other than XML::Parser) can be specified by passing the package name to SVG::Parser in the import list. For example:

use SVG::Parser qw(My::XML::Parser::Subclass);

Where My::XML::Parser::Subclass is a subclass like:

package My::XML::Parser::Subclass;
use strict;
use vars qw(@ISA);
use XML::Parser;
@ISA=qw(XML::Parser);

...custom methods...

1;

EXAMPLES

See svgparse in the examples directory of the distribution.

AUTHOR

Peter Wainwright, peter.wainwright@cybrid.net

SEE ALSO

SVG, XML::Parser, perl(1).