use XML::Parser; # Variables my $xmlp; my $currentTag = ""; # Prototypes # Create new parser and set callbacks $xmlp = new XML::Parser(); $xmlp->setHandlers( Start => \&start, End => \&end, Char => \&cdata ); # Parse the file $xmlp->parsefile("../thes_ex.xml"); # Called when a tag is started sub start() { # extract variables my ($parser, $name, %attr) = @_; $currentTag = lc($name); print "start $currentTag\n"; } # Called when a tag is ended sub end() { # extract variables my ($parser, $name) = @_; $currentTag = lc($name); print "ended $currentTag\n"; # clear value of current tag $currentTag = ""; $cdata = ""; } # Called when CDATA section found sub cdata() { my ($parser, $data) = @_; print "cdata: $data\n"; }