/usr/bin/validxml is in libxml-validate-perl 1.025-3.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | #!/usr/bin/perl -w
use strict;
use XML::Validate qw();
use Getopt::Long qw();
require Log::Trace;
use vars qw($VERSION);
($VERSION) = ('$Revision: 1.10 $' =~ /([\d\.]+)/ );
my $assert_invalid = 0;
my $help = 0;
my $tracing = 0;
my $deep_tracing = 0;
my $backend = 'BestAvailable';
Getopt::Long::GetOptions(
't' => \$tracing,
'T' => \$deep_tracing,
'assert-invalid' => \$assert_invalid,
'backend:s' => \$backend,
'help' => \$help
);
import Log::Trace 'print' if $tracing;
import Log::Trace 'print' => { Deep => 1 } if $deep_tracing;
my @files;
while (my $mask = shift) {
push @files, glob($mask);
}
if ($help || @files < 1) {
require Pod::Usage;
Pod::Usage::pod2usage(-verbose => 2);
}
my $validator = new XML::Validate(Type => $backend);
my %errors;
for my $file (@files) {
open(FH,$file) || die "Unable to open file handle FH for file '$file': $!\n";
local $/ = undef;
my $xml = <FH>;
close(FH) || warn "Unable to close file handle FH for file '$file': $!\n";
if (my $tree = $validator->validate($xml)) {
$errors{$file} = '';
} else {
if ($validator->last_error()->{message}) {
$errors{$file} = sprintf("%s at %d:%d",@{$validator->last_error()}{'message','line','column'});
} else{
$errors{$file} = 'Unknown error';
}
if (length($errors{$file}) > 0) {
$errors{$file} =~ s/(\n|\r|\cM)/ /gi;
}
}
}
print "1..".@files."\n";
for my $file (@files) {
if ($errors{$file}) {
print(($assert_invalid ? '' : 'not ').
"ok - $file - $errors{$file}\n");
} else {
print(($assert_invalid ? 'not ' : '').
"ok - $file\n");
}
}
=pod
=head1 NAME
validxml - Command-line driver for XML::Validate.
=head1 SYNOPSIS
validxml *.xml
validxml --assert-invalid *.xml
=head1 DESCRIPTION
Command-line driver for XML::Validate using the 'BestAvailable' processing
type.
=head2 Commandline Options
=over 4
=item --assert-invalid
Swap the ok/not ok so invalid things are OK - still output the validation
error) - this is useful for schema "unit tests".
=item --backend [validator type]
Specify an C<XML::Validate> backend to use (e.g LibXML, Xerces). Defaults to
I<BestAvailable>.
=back
=head2 Output
Output is Test::Harness compatible.
1..scalar @files
ok - filename/not ok - filename - validation error
=head1 VERSION
$Revision: 1.10 $
$Id: validxml.pl,v 1.10 2006/04/07 09:43:10 johnl Exp $
=head1 AUTHOR
Nicola Worthington
$Author: johnl $
=head1 COPYRIGHT
(c) BBC 2005. This program is free software; you can redistribute it and/or modify it under the GNU GPL.
See the file COPYING in this distribution, or http://www.gnu.org/licenses/gpl.txt
=cut
__END__
|