Hello,

This issue is coming when i update drupal core to 8.4.2.

In my custom module I used SimpleXmlElement to fetch xml content. That's why I used "Symfony\Component\DependencyInjection" namespace. But when i updated the drupal core I got "Class 'Symfony\Component\DependencyInjection\SimpleXMLElement' not found" PHP Fatal error.

I found that SimpleXMLElement.php is missing in "vendor/symfony/dependency-injection" folder.
So,I manually added SimpleXMLElement.php in this folder, then the error was gone. But I know this is not a solution.
I have searched a lot but couldn't able to know why it's deprecated on drupal 8.4.2.

Can anyone advise how to use SimpleXMLElement to fetch XML object as in Drupal 8.4.2's code, or is there any other replacement for it?

Thanks in advance.

Comments

SohiniCP created an issue. See original summary.

cilefen’s picture

Title: Class 'Symfony\Component\DependencyInjection\SimpleXMLElement' not found » Class 'Symfony\Component\DependencyInjection\SimpleXMLElement' not found by custom module
dawehner’s picture

In my custom module I used SimpleXmlElement to fetch xml content. That's why I used "Symfony\Component\DependencyInjection" namespace. But when i updated the drupal core I got "Class 'Symfony\Component\DependencyInjection\SimpleXMLElement' not found" PHP Fatal error.

Do you mind showing your code, like for example the services.yml file? Otherwise its a bit tough to really help, beside providing some random guessing.

sohinicp’s picture

Ok. My requirement is very simple just want to read the rss feed & put it in the array.
Here is my code ->
I have created the functionality on Controller.php file

namespace Drupal\custom_job\Controller;
use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\DependencyInjection;
use Symfony\Component\DependencyInjection\SimpleXMLElement;

class AdminPage extends ControllerBase {
public function getJobDetails() {
$xmlUrl = "http://XXX/rss/"; // XML feed file/URL
$content = file_get_contents($xmlUrl);
if ($content == '') {
return '';
}
else {
$x = new SimpleXmlElement($content);
$i = 0;
foreach ($x->channel->item as $entry) {
$temp = (string) $entry->category;
$data[$i]['category'] = $temp;
.........
}
}
}
}

I got the above error when i updated drupal core to 8.4.2.

Thank you!

dawehner’s picture

Here is the code which probably would work:

namespace Drupal\custom_job\Controller;
use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\DependencyInjection;

class AdminPage extends ControllerBase {
public function getJobDetails() {
$xmlUrl = "http://XXX/rss/"; // XML feed file/URL
$content = file_get_contents($xmlUrl);
if ($content == '') {
return '';
}
else {
$x = new \SimpleXmlElement($content);
$i = 0;
foreach ($x->channel->item as $entry) {
$temp = (string) $entry->category;
$data[$i]['category'] = $temp;
.........
}
}
}
}
sohinicp’s picture

Ohh! it works. Thanks a lot @dawehner

cilefen’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.