#!/usr/bin/perl -w
use strict;
use diagnostics;
use XML::Parser;

if (! @ARGV) {
  print "Usage: $0 <xml-files>$/";
  exit(1);
}

my $parser = new XML::Parser(ErrorContext => 3);

foreach my $file (@ARGV) {
  if (! (-e $file)) {
    print "$file: does not exist!!!$/";
    exit(1);
  } else {
    print "Processing $file... ";
    eval {
      $parser->parsefile("$file");
    };
    if ($@) {
        # do some removal of noise
        $@ =~ s/Uncaught.*?\n// while ($@ =~ /Uncaught.*?\n/);
        $@ =~ s/\n\s*at.*?Parser.pm(.|\n)*//;
        print "Error:$/ $@ $/$/";
    } else {
        print "Okay!$/";
    }
  }
}
