public static function build($input, array $options = [])
    {
        $defaults = [
            'return' => 'simplexml',
            'loadEntities' => false,
            'readFile' => true,
            'parseHuge' => false,
        ];
        $options += $defaults;

        if (is_array($input) || is_object($input)) {
            return static::fromArray($input, $options);
        }

        if (strpos($input, '<') !== false) {
            return static::_loadXml($input, $options);
        }

        if ($options['readFile'] && file_exists($input)) {
            return static::_loadXml(file_get_contents($input), $options);
        }

        if (!is_string($input)) {
            throw new XmlException('Invalid input.');
        }

        throw new XmlException('XML cannot be read.');
    }
public static function build($input, array $options = [])
    {
        $defaults = [
            'return' => 'simplexml',
            'loadEntities' => false,
            'readFile' => true,
            'parseHuge' => false,
        ];
        $options += $defaults;

        if (is_array($input) || is_object($input)) {
            return static::fromArray($input, $options);
        }

        if (strpos($input, '<') !== false) {
            return static::_loadXml($input, $options);
        }

        if ($options['readFile'] && file_exists($input)) {
            return static::_loadXml(file_get_contents($input), $options);
        }

        if (!is_string($input)) {
            throw new XmlException('Invalid input.');
        }

        throw new XmlException('XML cannot be read.');
    }
public static function build ( $ input , array $ options = [ ] ) { $ defaults = [ 'return' => 'simplexml' , 'loadEntities' => false , 'readFile' => true , 'parseHuge' => false , ] ; $ options += $ defaults ; if ( is_array ( $ input ) || is_object ( $ input ) ) { return static :: fromArray ( $ input , $ options ) ; } if ( strpos ( $ input , '<' ) !== false ) { return static :: _loadXml ( $ input , $ options ) ; } if ( $ options [ 'readFile' ] && file_exists ( $ input ) ) { return static :: _loadXml ( file_get_contents ( $ input ) , $ options ) ; } if ( ! is_string ( $ input ) ) { throw new XmlException ( 'Invalid input.' ) ; } throw new XmlException ( 'XML cannot be read.' ) ; }
Initialize SimpleXMLElement or DOMDocument from a given XML string, file path, URL or array.

### Usage:

Building XML from a string:

```
$xml = Xml::build('<example>text</example>');
```

Building XML from string (output DOMDocument):

```
$xml = Xml::build('<example>text</example>', ['return' => 'domdocument']);
```

Building XML from a file path:

```
$xml = Xml::build('/path/to/an/xml/file.xml');
```

Building XML from a remote URL:

```
use Cake\Http\Client;

$http = new Client();
$response = $http->get('http://example.com/example.xml');
$xml = Xml::build($response->body());
```

Building from an array:

```
$value = [
'tags' => [
'tag' => [
[
'id' => '1',
'name' => 'defect'
],
[
'id' => '2',
'name' => 'enhancement'
]
]
]
];
$xml = Xml::build($value);
```

When building XML from an array ensure that there is only one top level element.

### Options

- `return` Can be 'simplexml' to return object of SimpleXMLElement or 'domdocument' to return DOMDocument.
- `loadEntities` Defaults to false. Set to true to enable loading of `<!ENTITY` definitions. This
is disabled by default for security reasons.
- `readFile` Set to false to disable file reading. This is important to disable when
putting user data into Xml::build(). If enabled local files will be read if they exist.
Defaults to true for backwards compatibility reasons.
- `parseHuge` Enable the `LIBXML_PARSEHUGE` flag.

If using array as input, you can pass `options` from Xml::fromArray.

@param string|array $input XML string, a path to a file, a URL or an array
@param array $options The options to use
@return \SimpleXMLElement|\DOMDocument SimpleXMLElement or DOMDocument
@throws \Cake\Utility\Exception\XmlException
Initialize SimpleXMLElement or DOMDocument from a given XML string file path URL or array .