diff --git a/lib/SimpleSAML/Metadata/MetaDataStorageHandlerXML.php b/lib/SimpleSAML/Metadata/MetaDataStorageHandlerXML.php
index 7c537aa960515b08655e41c185190fd925b138b4..7e2b50509163583d6ac58101b49d1730b8e9e34b 100644
--- a/lib/SimpleSAML/Metadata/MetaDataStorageHandlerXML.php
+++ b/lib/SimpleSAML/Metadata/MetaDataStorageHandlerXML.php
@@ -32,15 +32,17 @@ class SimpleSAML_Metadata_MetaDataStorageHandlerXML extends SimpleSAML_Metadata_
      */
     protected function __construct($config)
     {
-        // get the configuration
-        $globalConfig = SimpleSAML_Configuration::getInstance();
-
+        $src = $srcXml = null;
         if (array_key_exists('file', $config)) {
+            // get the configuration
+            $globalConfig = SimpleSAML_Configuration::getInstance();
             $src = $globalConfig->resolvePath($config['file']);
         } elseif (array_key_exists('url', $config)) {
             $src = $config['url'];
+        } elseif (array_key_exists('xml', $config)) {
+            $srcXml = $config['xml'];
         } else {
-            throw new Exception("Missing either 'file' or 'url' in XML metadata source configuration.");
+            throw new Exception("Missing one of 'file', 'url' and 'xml' in XML metadata source configuration.");
         }
 
 
@@ -50,7 +52,13 @@ class SimpleSAML_Metadata_MetaDataStorageHandlerXML extends SimpleSAML_Metadata_
         $IdP20 = array();
         $AAD = array();
 
-        $entities = SimpleSAML_Metadata_SAMLParser::parseDescriptorsFile($src);
+        if(isset($src)) {
+            $entities = SimpleSAML_Metadata_SAMLParser::parseDescriptorsFile($src);
+        } elseif(isset($srcXml)) {
+            $entities = SimpleSAML_Metadata_SAMLParser::parseDescriptorsString($srcXml);
+        } else {
+            throw new Exception("Neither source file path/URI nor string data provided");
+        }
         foreach ($entities as $entityId => $entity) {
             $md = $entity->getMetadata1xSP();
             if ($md !== null) {
diff --git a/tests/lib/SimpleSAML/Metadata/MetaDataStorageSourceTest.php b/tests/lib/SimpleSAML/Metadata/MetaDataStorageSourceTest.php
new file mode 100644
index 0000000000000000000000000000000000000000..35964f2ac4275158fa040d6c7e6486b9e1ee42e4
--- /dev/null
+++ b/tests/lib/SimpleSAML/Metadata/MetaDataStorageSourceTest.php
@@ -0,0 +1,56 @@
+<?php
+
+
+/**
+ * Class SimpleSAML_Metadata_MetaDataStorageSourceTest
+ */
+class SimpleSAML_Metadata_MetaDataStorageSourceTest extends PHPUnit_Framework_TestCase
+{
+    /**
+     * Test SimpleSAML_Metadata_MetaDataStorageSourceTest::getConfig XML bad source
+     * @expectedException Exception
+     */
+    public function testBadXMLSource() {
+        SimpleSAML_Metadata_MetaDataStorageSource::getSource(["type"=>"xml", "foo"=>"baa"]);
+    }
+
+    /**
+     * Test SimpleSAML_Metadata_MetaDataStorageSourceTest::getConfig invalid static XML source
+     * @expectedException Exception
+     */
+    public function testInvalidStaticXMLSource() {
+        $strTestXML = "
+<EntityDescriptor ID=\"_12345678-90ab-cdef-1234-567890abcdef\" entityID=\"https://saml.idp/entityid\" xmlns=\"urn:oasis:names:tc:SAML:2.0:metadata\">
+</EntityDescriptor>
+";
+        SimpleSAML_Metadata_MetaDataStorageSource::getSource(["type"=>"xml", "xml"=>$strTestXML]);
+    }
+
+    /**
+     * Test SimpleSAML_Metadata_MetaDataStorageSourceTest::getConfig XML static XML source
+     */
+    public function testStaticXMLSource() {
+        $testEntityId = "https://saml.idp/entityid";
+        $strTestXML = "
+<EntityDescriptor ID=\"_12345678-90ab-cdef-1234-567890abcdef\" entityID=\"$testEntityId\" xmlns=\"urn:oasis:names:tc:SAML:2.0:metadata\">
+<RoleDescriptor xsi:type=\"fed:ApplicationServiceType\"
+protocolSupportEnumeration=\"http://docs.oasis-open.org/ws-sx/ws-trust/200512 http://schemas.xmlsoap.org/ws/2005/02/trust http://docs.oasis-open.org/wsfed/federation/200706\"
+ServiceDisplayName=\"SimpleSAMLphp Test\"
+xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
+xmlns:fed=\"http://docs.oasis-open.org/wsfed/federation/200706\">
+<NameIDFormat>urn:oasis:names:tc:SAML:2.0:nameid-format:persistent</NameIDFormat>
+<SingleSignOnService Binding=\"urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect\" Location=\"https://saml.idp/sso/\"/>
+<SingleLogoutService Binding=\"urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect\" Location=\"https://saml.idp/logout/\"/>
+</RoleDescriptor>
+<IDPSSODescriptor protocolSupportEnumeration=\"urn:oasis:names:tc:SAML:2.0:protocol\"/>
+</EntityDescriptor>
+";
+        // The primary test here is that - in contrast to the others above - this loads without error
+        // As a secondary thing, check that the entity ID from the static source provided can be extracted
+        $source = SimpleSAML_Metadata_MetaDataStorageSource::getSource(["type"=>"xml", "xml"=>$strTestXML]);
+        $idpSet = $source->getMetadataSet("saml20-idp-remote");
+        $this->assertArrayHasKey($testEntityId, $idpSet,  "Did not extract expected IdP entity ID from static XML source");
+	// Finally verify that a different entity ID does not get loaded
+        $this->assertCount(1, $idpSet, "Unexpectedly got metadata for an alternate entity than that defined");
+    }
+}