diff --git a/lib/SAML2/XML/mdattr/EntityAttributes.php b/lib/SAML2/XML/mdattr/EntityAttributes.php
index a53056917631589c1c74c6425bbd1a509c79ced5..93590081cde847bed2334e5864e5599099d74761 100644
--- a/lib/SAML2/XML/mdattr/EntityAttributes.php
+++ b/lib/SAML2/XML/mdattr/EntityAttributes.php
@@ -60,8 +60,10 @@ class SAML2_XML_mdattr_EntityAttributes {
 		$e = $doc->createElementNS(SAML2_XML_mdattr_EntityAttributes::NS, 'mdattr:EntityAttributes');
 		$parent->appendChild($e);
 
-		foreach ($this->children as $child) {
-			$child->toXML($e);
+		if (!empty($this->children)) {
+			foreach ($this->children as $child) {
+				$child->toXML($e);
+			}
 		}
 
 		return $e;
diff --git a/lib/SimpleSAML/Metadata/SAMLParser.php b/lib/SimpleSAML/Metadata/SAMLParser.php
index e81732999fed5d971a7b56dc4490022b225bf876..02bfa5676384782b281c3ba4bae96fa0a4941b9b 100644
--- a/lib/SimpleSAML/Metadata/SAMLParser.php
+++ b/lib/SimpleSAML/Metadata/SAMLParser.php
@@ -886,7 +886,7 @@ class SimpleSAML_Metadata_SAMLParser {
 			// and not at RoleDescriptor level
 			if ($element instanceof SAML2_XML_md_EntityDescriptor) {
 	
-				if ($e instanceof SAML2_XML_mdattr_EntityAttributes) {
+				if ($e instanceof SAML2_XML_mdattr_EntityAttributes && !empty($e->children)) {
 
 					foreach($e->children AS $attr) {