| Test-XML-Valid documentation | Contained in the Test-XML-Valid distribution. |
Test::XML::Valid - Validate XML and XHTML
use Test::XML::Valid; xml_file_ok($xmlfilename); xml_string_ok($xml_string);
Tests for Valid XHTML (using XML::LibXML). If the XML is not valid, a message will be generated with specific details about where the parser failed.
Checks that $xmlfilename validates. $msg is optional.
Checks that $xml_string validates. $msg is optional.
Mark Stosberg <mark@summersault.com>
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
The full text of the license can be found in the LICENSE file included with this module.
perl(1).
| Test-XML-Valid documentation | Contained in the Test-XML-Valid distribution. |
package Test::XML::Valid; use XML::LibXML; use strict; use Test::Builder; use vars qw/$VERSION/; $VERSION = "0.04"; my $Test = Test::Builder->new; sub import { my $self = shift; my $caller = caller; no strict 'refs'; *{$caller.'::xml_file_ok'} = \&xml_file_ok; *{$caller.'::xml_string_ok'} = \&xml_string_ok; # *{$caller.'::xml_fh_ok'} = \&xml_fh_ok; # *{$caller.'::xml_html_file_ok'} = \&xml_html_file_ok; # *{$caller.'::xml_html_fh_ok'} = \&xml_html_fh_ok; # *{$caller.'::xml_html_string_ok'} = \&xml_html_string_ok; # *{$caller.'::xml_sgml_file_ok'} = \&xml_sgml_file_ok; # *{$caller.'::xml_sgml_fh_ok'} = \&xml_sgml_fh_ok; # *{$caller.'::xml_sgml_string_ok'} = \&xml_sgml_string_ok; $Test->exported_to($caller); $Test->plan(@_); }
sub xml_file_ok { my $xmlfilename = shift; my $msg = shift || "$xmlfilename is valid XHTML"; eval { my $parser = XML::LibXML->new; $parser->validation(1); $parser->parse_file($xmlfilename); }; my $ok = !$@; $Test->ok($ok,$msg); $Test->diag($@) unless $ok; return $ok; } sub xml_string_ok { my $xml_string = shift; my $msg = shift || "valid XHTML"; eval { my $parser = XML::LibXML->new; $parser->validation(1); $parser->parse_string($xml_string); }; my $ok = !$@; $Test->ok($ok,$msg); $Test->diag($@) unless $ok; return $ok; } 1; #this line is important and will help the module return a true value __END__