Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Xml.php
Go to the documentation of this file.
1 <?php
7 
9 
15 class Xml implements ConverterInterface
16 {
23  private function convertNode(\DOMNode $source)
24  {
25  $result = [];
26  if ($source->hasAttributes()) {
27  $attrs = $source->attributes;
28  foreach ($attrs as $attr) {
29  $result[$attr->name] = $attr->value;
30  }
31  }
32  if ($source->hasChildNodes()) {
33  $children = $source->childNodes;
34  if ($children->length == 1) {
35  $child = $children->item(0);
36  if ($child->nodeType == XML_TEXT_NODE) {
37  $result['_value'] = $child->nodeValue;
38  return count($result) == 1 ? $result['_value'] : $result;
39  }
40  }
41  foreach ($children as $child) {
42  if ($child instanceof \DOMCharacterData) {
43  continue;
44  }
45  $result[$child->nodeName][] = $this->convertNode($child);
46  }
47  }
48  return $result;
49  }
50 
57  public function convert($source)
58  {
59  return $this->convertNode($source);
60  }
61 }
$attr
Definition: text.phtml:8
$source
Definition: source.php:23
$children
Definition: actions.phtml:11