use strict;
use warnings;
use XML::LibXML;

my $doc = XML::LibXML->new->parse_fh(*DATA);
for ( $doc->findnodes("//*") )
{
    $_->parentNode->removeChild($_)
        unless $_->textContent() =~ /\S/
        or $_->hasAttributes();
}
print $doc->serialize(1);
