25 public function assocToXml(array $array, $rootName =
'_')
27 if (empty($rootName) || is_numeric($rootName)) {
30 "The root element can't be empty or use numbers. Change the element and try again." 36 <?xml version=
'1.0' encoding=
'UTF-8' standalone=
'yes'?>
37 <$rootName></$rootName>
39 $xml = new \SimpleXMLElement($xmlStr);
40 foreach (array_keys($array) as $key) {
41 if (is_numeric($key)) {
43 new \
Magento\Framework\
Phrase(
'An error occurred. Use non-numeric array root keys and try again.')
47 return self::_assocToXml($array, $rootName, $xml);
77 private function _assocToXml(array $array, $rootName, \SimpleXMLElement $xml)
79 $hasNumericKey =
false;
80 $hasStringKey =
false;
81 foreach ($array as $key =>
$value) {
83 if (is_string($key)) {
84 if ($key === $rootName) {
87 "An associative key can't be the same as its parent associative key. " 88 .
"Verify and try again." 93 $xml->addChild($key,
$value);
95 $hasNumericKey =
true;
96 $xml->addChild($key,
$value);
100 self::_assocToXml(
$value, $key, $xml->{$key});
103 if ($hasNumericKey && $hasStringKey) {
104 throw new LocalizedException(
106 "Associative and numeric keys can't be mixed at one level. Verify and try again."
elseif(isset( $params[ 'redirect_parent']))
static toFlatArray($data)
assocToXml(array $array, $rootName='_')