Xml.php
public static function build($input, array $options = [])
    {
        if (!\is_array($options)) {
            $options = ['return' => (string)$options];
        }
        $defaults = [
            'return' => 'simplexml',
        ];
        $options = array_merge($defaults, $options);

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

        if (strpos($input, '<') !== false) {
            if ($options['return'] === 'simplexml' || $options['return'] === 'simplexmlelement') {
                return new \SimpleXMLElement($input, LIBXML_NOCDATA);
            }
            $dom = new \DOMDocument();
            $dom->loadXML($input);

            return $dom;
        }

        if (file_exists($input) || strpos($input, 'http://') === 0 || strpos($input, 'https://') === 0) {
            if ($options['return'] === 'simplexml' || $options['return'] === 'simplexmlelement') {
                return new \SimpleXMLElement($input, LIBXML_NOCDATA, true);
            }
            $dom = new \DOMDocument();
            $dom->load($input);

            return $dom;
        }

        if (!\is_string($input)) {
            throw new \RuntimeException(Tools::poorManTranslate('fts-shared', 'Invalid input.'));
        }
        throw new \RuntimeException(Tools::poorManTranslate('fts-shared', 'XML cannot be read.'));
    }
public static function build($input, array $options = [])
    {
        if (!\is_array($options)) {
            $options = ['return' => (string)$options];
        }
        $defaults = [
            'return' => 'simplexml',
        ];
        $options = array_merge($defaults, $options);

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

        if (strpos($input, '<') !== false) {
            if ($options['return'] === 'simplexml' || $options['return'] === 'simplexmlelement') {
                return new \SimpleXMLElement($input, LIBXML_NOCDATA);
            }
            $dom = new \DOMDocument();
            $dom->loadXML($input);

            return $dom;
        }

        if (file_exists($input) || strpos($input, 'http://') === 0 || strpos($input, 'https://') === 0) {
            if ($options['return'] === 'simplexml' || $options['return'] === 'simplexmlelement') {
                return new \SimpleXMLElement($input, LIBXML_NOCDATA, true);
            }
            $dom = new \DOMDocument();
            $dom->load($input);

            return $dom;
        }

        if (!\is_string($input)) {
            throw new \RuntimeException(Tools::poorManTranslate('fts-shared', 'Invalid input.'));
        }
        throw new \RuntimeException(Tools::poorManTranslate('fts-shared', '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>', array('return' => 'domdocument'));`

Building XML from a file path:

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

Building from a remote URL:

`$xml = Xml::build('http://example.com/example.xml');`

Building from an array:

{{{
$value = array(
'tags' => array(
'tag' => array(
array(
'id' => '1',
'name' => 'defect'
),
array(
'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.
- If using array as input, you can pass `options` from Xml::fromArray.

@param mixed $input XML string, a path to a file, an URL or an array
@param array $options The options to use
@return \SimpleXMLElement|\DOMDocument SimpleXMLElement or DOMDocument
@throws \RuntimeException