symfony/translation · error · InvalidArgumentException

Not a valid XLIFF namespace

Error message

Not a valid XLIFF namespace "%s".

What it means

Thrown by XliffUtils::getVersionNumber() when an XLIFF file's root element has an xmlns attribute that does not start with 'urn:oasis:names:tc:xliff:document:'. The XLIFF loader detects the version from this namespace to pick the right schema and parser.

Solutions

  1. Fix the root element namespace to urn:oasis:names:tc:xliff:document:1.2 or :2.0/:2.1/:2.2
  2. Re-export the file from the translation tool in a standard XLIFF format
  3. Validate the file against the XLIFF XSD before loading

Example fix

// before
<xliff xmlns="http://example.com/xliff" version="1.2">
// after
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2">
Defensive patterns

Strategy: validation

Validate before calling

$xml = simplexml_load_file($file);
$ns = (string) ($xml->getDocNamespaces()[''] ?? '');
if (!str_starts_with($ns, 'urn:oasis:names:tc:xliff:document:')) {
    throw new \InvalidArgumentException("{$file} is not standard XLIFF.");
}

Try / catch

try {
    $translator->getCatalogue($locale);
} catch (InvalidArgumentException $e) {
    if (str_contains($e->getMessage(), 'Not a valid XLIFF namespace')) {
        // fix or re-export the .xlf file
    }
}

Prevention

When it happens

Trigger: Loading an XLIFF file whose root <xliff> element declares a different or malformed default namespace, e.g. generic 'http://...' namespaces or SVG/HTML documents saved as .xlf.

Common situations: Exporting XLIFF from a tool that writes non-standard namespaces, renaming an HTML/XML file to .xlf, or hand-written XLIFF with a wrong xmlns string.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of symfony/translation@ae9e8a51bc (2026-09-15). Data as JSON: /api/errors/a819ce0a4cd8f069. Report an issue: GitHub.

Appendix: source

Thrown at Util/XliffUtils.php:43

    /**
     * Gets xliff file version based on the root "version" attribute.
     *
     * Defaults to 1.2 for backwards compatibility.
     *
     * @throws InvalidArgumentException
     */
    public static function getVersionNumber(\DOMDocument $dom): string
    {
        foreach ($dom->getElementsByTagName('xliff') as $xliff) {
            $version = $xliff->attributes->getNamedItem('version');
            if ($version) {
                return $version->nodeValue;
            }

            $namespace = $xliff->attributes->getNamedItem('xmlns');
            if ($namespace) {
                if (0 !== substr_compare('urn:oasis:names:tc:xliff:document:', $namespace->nodeValue, 0, 34)) {
                    throw new InvalidArgumentException(\sprintf('Not a valid XLIFF namespace "%s".', $namespace));
                }

                return substr($namespace, 34);
            }
        }

        // Falls back to v1.2
        return '1.2';
    }

    /**
     * Validates and parses the given file into a DOMDocument.
     *
     * @throws InvalidResourceException
     */
    public static function validateSchema(\DOMDocument $dom): array
    {
        $xliffVersion = static::getVersionNumber($dom);

View on GitHub (pinned to ae9e8a51bc)