Returns the simple XMLElement object.
string $imported_file: Path to a file or an XML string to import.
bool $is_file: (optional) Whether $imported_file is the path to a file or not.
bool|\SimpleXMLElement The parsed SimpleXMLElement object. FALSE in case of failed parsing.
protected function getImportedXML($imported_file, $is_file = TRUE) {
if (empty($this->importedXML)) {
// It is not possible to load the file directly with simplexml as it gets
// url encoded due to the temporary://. This is a PHP bug, see
// https://bugs.php.net/bug.php?id=61469
if ($is_file) {
$imported_file = file_get_contents($imported_file);
}
$this->importedXML = simplexml_load_string($imported_file);
if ($this->importedXML === FALSE) {
$this
->messenger()
->addError(t('The imported file is not a valid XML.'));
return FALSE;
}
// Register the XLIFF namespace, required for xpath.
$this->importedXML
->registerXPathNamespace('xliff', 'urn:oasis:names:tc:xliff:document:1.2');
}
return $this->importedXML;
}