original_string: protected function _arrayToXml($data, Xml $xml, $addCdata, $parent)
      {
          foreach ($data as $key => $value) {
              $key        = str_replace(' ', '_', $key);
              $attributes = [];
              $data       = '';
  
              if (is_object($value)) {
                  try {
                      $data = Serializer::serialize($value);
                  } catch (ExceptionInterface $exception) {
                      $this->_addException($exception);
                  }
  
                  $value = [
                      '@attributes' => ['serialized_object' => true],
                      $data
                  ];
              }
  
              try {
                  $isArray = is_array($value);
  
                  if ($isArray && array_key_exists('@attributes', $value)) {
                      $attributes = $value['@attributes'];
                      unset ($value['@attributes']);
                  }
  
                  if ($isArray) {
                      $parent = $this->_convertArrayDataToXml(
                          $value,
                          $addCdata,
                          $xml,
                          $key,
                          $parent,
                          $attributes
                      );
                      continue;
                  }
  
                  $element = $this->_appendDataToNode($addCdata, $xml, $key, $value);
                  $parent->appendChild($element);
  
              } catch (DOMException $exception) {
                  $this->_addException($exception);
              }
          }
  
          return $xml;
      }
code: protected function _arrayToXml($data, Xml $xml, $addCdata, $parent)
      {
          foreach ($data as $key => $value) {
              $key        = str_replace(' ', '_', $key);
              $attributes = [];
              $data       = '';
  
              if (is_object($value)) {
                  try {
                      $data = Serializer::serialize($value);
                  } catch (ExceptionInterface $exception) {
                      $this->_addException($exception);
                  }
  
                  $value = [
                      '@attributes' => ['serialized_object' => true],
                      $data
                  ];
              }
  
              try {
                  $isArray = is_array($value);
  
                  if ($isArray && array_key_exists('@attributes', $value)) {
                      $attributes = $value['@attributes'];
                      unset ($value['@attributes']);
                  }
  
                  if ($isArray) {
                      $parent = $this->_convertArrayDataToXml(
                          $value,
                          $addCdata,
                          $xml,
                          $key,
                          $parent,
                          $attributes
                      );
                      continue;
                  }
  
                  $element = $this->_appendDataToNode($addCdata, $xml, $key, $value);
                  $parent->appendChild($element);
  
              } catch (DOMException $exception) {
                  $this->_addException($exception);
              }
          }
  
          return $xml;
      }
code_tokens: protected function _arrayToXml ( $ data , Xml $ xml , $ addCdata , $ parent ) { foreach ( $ data as $ key => $ value ) { $ key = str_replace ( ' ' , '_' , $ key ) ; $ attributes = [ ] ; $ data = '' ; if ( is_object ( $ value ) ) { try { $ data = Serializer :: serialize ( $ value ) ; } catch ( ExceptionInterface $ exception ) { $ this -> _addException ( $ exception ) ; } $ value = [ '@attributes' => [ 'serialized_object' => true ] , $ data ] ; } try { $ isArray = is_array ( $ value ) ; if ( $ isArray && array_key_exists ( '@attributes' , $ value ) ) { $ attributes = $ value [ '@attributes' ] ; unset ( $ value [ '@attributes' ] ) ; } if ( $ isArray ) { $ parent = $ this -> _convertArrayDataToXml ( $ value , $ addCdata , $ xml , $ key , $ parent , $ attributes ) ; continue ; } $ element = $ this -> _appendDataToNode ( $ addCdata , $ xml , $ key , $ value ) ; $ parent -> appendChild ( $ element ) ; } catch ( DOMException $ exception ) { $ this -> _addException ( $ exception ) ; } } return $ xml ; }
docstring: recursive method to create structure xml structure of object DATA
  
  @param $data
  @param Xml $xml
  @param boolean $addCdata
  @param Xml|DOMElement $parent
  @return Xml
docstring_tokens: recursive method to create structure xml structure of object DATA