Shlomi Fish avatar Shlomi Fish committed 10cad3b

Add a convenience method.

Comments (0)

Files changed (2)

XML-GrammarBase/lib/XML/GrammarBase/Role/RelaxNG.pm

     return;
 }
 
+sub rng_validate_file
+{
+    my ($self, $filename) = @_;
+
+    my $xml_parser = XML::LibXML->new();
+    $xml_parser->validation(0);
+
+    my $dom = $xml_parser->parse_file($filename);
+
+    return $self->rng_validate_dom($dom);
+}
+
 =head1 SYNOPSIS
 
     package XML::Grammar::MyGrammar::RelaxNG::Validate;
 
 =head2 $self->rng_validate_dom($source_dom)
 
-Validates the DOM using the RELAX-NG schema.
+Validates the DOM ( $source_dom ) using the RELAX-NG schema.
+
+=head2 $self->rng_validate_file($file_path)
+
+Validates the file in $file_path using the RELAX-NG schema.
 
 =head2 BUILD
 

XML-GrammarBase/t/rng.t

 use strict;
 use warnings;
 
-use Test::More tests => 1;
+use Test::More tests => 2;
 
 package MyGrammar::RNG;
 
     is ($@, '', 'No exception was thrown.');
 }
 
+{
+    my $rng = MyGrammar::RNG->new();
+
+    eval {
+        $rng->rng_validate_file(
+            File::Spec->catfile(
+                File::Spec->curdir(), "t", "data", "fiction-xml-test.xml"
+            )
+        );
+    };
+
+    # TEST
+    is ($@, '', 'No exception was thrown.');
+}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.