protected function Xliff::getImportedXML

Returns the simple XMLElement object.

Parameters

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.

Return value

bool|\SimpleXMLElement The parsed SimpleXMLElement object. FALSE in case of failed parsing.

2 calls to Xliff::getImportedXML()
Xliff::import in translators/tmgmt_file/src/Plugin/tmgmt_file/Format/Xliff.php
Converts an exported file content back to the translated data.
Xliff::validateImport in translators/tmgmt_file/src/Plugin/tmgmt_file/Format/Xliff.php
Validates that the given file is valid and can be imported.

File

translators/tmgmt_file/src/Plugin/tmgmt_file/Format/Xliff.php, line 363

Class

Xliff
Export to XLIFF format.

Namespace

Drupal\tmgmt_file\Plugin\tmgmt_file\Format

Code

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;
}