public function loadContent(string $content)
    {
        // run this method with libxml internal errors enabled
        if (true !== libxml_use_internal_errors(true)) {
            try {
                $this->loadContent($content);
            } finally {
                libxml_use_internal_errors(false);
            }
        }

        libxml_clear_errors(); // clear previous libxml errors
        $dom = new DOMDocument();
        @$dom->loadXML($content, LIBXML_NOWARNING | LIBXML_NONET);
        if (false !== $loaderror = libxml_get_last_error()) {
            libxml_clear_errors();  // clear recently libxml errors
            throw new CFDICleanerException('XML Error: ' . $loaderror->message);
        }
        $prefix = $dom->lookupPrefix('http://www.sat.gob.mx/cfd/3');
        if (! $prefix) {
            throw new CFDICleanerException('The XML document is not a CFDI');
        }
        $version = $this->xpathQuery('/' . $prefix . ':Comprobante/@version', $dom->documentElement);
        if ($version->length != 1) {
            $version = $this->xpathQuery('/' . $prefix . ':Comprobante/@Version', $dom->documentElement);
        }
        if ($version->length != 1) {
            throw new CFDICleanerException('The XML document does not contains a version');
        }
        if (! $this->isVersionAllowed($version->item(0)->nodeValue)) {
            throw new CFDICleanerException(
                'The XML document version "' . $version->item(0)->nodeValue . '" is not compatible'
            );
        }
        $this->dom = $dom;
    }
public function loadContent(string $content)
    {
        // run this method with libxml internal errors enabled
        if (true !== libxml_use_internal_errors(true)) {
            try {
                $this->loadContent($content);
            } finally {
                libxml_use_internal_errors(false);
            }
        }

        libxml_clear_errors(); // clear previous libxml errors
        $dom = new DOMDocument();
        @$dom->loadXML($content, LIBXML_NOWARNING | LIBXML_NONET);
        if (false !== $loaderror = libxml_get_last_error()) {
            libxml_clear_errors();  // clear recently libxml errors
            throw new CFDICleanerException('XML Error: ' . $loaderror->message);
        }
        $prefix = $dom->lookupPrefix('http://www.sat.gob.mx/cfd/3');
        if (! $prefix) {
            throw new CFDICleanerException('The XML document is not a CFDI');
        }
        $version = $this->xpathQuery('/' . $prefix . ':Comprobante/@version', $dom->documentElement);
        if ($version->length != 1) {
            $version = $this->xpathQuery('/' . $prefix . ':Comprobante/@Version', $dom->documentElement);
        }
        if ($version->length != 1) {
            throw new CFDICleanerException('The XML document does not contains a version');
        }
        if (! $this->isVersionAllowed($version->item(0)->nodeValue)) {
            throw new CFDICleanerException(
                'The XML document version "' . $version->item(0)->nodeValue . '" is not compatible'
            );
        }
        $this->dom = $dom;
    }
public function loadContent ( string $ content ) { // run this method with libxml internal errors enabled if ( true !== libxml_use_internal_errors ( true ) ) { try { $ this -> loadContent ( $ content ) ; } finally { libxml_use_internal_errors ( false ) ; } } libxml_clear_errors ( ) ; // clear previous libxml errors $ dom = new DOMDocument ( ) ; @ $ dom -> loadXML ( $ content , LIBXML_NOWARNING | LIBXML_NONET ) ; if ( false !== $ loaderror = libxml_get_last_error ( ) ) { libxml_clear_errors ( ) ; // clear recently libxml errors throw new CFDICleanerException ( 'XML Error: ' . $ loaderror -> message ) ; } $ prefix = $ dom -> lookupPrefix ( 'http://www.sat.gob.mx/cfd/3' ) ; if ( ! $ prefix ) { throw new CFDICleanerException ( 'The XML document is not a CFDI' ) ; } $ version = $ this -> xpathQuery ( '/' . $ prefix . ':Comprobante/@version' , $ dom -> documentElement ) ; if ( $ version -> length != 1 ) { $ version = $ this -> xpathQuery ( '/' . $ prefix . ':Comprobante/@Version' , $ dom -> documentElement ) ; } if ( $ version -> length != 1 ) { throw new CFDICleanerException ( 'The XML document does not contains a version' ) ; } if ( ! $ this -> isVersionAllowed ( $ version -> item ( 0 ) -> nodeValue ) ) { throw new CFDICleanerException ( 'The XML document version "' . $ version -> item ( 0 ) -> nodeValue . '" is not compatible' ) ; } $ this -> dom = $ dom ; }
Load the string content as a CFDI
This is exposed to reuse the current object instead of create a new instance

@param string $content

@throws CFDICleanerException when the content is not valid xml
@throws CFDICleanerException when the document does not use the namespace http://www.sat.gob.mx/cfd/3
@throws CFDICleanerException when cannot find a Comprobante version (or Version) attribute
@throws CFDICleanerException when the version is not compatible

@return void
Load the string content as a CFDI This is exposed to reuse the current object instead of create a new instance