protected static function _loadXml($input, $options)
    {
        $hasDisable = function_exists('libxml_disable_entity_loader');
        $internalErrors = libxml_use_internal_errors(true);
        if ($hasDisable && !$options['loadEntities']) {
            libxml_disable_entity_loader(true);
        }
        $flags = 0;
        if (!empty($options['parseHuge'])) {
            $flags |= LIBXML_PARSEHUGE;
        }
        try {
            if ($options['return'] === 'simplexml' || $options['return'] === 'simplexmlelement') {
                $flags |= LIBXML_NOCDATA;
                $xml = new SimpleXMLElement($input, $flags);
            } else {
                $xml = new DOMDocument();
                $xml->loadXML($input, $flags);
            }

            return $xml;
        } catch (Exception $e) {
            throw new XmlException('Xml cannot be read. ' . $e->getMessage(), null, $e);
        } finally {
            if ($hasDisable && !$options['loadEntities']) {
                libxml_disable_entity_loader(false);
            }
            libxml_use_internal_errors($internalErrors);
        }
    }