my $parser = XML::Parser->new(ErrorContext => 2, Style => "Tree"); my $xso = XML::SimpleObject->new( $parser->parse($content) ) or die "could not parse!"; check_tag($xso); ... #### #!/bin/perl -w use strict; use XML::Twig; my $twig = XML::Twig->new(); $twig->parse( \*DATA) or die "could not parse!"; # the #ELT argument means that we will get only the # "real" elements, as opposed to the ones containing the text foreach my $tag($twig->descendants( '#ELT')) { print $tag->gi; print " ", $tag->text if( is_field( $tag)); print "\n"; } sub is_field { my $tag= shift; return 1 if( ($tag->children == 1) && $tag->first_child->is_text); return 0; } __DATA__ elt 1 subelt 1 subelt 2 subelt 3 elt 3 subelt 4