#!/bin/perl -w use strict; use XML::Twig; my $t= new XML::Twig( # called for all opening tags start_tag_handlers => { _all_ => \&store_position }, # called for each closing elt tag twig_handlers => { elt => \&elt}); $t->parse( \*DATA); sub store_position { my( $t, $elt)= @_; my $line = $t->{twig_parser}->current_line; # $t->{twig_parser} is the expat object my $column = $t->{twig_parser}->current_column; $elt->{my_atts}= { line => $line, column => $column }; # crude but works } sub elt { my( $t, $elt)= @_; if( my $error= $elt->att( 'error')) { my $line = $elt->{my_atts}->{line}; my $column = $elt->{my_atts}->{column}; print STDERR "error $error at $line:$column\n"; } } __DATA__ this one is OK not this one though OK here is a bar error