/** * @param $newData * @return DOMDocument * @throws Exception */ private static function makeDomFromNewData($newData) { $newXmlString = Dfi_Xml::castToXmlString($newData); $newXml = Dfi_Xml::asSimpleXml($newXmlString); $x = Dfi_Xml::asSimpleXml('<current></current>'); /** @var SimpleXMLElement $value */ foreach ($newXml as $key => $value) { if ((string) $value != '') { $x->addChild($key, $value); } } $newXml = $x; //new DOM document definition $dom = new DOMDocument(); $dom->formatOutput = true; $dom->preserveWhiteSpace = FALSE; $dom->encoding = 'UTF-8'; $newDataDom = dom_import_simplexml($newXml); $currentDom = $dom->createElement('data'); $dom->appendChild($currentDom); $newDataImported = $dom->importNode($newDataDom, true); $currentDom->appendChild($newDataImported); $x = $dom->saveXML($dom); return $dom; }