src/XmlUtil.php
public static function createXmlDocumentFromStr($xml, $docOptions = XMLUTIL_OPT_DONT_FIX_AMPERSAND)
    {
        set_error_handler(function ($number, $error) {
            $matches = [];
            if (preg_match('/^DOMDocument::loadXML\(\): (.+)$/', $error, $matches) === 1) {
                throw new \InvalidArgumentException("[Err #$number] ".$matches[1]);
            }
        });

        $xmldoc = self::createXmlDocument($docOptions);

        $xmlFixed = XmlUtil::fixXmlHeader($xml);
        if (($docOptions & XMLUTIL_OPT_DONT_FIX_AMPERSAND) != XMLUTIL_OPT_DONT_FIX_AMPERSAND) {
            $xmlFixed = str_replace("&amp;", "&", $xmlFixed);
        }

        $xmldoc->loadXML($xmlFixed);

        XmlUtil::extractNamespaces($xmldoc);

        restore_error_handler();

        return $xmldoc;
    }
public static function createXmlDocumentFromStr($xml, $docOptions = XMLUTIL_OPT_DONT_FIX_AMPERSAND)
    {
        set_error_handler(function ($number, $error) {
            $matches = [];
            if (preg_match('/^DOMDocument::loadXML\(\): (.+)$/', $error, $matches) === 1) {
                throw new \InvalidArgumentException("[Err #$number] ".$matches[1]);
            }
        });

        $xmldoc = self::createXmlDocument($docOptions);

        $xmlFixed = XmlUtil::fixXmlHeader($xml);
        if (($docOptions & XMLUTIL_OPT_DONT_FIX_AMPERSAND) != XMLUTIL_OPT_DONT_FIX_AMPERSAND) {
            $xmlFixed = str_replace("&amp;", "&", $xmlFixed);
        }

        $xmldoc->loadXML($xmlFixed);

        XmlUtil::extractNamespaces($xmldoc);

        restore_error_handler();

        return $xmldoc;
    }
public static function createXmlDocumentFromStr ( $ xml , $ docOptions = XMLUTIL_OPT_DONT_FIX_AMPERSAND ) { set_error_handler ( function ( $ number , $ error ) { $ matches = [ ] ; if ( preg_match ( '/^DOMDocument::loadXML\(\): (.+)$/' , $ error , $ matches ) === 1 ) { throw new \ InvalidArgumentException ( "[Err #$number] " . $ matches [ 1 ] ) ; } } ) ; $ xmldoc = self :: createXmlDocument ( $ docOptions ) ; $ xmlFixed = XmlUtil :: fixXmlHeader ( $ xml ) ; if ( ( $ docOptions & XMLUTIL_OPT_DONT_FIX_AMPERSAND ) != XMLUTIL_OPT_DONT_FIX_AMPERSAND ) { $ xmlFixed = str_replace ( "&amp;" , "&" , $ xmlFixed ) ; } $ xmldoc -> loadXML ( $ xmlFixed ) ; XmlUtil :: extractNamespaces ( $ xmldoc ) ; restore_error_handler ( ) ; return $ xmldoc ; }
Create XML \DOMDocument from a string

@param string $xml - XML string document
@param int $docOptions
@return DOMDocument
@throws \ByJG\Util\Exception\XmlUtilException
Create XML \ DOMDocument from a string