Know-How für Ihr Projekt

Perl Documentation


XML::Parser::Expat - Lowlevel access to James Clark's expat XML parser


use XML::Parser::Expat;
$parser = XML::Parser::Expat->new;
$parser->setHandlers('Start' => \&sh,
                     'End'   => \&eh,
                     'Char'  => \&ch);
open(FOO, '<', 'info.xml') or die "Couldn't open";
# $parser->parse('<foo id="me"> here <em>we</em> go </foo>');
sub sh
  my ($p, $el, %atts) = @_;
  $p->setHandlers('Char' => \&spec)
    if ($el eq 'special');
sub eh
  my ($p, $el) = @_;
  $p->setHandlers('Char' => \&ch)  # Special elements won't contain
    if ($el eq 'special');         # other special elements


This module provides an interface to James Clark's XML parser, expat. As in expat, a single instance of the parser can only parse one document. Calls to parsestring after the first for a given instance will die.

Expat (and XML::Parser::Expat) are event based. As the parser recognizes parts of the document (say the start or end of an XML element), then any handlers registered for that type of an event are called with suitable parameters.


XML::Parser::ContentModel Methods

The element declaration handlers are passed objects of this class as the content model of the element declaration. They also represent content particles, components of a content model.

When referred to as a string, these objects are automagicly converted to a string representation of the model (or content particle).

XML::Parser::ExpatNB Methods

The class XML::Parser::ExpatNB is a subclass of XML::Parser::Expat used for non-blocking access to the expat library. It does not support the parse, parsestring, or parsefile methods, but it does have these additional methods:



Larry Wall <> wrote version 1.0.

Clark Cooper <> picked up support, changed the API for this version (2.x), provided documentation, and added some standard package features.