﻿#!/usr/bin/perl -w
use strict;
use warnings;
use utf8;
use open qw(:std :utf8);

# use open IN => ':utf8', OUT => ':utf8';
# binmode STDIN, ':utf8';
# binmode STDOUT, ':utf8';
# binmode STDERR, ':utf8';

# use XML::Parser;
# use XML::Simple;
# use XML::LibXML;


# Filter_3_test_wellformedness.pl
# 2010-05-03
# Wolfgang Schmidle

# This Filter is a wrapper for checking the well-formedness of an XML document using xmllint.


# text input

my $file = shift @ARGV;

unless ($file =~ m!\.xml!) { warn "Don't forget to save your document as .xml !\n(Filename $file)\n\n"; }

my $result = `xmllint --noout "$file" 2>&1`; # 2>&1: redirect xmllint's output from stderr to stdout

if ($result) {
	$result =~ s!/private[^:]+(xml|txt)\.S:!!g;
} else {
	$result = "The document is well-formed.\n";
}

die $result;
