'); self::arrToXml($array, $xml_info); return $xml_info->asXML(); } /** * @return mixed[] */ protected static function structToArray(mixed $values, mixed &$i): array { $child = []; if (isset($values[$i]['value'])) { $child[] = $values[$i]['value']; } while ($i++ < count($values)) { switch ($values[$i]['type']) { case 'cdata': $child[] = $values[$i]['value']; break; case 'complete': $name = $values[$i]['tag']; if (!empty($name)) { $child[$name] = $values[$i]['attributes'] ?? (($values[$i]['value']) ?: ''); } break; case 'open': $name = $values[$i]['tag']; $size = isset($child[$name]) ? sizeof($child[$name]) : 0; $child[$name][$size] = self::structToArray($values, $i); break; case 'close': return $child; } } return $child; } /** @noinspection PhpParameterByRefIsNotUsedAsReferenceInspection */ protected static function arrToXml(array $array, SimpleXMLElement &$xml): void { foreach ($array as $key => $value) { $key = is_numeric($key) ? "item$key" : $key; if (is_array($value)) { $subnode = $xml->addChild((string)$key); self::arrToXml($value, $subnode); } else { $xml->addChild((string)$key, htmlspecialchars($value, ENT_QUOTES | ENT_HTML5)); } } } }