original_string: public static function fromArray($input, $options = [])
      {
          if (is_object($input) && method_exists($input, 'toArray') && is_callable([$input, 'toArray'])) {
              $input = call_user_func([$input, 'toArray']);
          }
          if (!is_array($input) || count($input) !== 1) {
              throw new XmlException('Invalid input.');
          }
          $key = key($input);
          if (is_int($key)) {
              throw new XmlException('The key of input must be alphanumeric');
          }
  
          if (!is_array($options)) {
              $options = ['format' => (string)$options];
          }
          $defaults = [
              'format' => 'tags',
              'version' => '1.0',
              'encoding' => mb_internal_encoding(),
              'return' => 'simplexml',
              'pretty' => false
          ];
          $options += $defaults;
  
          $dom = new DOMDocument($options['version'], $options['encoding']);
          if ($options['pretty']) {
              $dom->formatOutput = true;
          }
          self::_fromArray($dom, $dom, $input, $options['format']);
  
          $options['return'] = strtolower($options['return']);
          if ($options['return'] === 'simplexml' || $options['return'] === 'simplexmlelement') {
              return new SimpleXMLElement($dom->saveXML());
          }
  
          return $dom;
      }
code: public static function fromArray($input, $options = [])
      {
          if (is_object($input) && method_exists($input, 'toArray') && is_callable([$input, 'toArray'])) {
              $input = call_user_func([$input, 'toArray']);
          }
          if (!is_array($input) || count($input) !== 1) {
              throw new XmlException('Invalid input.');
          }
          $key = key($input);
          if (is_int($key)) {
              throw new XmlException('The key of input must be alphanumeric');
          }
  
          if (!is_array($options)) {
              $options = ['format' => (string)$options];
          }
          $defaults = [
              'format' => 'tags',
              'version' => '1.0',
              'encoding' => mb_internal_encoding(),
              'return' => 'simplexml',
              'pretty' => false
          ];
          $options += $defaults;
  
          $dom = new DOMDocument($options['version'], $options['encoding']);
          if ($options['pretty']) {
              $dom->formatOutput = true;
          }
          self::_fromArray($dom, $dom, $input, $options['format']);
  
          $options['return'] = strtolower($options['return']);
          if ($options['return'] === 'simplexml' || $options['return'] === 'simplexmlelement') {
              return new SimpleXMLElement($dom->saveXML());
          }
  
          return $dom;
      }
code_tokens: public static function fromArray ( $ input , $ options = [ ] ) { if ( is_object ( $ input ) && method_exists ( $ input , 'toArray' ) && is_callable ( [ $ input , 'toArray' ] ) ) { $ input = call_user_func ( [ $ input , 'toArray' ] ) ; } if ( ! is_array ( $ input ) || count ( $ input ) !== 1 ) { throw new XmlException ( 'Invalid input.' ) ; } $ key = key ( $ input ) ; if ( is_int ( $ key ) ) { throw new XmlException ( 'The key of input must be alphanumeric' ) ; } if ( ! is_array ( $ options ) ) { $ options = [ 'format' => ( string ) $ options ] ; } $ defaults = [ 'format' => 'tags' , 'version' => '1.0' , 'encoding' => mb_internal_encoding ( ) , 'return' => 'simplexml' , 'pretty' => false ] ; $ options += $ defaults ; $ dom = new DOMDocument ( $ options [ 'version' ] , $ options [ 'encoding' ] ) ; if ( $ options [ 'pretty' ] ) { $ dom -> formatOutput = true ; } self :: _fromArray ( $ dom , $ dom , $ input , $ options [ 'format' ] ) ; $ options [ 'return' ] = strtolower ( $ options [ 'return' ] ) ; if ( $ options [ 'return' ] === 'simplexml' || $ options [ 'return' ] === 'simplexmlelement' ) { return new SimpleXMLElement ( $ dom -> saveXML ( ) ) ; } return $ dom ; }
docstring: Transform an array into a SimpleXMLElement
  
  ### Options
  
  - `format` If create childs ('tags') or attributes ('attributes').
  - `pretty` Returns formatted Xml when set to `true`. Defaults to `false`
  - `version` Version of XML document. Default is 1.0.
  - `encoding` Encoding of XML document. If null remove from XML header. Default is the some of application.
  - `return` If return object of SimpleXMLElement ('simplexml') or DOMDocument ('domdocument'). Default is SimpleXMLElement.
  
  Using the following data:
  
  ```
  $value = [
  'root' => [
  'tag' => [
  'id' => 1,
  'value' => 'defect',
  '@' => 'description'
  ]
  ]
  ];
  ```
  
  Calling `Xml::fromArray($value, 'tags');` Will generate:
  
  `<root><tag><id>1</id><value>defect</value>description</tag></root>`
  
  And calling `Xml::fromArray($value, 'attributes');` Will generate:
  
  `<root><tag id="1" value="defect">description</tag></root>`
  
  @param array|\Cake\Collection\Collection $input Array with data or a collection instance.
  @param string|array $options The options to use or a string to use as format.
  @return \SimpleXMLElement|\DOMDocument SimpleXMLElement or DOMDocument
  @throws \Cake\Utility\Exception\XmlException
docstring_tokens: Transform an array into a SimpleXMLElement