Trying to use SimpleXMLElement


I am trying to use:

“$xml = new SimpleXMLElement($variableWhichHoldsFile);”

and implemented

use Symfony\Component\DependencyInjection;
use Symfony\Component\DependencyInjection\SimpleXMLElement;

SimpleXML is installed and enabled (checked php info) but I permanently got following error:

Attempted to load class “SimpleXMLElement” from namespace “Symfony\Component\DependencyInjection”. Did you forget a “use” statement for another namespace?

Server threw exception - could not perform action. Please reload the admin interface and try again.

Use \SimpleXMLElement instead of Symfony\Component\DependencyInjection\SimpleXMLElement.
So your code would look something like this:

use SimpleXMLElement;

class MyXmlProcessingClass
    public function someMethodName()
        $file = // ...
        $xml = new SimpleXMLElement($file);
1 Like