private static function findEntityDescriptor($doc)
{
assert('$doc instanceof DOMDocument');
// find the EntityDescriptor DOMElement. This should be the first (and only) child of the DOMDocument
$ed = $doc->documentElement;
if ($ed === null) {
throw new Exception('Failed to load SAML metadata from empty XML document.');
}
if (SimpleSAML\Utils\XML::isDOMElementOfType($ed, 'EntityDescriptor', '@md') === false) {
throw new Exception('Expected first element in the metadata document to be an EntityDescriptor element.');
}
return new \SAML2\XML\md\EntityDescriptor($ed);
}