Others have mentioned Perl-based solutions, and also warned about the danger of using XML or SGML tools on data that isn't guaranteed to be either; but, if you know you're producing XML and aren't too committed to using Perl, would xmllint do what you want?