Changeset 13148


Ignore:
Timestamp:
2006-10-20T12:37:50+13:00 (18 years ago)
Author:
shaoqun
Message:

added code to check whether its subclass can parse a doc type before parsing

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/perllib/plugins/XMLPlug.pm

    r12844 r13148  
    7979                        'Entity' => \&Entity,
    8080                        'Doctype' => \&Doctype,
    81                         'Default' => \&Default
    82                         }); 
     81                        'Default' => \&Default,
     82                        }); 
     83
    8384    $self->{'parser'} = $parser;
    8485
     
    168169    $self->{'processor'} = $processor;
    169170    $self->{'metadata'} = $metadata;
     171
     172
     173    ##call the inheriting plugin's get_doctype method to decide whether to carry on the parsing
     174    if (open(XMLIN,"<$filename")) {
     175    my $doctype = $self->get_doctype();
     176    ## check whether the doctype have the same name as the root element tag
     177    while (defined (my $line = <XMLIN>)) {
     178        ## find the root element
     179         if ($line =~ /<(\w+)[\s>]/){
     180        my $root = $1;
     181        if ($root !~ $doctype){
     182            close(XMLIN);
     183            return undef;
     184        }
     185        else{
     186            close(XMLIN);
     187            last;
     188        }
     189        }
     190    }
     191}
     192
    170193
    171194    eval {
     
    275298sub xml_doctype {
    276299    my $self = shift(@_);
     300
    277301    my ($expat, $name, $sysid, $pubid, $internal) = @_;
    278302    die "XMLPlug Cannot process XML document with DOCTYPE of $name";
    279303}
     304
     305# the inheriting class must implement this method to tell whether to parse this doc type
     306sub get_doctype {
     307    my $self = shift(@_);
     308    die "The inheriting class must implement this method";
     309}
     310
     311
    280312
    281313# Called for every start tag. The $_ variable will contain a copy of the
Note: See TracChangeset for help on using the changeset viewer.