original_string: protected static function _fromArray($dom, $node, &$data, $format)
      {
          if (empty($data) || !is_array($data)) {
              return;
          }
          foreach ($data as $key => $value) {
              if (is_string($key)) {
                  if (is_object($value) && method_exists($value, 'toArray') && is_callable([$value, 'toArray'])) {
                      $value = call_user_func([$value, 'toArray']);
                  }
  
                  if (!is_array($value)) {
                      if (is_bool($value)) {
                          $value = (int)$value;
                      } elseif ($value === null) {
                          $value = '';
                      }
                      $isNamespace = strpos($key, 'xmlns:');
                      if ($isNamespace !== false) {
                          $node->setAttributeNS('http://www.w3.org/2000/xmlns/', $key, $value);
                          continue;
                      }
                      if ($key[0] !== '@' && $format === 'tags') {
                          if (!is_numeric($value)) {
                              // Escape special characters
                              // https://www.w3.org/TR/REC-xml/#syntax
                              // https://bugs.php.net/bug.php?id=36795
                              $child = $dom->createElement($key, '');
                              $child->appendChild(new DOMText($value));
                          } else {
                              $child = $dom->createElement($key, $value);
                          }
                          $node->appendChild($child);
                      } else {
                          if ($key[0] === '@') {
                              $key = substr($key, 1);
                          }
                          $attribute = $dom->createAttribute($key);
                          $attribute->appendChild($dom->createTextNode($value));
                          $node->appendChild($attribute);
                      }
                  } else {
                      if ($key[0] === '@') {
                          throw new XmlException('Invalid array');
                      }
                      if (is_numeric(implode('', array_keys($value)))) {
  // List
                          foreach ($value as $item) {
                              $itemData = compact('dom', 'node', 'key', 'format');
                              $itemData['value'] = $item;
                              static::_createChild($itemData);
                          }
                      } else {
  // Struct
                          static::_createChild(compact('dom', 'node', 'key', 'value', 'format'));
                      }
                  }
              } else {
                  throw new XmlException('Invalid array');
              }
          }
      }
code: protected static function _fromArray($dom, $node, &$data, $format)
      {
          if (empty($data) || !is_array($data)) {
              return;
          }
          foreach ($data as $key => $value) {
              if (is_string($key)) {
                  if (is_object($value) && method_exists($value, 'toArray') && is_callable([$value, 'toArray'])) {
                      $value = call_user_func([$value, 'toArray']);
                  }
  
                  if (!is_array($value)) {
                      if (is_bool($value)) {
                          $value = (int)$value;
                      } elseif ($value === null) {
                          $value = '';
                      }
                      $isNamespace = strpos($key, 'xmlns:');
                      if ($isNamespace !== false) {
                          $node->setAttributeNS('http://www.w3.org/2000/xmlns/', $key, $value);
                          continue;
                      }
                      if ($key[0] !== '@' && $format === 'tags') {
                          if (!is_numeric($value)) {
                              // Escape special characters
                              // https://www.w3.org/TR/REC-xml/#syntax
                              // https://bugs.php.net/bug.php?id=36795
                              $child = $dom->createElement($key, '');
                              $child->appendChild(new DOMText($value));
                          } else {
                              $child = $dom->createElement($key, $value);
                          }
                          $node->appendChild($child);
                      } else {
                          if ($key[0] === '@') {
                              $key = substr($key, 1);
                          }
                          $attribute = $dom->createAttribute($key);
                          $attribute->appendChild($dom->createTextNode($value));
                          $node->appendChild($attribute);
                      }
                  } else {
                      if ($key[0] === '@') {
                          throw new XmlException('Invalid array');
                      }
                      if (is_numeric(implode('', array_keys($value)))) {
  // List
                          foreach ($value as $item) {
                              $itemData = compact('dom', 'node', 'key', 'format');
                              $itemData['value'] = $item;
                              static::_createChild($itemData);
                          }
                      } else {
  // Struct
                          static::_createChild(compact('dom', 'node', 'key', 'value', 'format'));
                      }
                  }
              } else {
                  throw new XmlException('Invalid array');
              }
          }
      }
code_tokens: protected static function _fromArray ( $ dom , $ node , & $ data , $ format ) { if ( empty ( $ data ) || ! is_array ( $ data ) ) { return ; } foreach ( $ data as $ key => $ value ) { if ( is_string ( $ key ) ) { if ( is_object ( $ value ) && method_exists ( $ value , 'toArray' ) && is_callable ( [ $ value , 'toArray' ] ) ) { $ value = call_user_func ( [ $ value , 'toArray' ] ) ; } if ( ! is_array ( $ value ) ) { if ( is_bool ( $ value ) ) { $ value = ( int ) $ value ; } elseif ( $ value === null ) { $ value = '' ; } $ isNamespace = strpos ( $ key , 'xmlns:' ) ; if ( $ isNamespace !== false ) { $ node -> setAttributeNS ( 'http://www.w3.org/2000/xmlns/' , $ key , $ value ) ; continue ; } if ( $ key [ 0 ] !== '@' && $ format === 'tags' ) { if ( ! is_numeric ( $ value ) ) { // Escape special characters // https://www.w3.org/TR/REC-xml/#syntax // https://bugs.php.net/bug.php?id=36795 $ child = $ dom -> createElement ( $ key , '' ) ; $ child -> appendChild ( new DOMText ( $ value ) ) ; } else { $ child = $ dom -> createElement ( $ key , $ value ) ; } $ node -> appendChild ( $ child ) ; } else { if ( $ key [ 0 ] === '@' ) { $ key = substr ( $ key , 1 ) ; } $ attribute = $ dom -> createAttribute ( $ key ) ; $ attribute -> appendChild ( $ dom -> createTextNode ( $ value ) ) ; $ node -> appendChild ( $ attribute ) ; } } else { if ( $ key [ 0 ] === '@' ) { throw new XmlException ( 'Invalid array' ) ; } if ( is_numeric ( implode ( '' , array_keys ( $ value ) ) ) ) { // List foreach ( $ value as $ item ) { $ itemData = compact ( 'dom' , 'node' , 'key' , 'format' ) ; $ itemData [ 'value' ] = $ item ; static :: _createChild ( $ itemData ) ; } } else { // Struct static :: _createChild ( compact ( 'dom' , 'node' , 'key' , 'value' , 'format' ) ) ; } } } else { throw new XmlException ( 'Invalid array' ) ; } } }
docstring: Recursive method to create childs from array
  
  @param \DOMDocument $dom Handler to DOMDocument
  @param \DOMElement $node Handler to DOMElement (child)
  @param array $data Array of data to append to the $node.
  @param string $format Either 'attributes' or 'tags'. This determines where nested keys go.
  @return void
  @throws \Cake\Utility\Exception\XmlException
docstring_tokens: Recursive method to create childs from array