storri has asked for the wisdom of the Perl Monks concerning the following question:
I am trying to validate an XML using a DTD file. I have captured the output but I don't know what line/what word, etc. is causing the validation to fail. Here is the code:
my ($dtd_file) = @_; my $file_target = "$main::args{xml_dir}/$main::args{file}"; my $dtd_target = "$main::args{xml_dir}/$dtd_file"; my $dtd = XML::LibXML::Dtd->new("", $dtd_target); my $parser = XML::LibXML->new(); $parser->validation(1); my $document; if (! -f $file_target) { print "Cannot find required file: $file_target\n"; exit(0); } if (! -f "$dtd_target") { print "Cannot find required file: $dtd_target\n"; exit(0); } eval { $document = $parser->parse_file($file_target); $document->validate($dtd_file); }; if ($@) { print "XML not valid because of $@ !\n"; }
If I use this code I get the error message:
XML not valid because of is_valid: argument must be a DTD object at ./autobuild.pl line 146.
Line 146 is the line were $document->validate($dtd_file) is called.
Stephen
2003-06-07 edit ybiC: <code> tags
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Gathering more verbose output from XML file validation
by arturo (Vicar) on Jun 08, 2003 at 00:39 UTC |
Back to
Seekers of Perl Wisdom