I am developing an application with php where I need to use XML files and transform them by using a XSL style sheet. To load the XML and XSL files I use the following:
$xsl = new DOMDocument();
$xsl->load("myxslfile.xsl"); // load XSL
$xml = new DOMDocument();
$xml->load("myxmlfile.xml"); // load XML
the problem is when running the code the next error appears:
Fatal error: Class 'MyDirectory\DOMDocument' not found in 'mydirectory'
Running phpinfo() I can see dom is intalled and enabled. I don’t know why I can’t run DOMDocument()
You are apparently using the namespace
MyDirectory. ButDOMDocumentis a class in the global namespace. To reference a class from the global namespace in a local namespace you have to use the Fully Qualified Name or import it into the local namespace:Fully Qualified Namespace:
Importing with
use