澄清SAX解析器例程

时间:2014-12-12 08:04:41

标签: perl

请您澄清下面SAX解析器会做什么? 特别是在以下_parse例程中的$self->document($reader);

sub _parse_systemid {
    my $self = shift;
    my ($uri) = @_;
    my $reader = XML::SAX::PurePerl::Reader::URI->new($uri);
    return $self->_parse($reader);
}

sub _parse {
    my ($self, $reader) = @_;

    $reader->public_id($self->{ParseOptions}{Source}{PublicId});
    $reader->system_id($self->{ParseOptions}{Source}{SystemId});

    $self->{NSHelper} = XML::NamespaceSupport->new({xmlns => 1});

    $self->set_document_locator(
        XML::SAX::DocumentLocator->new(
            sub { $reader->public_id },
            sub { $reader->system_id },
            sub { $reader->line },
            sub { $reader->column },
            sub { $reader->get_encoding },
            sub { $reader->get_xml_version },
        ),
    );

    $self->start_document({});

    if (defined $self->{ParseOptions}{Source}{Encoding}) {
        $reader->set_encoding($self->{ParseOptions}{Source}{Encoding});
    }
    else {
        $self->encoding_detect($reader);
    }

    # parse a document
    $self->document($reader);     # what exactly it will parse and where it will store?

    return $self->end_document({});
}

这是一个开源API,请在下面的参考链接中找到完整的代码

http://cubist.cs.washington.edu/docperl/?page=code&module=XML::SAX::PurePerl&location=inc&source=/usr/share/perl5/vendor_perl/XML/SAX/PurePerl.pm

0 个答案:

没有答案