diff --git a/lib/IdPAccountManager/SAMLMetadata.pm b/lib/IdPAccountManager/SAMLMetadata.pm
index ccda103ba345779571ec59772b7b0ad4a0d2eaee..588eea72dbbb767adf3043156ae54b922f84f626 100644
--- a/lib/IdPAccountManager/SAMLMetadata.pm
+++ b/lib/IdPAccountManager/SAMLMetadata.pm
@@ -15,19 +15,9 @@ sub new {
     die "non-existing file $args{file}" unless -f $args{file};
     die "non-readable file $args{file}" unless -r $args{file};
 
-    open(my $handle, '<', $args{file})
-        or die "failed to open file $args{file}: $ERRNO";
-
-    my $parser = XML::LibXML->new();
-    die "Failed to initialize XML parser" unless $parser;
-
     my $doc;
-    eval { $doc = $parser->parse_fh($handle) };
-    die "Failed to parse file $args{file}: $EVAL_ERROR"
-        if $EVAL_ERROR;
-
-    die "Failed to parse file $args{file}: $EVAL_ERROR"
-        unless $doc;
+    eval { $doc = XML::LibXML->load_xml(location => $args{file}); };
+    die "Failed to parse file: $EVAL_ERROR" if $EVAL_ERROR;
 
     my $root = $doc->documentElement();
     my $type = $root->nodeName();
diff --git a/t/samlmetadata.t b/t/samlmetadata.t
index a28ecd82ce8f154134c123f9792271982856bcd6..93feb91186dabf0a52f50cc32b4d94e4c9f870a5 100644
--- a/t/samlmetadata.t
+++ b/t/samlmetadata.t
@@ -43,7 +43,7 @@ throws_ok {
     $metadata = IdPAccountManager::SAMLMetadata->new(
         file => $file1->filename()
     );
-} qr/^Failed to parse file \S+: Empty Stream/,
+} qr/^Failed to parse file: \S+ parser error : Document is empty/,
 'instanciation: empty file';
 
 my $file2 = File::Temp->new(UNLINK => $ENV{TEST_DEBUG} ? 0 : 1);
@@ -57,7 +57,7 @@ throws_ok {
     $metadata = IdPAccountManager::SAMLMetadata->new(
         file => $file2->filename()
     );
-} qr/^Failed to parse file \S+: Entity: line 1: parser error/,
+} qr/^Failed to parse file: \S+ parser error : Start tag expected/,
 'instanciation: non-xml file';
 
 my $file3 = File::Temp->new(UNLINK => $ENV{TEST_DEBUG} ? 0 : 1);