public function fromXml(string $xml): array
    {
        if (!$this->isEmptyValue($xml)) {

            libxml_use_internal_errors(true);

            // convert string to xml object
            $result = simplexml_load_string("$xml", 'SimpleXMLElement', LIBXML_NOCDATA);

            if ($result) {
                return $this->fromClass($result);

            } else {

                foreach (libxml_get_errors() as $error) {

                    // if don`t have container add that`s
                    if ($error->code == 5) {
                        $this->errors = [];

                        // append container and parse again
                        return $this->fromXml("<DATA>$xml</DATA>");

                    } else
                        $this->setError($error->code, $error->message);
                }
            }
        }

        return $this->result;
    }
public function fromXml(string $xml): array
    {
        if (!$this->isEmptyValue($xml)) {

            libxml_use_internal_errors(true);

            // convert string to xml object
            $result = simplexml_load_string("$xml", 'SimpleXMLElement', LIBXML_NOCDATA);

            if ($result) {
                return $this->fromClass($result);

            } else {

                foreach (libxml_get_errors() as $error) {

                    // if don`t have container add that`s
                    if ($error->code == 5) {
                        $this->errors = [];

                        // append container and parse again
                        return $this->fromXml("<DATA>$xml</DATA>");

                    } else
                        $this->setError($error->code, $error->message);
                }
            }
        }

        return $this->result;
    }
public function fromXml ( string $ xml ) : array { if ( ! $ this -> isEmptyValue ( $ xml ) ) { libxml_use_internal_errors ( true ) ; // convert string to xml object $ result = simplexml_load_string ( "$xml" , 'SimpleXMLElement' , LIBXML_NOCDATA ) ; if ( $ result ) { return $ this -> fromClass ( $ result ) ; } else { foreach ( libxml_get_errors ( ) as $ error ) { // if don`t have container add that`s if ( $ error -> code == 5 ) { $ this -> errors = [ ] ; // append container and parse again return $ this -> fromXml ( "<DATA>$xml</DATA>" ) ; } else $ this -> setError ( $ error -> code , $ error -> message ) ; } } } return $ this -> result ; }
Convert xml to array

@param string $xml
@return array|mixed
Convert xml to array