convert array DATA value to xml format and return as xml object

@param array|string $value
@param string $addCdata
@param Xml $xml
@param string|integer $key
@param DOMElement $parent
@param array $attributes
@return DOMElement
193434
protected function _convertArrayDataToXml(
        $value,
        $addCdata,
        Xml $xml,
        $key,
        $parent,
        array $attributes
    ) {
        $count      = count($value) === 1;
        $isNotEmpty = !empty($attributes);
        $exist      = array_key_exists(0, $value);

        if ($count && $isNotEmpty && $exist) {
            $children = $this->_appendDataToNode(
                $addCdata,
                $xml,
                $key,
                $value[0]
            );
        } else {
            $children = $xml->createElement(
                $this->_integerToStringKey($key)
            );
            $this->_arrayToXml($value, $xml, $addCdata, $children);
        }
        $parent->appendChild($children);

        foreach ($attributes as $attributeKey => $attributeValue) {
            $children->setAttribute($attributeKey, $attributeValue);
        }

        return $parent;
    }
586064
private function fillElement (DOMDocument $doc, DOMElement $parent, array $filler)
    {
        foreach ($filler as $name => $value) {
            if ($value instanceof DOMElement) {
                $element = $value;
            } else {
                $element = $doc->createElement($name);
                
                if (is_array($value)) {
                    $this->fillElement($doc, $element, $value);
                } else {
                    $element->appendChild(new DOMCdataSection($value));
                }
            }
            
            $parent->appendChild($element);
        }
    }
613059
protected function addCollectionNode(DOMElement $element, $value)
    {
        if ($element->childNodes->length === 0 && $element->attributes->length === 0) {
            $this->convertElement($element, $value);

            return;
        }

        $child = $this->document->createElement($element->tagName);
        $element->parentNode->appendChild($child);
        $this->convertElement($child, $value);
    }
580523
private function createCDATASection(\DOMDocument $dom, \DOMNode $node, $value)
    {
        $cdata = $dom->createCDATASection($value);
        $node->appendChild($cdata);
    }
783413
public function toXML(DOMElement $parent) : DOMElement
    {
        $e = parent::toXML($parent);

        if (is_bool($this->WantAuthnRequestsSigned)) {
            $e->setAttribute('WantAuthnRequestsSigned', $this->WantAuthnRequestsSigned ? 'true' : 'false');
        }

        foreach ($this->SingleSignOnService as $ep) {
            $ep->toXML($e, 'md:SingleSignOnService');
        }

        foreach ($this->NameIDMappingService as $ep) {
            $ep->toXML($e, 'md:NameIDMappingService');
        }

        foreach ($this->AssertionIDRequestService as $ep) {
            $ep->toXML($e, 'md:AssertionIDRequestService');
        }

        Utils::addStrings($e, Constants::NS_MD, 'md:AttributeProfile', false, $this->AttributeProfile);

        foreach ($this->Attribute as $a) {
            $a->toXML($e);
        }

        return $e;
    }
342915
public function toXML(DOMElement $parent) : DOMElement
    {
        Assert::same($this->getElement()->namespaceURI, Constants::NS_SAML);
        Assert::same($this->getElement()->localName, "AttributeValue");

        return Utils::copyElement($this->element, $parent);
    }
1291355
protected function toXML(DOMElement $parent) : DOMElement
    {
        $e = $parent->ownerDocument->createElementNS(Constants::NS_MD, $this->elementName);
        $parent->appendChild($e);

        if ($this->ID !== null) {
            $e->setAttribute('ID', $this->ID);
        }

        if ($this->validUntil !== null) {
            $e->setAttribute('validUntil', gmdate('Y-m-d\TH:i:s\Z', $this->validUntil));
        }

        if ($this->cacheDuration !== null) {
            $e->setAttribute('cacheDuration', $this->cacheDuration);
        }

        $e->setAttribute('protocolSupportEnumeration', implode(' ', $this->protocolSupportEnumeration));

        if ($this->errorURL !== null) {
            $e->setAttribute('errorURL', $this->errorURL);
        }

        Extensions::addList($e, $this->Extensions);

        foreach ($this->KeyDescriptor as $kd) {
            $kd->toXML($e);
        }

        if ($this->Organization !== null) {
            $this->Organization->toXML($e);
        }

        foreach ($this->ContactPerson as $cp) {
            $cp->toXML($e);
        }

        return $e;
    }
1083759
private function addChildData(&$parentData, $childAttributes)
    {
        $authorizedChildAttributes = $parentData['children_attributes'];
        $addedChildAttributesData  = array_filter(
            $childAttributes,
            function ($attributeCode) use ($authorizedChildAttributes) {
                return in_array($attributeCode, $authorizedChildAttributes);
            },
            ARRAY_FILTER_USE_KEY
        );

        foreach ($addedChildAttributesData as $attributeCode => $value) {
            if (!isset($parentData[$attributeCode])) {
                $parentData[$attributeCode] = [];
            }

            $parentData[$attributeCode] = array_values(array_unique(array_merge($parentData[$attributeCode], $value)));
        }
    }
52922
public function toXML(DOMElement $parent) : DOMElement
    {
        if ($this->KeyInfo === null) {
            throw new \Exception('Cannot convert KeyDescriptor to XML without KeyInfo set.');
        }

        $doc = $parent->ownerDocument;

        $e = $doc->createElementNS(Constants::NS_MD, 'md:KeyDescriptor');
        $parent->appendChild($e);

        if ($this->use !== null) {
            $e->setAttribute('use', $this->use);
        }

        $this->KeyInfo->toXML($e);

        foreach ($this->EncryptionMethod as $em) {
            $em->toXML($e);
        }

        return $e;
    }
351244
public function add($attributeCode, $value, array $context = null)
    {
        $attribute = $this->getAttribute($attributeCode);

        $method = 'add'.ucfirst($attributeCode);
        if (method_exists($this, $method)) {
            return $this->$method($value, $context);
        }

        return $this->addValueData($attribute, $value, $context);
    }
658440
protected function addSequentialNode(DOMElement $element, $value)
    {
        if (empty($element->nodeValue)) {
            $element->nodeValue = htmlspecialchars($value);

            return;
        }

        $child = $element->cloneNode();
        $child->nodeValue = htmlspecialchars($value);
        $element->parentNode->appendChild($child);
    }
1018382
protected function XMLAppend(\DOMNode &$parent = null, $content = null)
	{
		if (is_null($parent)) {
			$parent = $this->root;
		}
		if (
			is_string($content)
			or is_numeric($content)
			or (is_object($content) and method_exists($content, '__toString'))
		) {
			$parent->appendChild($this->createTextNode("$content"));
		} elseif (
			is_object($content)
			and is_subclass_of($content, '\DOMNode')
		) {
			$parent->appendChild($content);
		} elseif (
			is_array($content)
			or (is_object($content) and $content = get_object_vars($content))
		) {
			array_map(
				function($node, $value) use (&$parent){
					if (is_string($node)) {
						if (substr($node, 0, 1) === '@') {
							$parent->setAttribute(substr($node, 1), $value);
						} else {
							$node = $parent->appendChild($this->createElement($node));
							if (is_string($value)) {
								$this->XMLAppend(
									$node,
									$this->createTextNode($value)
								);
							} else {
								$this->XMLAppend($node, $value);
							}
						}
					} else {
						$this->XMLAppend($parent, $value);
					}
				},
				array_keys($content),
				array_values($content)
			);
		} elseif (is_bool($content)) {
			$parent->appendChild(
				$this->createTextNode($content ? 'true' : 'false')
			);
		} else {
			throw new \InvalidArgumentException(
				sprintf(
					'Unable to append unknown content [%s] to %s',
					get_class($content),
					get_class($this)
				)
			);
		}

		return $this;
	}
346885
public function makeChild(array $attributes=[], Node $parent)
    {
        $child = $this->make($attributes);

        $child[$this->getParentIdName()] = $parent->getId();
        $child[$this->getRootIdName()] = $parent[$this->getRootIdName()];

        $child->setParent($parent);

        return $child;
    }
123029
protected function addCollectionNode(DOMElement $element, $value)
    {
        if ($element->childNodes->length == 0) {
            $this->convertElement($element, $value);

            return;
        }

        $child = $element->cloneNode();
        $element->parentNode->appendChild($child);
        $this->convertElement($child, $value);
    }
909599
public function toXML(\DOMNode $parentElement = null) : DOMElement
    {
        if ($parentElement === null) {
            $document = DOMDocumentFactory::create();
            $parentElement = $document;
        } else {
            $document = $parentElement->ownerDocument;
        }

        $root = $document->createElementNS(Constants::NS_SAML, 'saml:'.'Assertion');
        $parentElement->appendChild($root);

        /* Ugly hack to add another namespace declaration to the root element. */
        $root->setAttributeNS(Constants::NS_SAMLP, 'samlp:tmp', 'tmp');
        $root->removeAttributeNS(Constants::NS_SAMLP, 'tmp');
        $root->setAttributeNS(Constants::NS_XSI, 'xsi:tmp', 'tmp');
        $root->removeAttributeNS(Constants::NS_XSI, 'tmp');
        $root->setAttributeNS(Constants::NS_XS, 'xs:tmp', 'tmp');
        $root->removeAttributeNS(Constants::NS_XS, 'tmp');

        $root->setAttribute('ID', $this->id);
        $root->setAttribute('Version', '2.0');
        $root->setAttribute('IssueInstant', gmdate('Y-m-d\TH:i:s\Z', $this->issueInstant));

        $issuer = $this->issuer->toXML($root);

        $this->addSubject($root);
        $this->addConditions($root);
        $this->addAuthnStatement($root);
        if ($this->getRequiredEncAttributes() === false) {
            $this->addAttributeStatement($root);
        } else {
            $this->addEncryptedAttributeStatement($root);
        }

        if ($this->signatureKey !== null) {
            Utils::insertSignature($this->signatureKey, $this->certificates, $root, $issuer->nextSibling);
        }

        return $root;
    }
800688
public function toXML(DOMElement $parent = null) : DOMElement
    {
        $element = parent::toXML($parent);

        if ($this->Format !== null) {
            $element->setAttribute('Format', $this->Format);
        }

        if ($this->SPProvidedID !== null) {
            $element->setAttribute('SPProvidedID', $this->SPProvidedID);
        }

        $value = $element->ownerDocument->createTextNode($this->value);
        $element->appendChild($value);

        return $element;
    }
812059
protected function performCreateChildOf(array $attributes, Node $parent)
    {

        $parentIdName = $this->getParentIdName();
        $rootIdName = $this->getRootIdName();

        $child = $this->make($attributes);
        $child[$parentIdName] = $parent->getId();
        $child[$rootIdName] = $parent[$rootIdName];

        $child->save();

        // Set in-memory relations
        $child->setParent($parent);
        $parent->addChild($child);

        return $child;

    }