Skip to content

[DOM] Dom\XMLDocument::schemaValidate fails to resolve xs:QName with prefix from imported schema (works in DOMDocument) #22219

@tvdijen

Description

@tvdijen

Description

The following code:

<?php

$xmlString = file_get_contents(__DIR__ . '/test.wsdl');

echo "=== Testing with new Dom\\XMLDocument (PHP 8.4+) ===\n\n";

testValidation("Direct custom.xsd", $xmlString, __DIR__ . '/custom.xsd', true);

echo "\n=== Testing with old DOMDocument (for comparison) ===\n\n";

testValidation("Direct custom.xsd", $xmlString, __DIR__ . '/custom.xsd', false);

function testValidation(string $name, string $xmlString, string $xsdPath, bool $useNewDom): void
{
    libxml_use_internal_errors(true);
    libxml_clear_errors();

    if ($useNewDom) {
        $doc = Dom\XMLDocument::createFromString($xmlString, LIBXML_NSCLEAN);
        $valid = $doc->schemaValidate($xsdPath);
    } else {
        $doc = new DOMDocument();
        $doc->loadXML($xmlString, LIBXML_NSCLEAN);
        $valid = $doc->schemaValidate($xsdPath);
    }

    echo "[$name] " . ($useNewDom ? "Dom\\XMLDocument" : "DOMDocument") . "";

    if ($valid) {
        echo "✓ VALID\n";
    } else {
        echo "✗ INVALID\n";
        foreach (libxml_get_errors() as $error) {
            echo "    Line {$error->line}: {$error->message}\n";
        }
        libxml_clear_errors();
    }
}

Resulted in this output:

=== Testing with new Dom\XMLDocument (PHP 8.4+) ===

[Direct custom.xsd] Dom\XMLDocument → ✗ INVALID
    Line 9: Element '{http://schemas.xmlsoap.org/wsdl/}part', attribute 'element': The QName value 'ssp:CustomElement' has no corresponding namespace declaration in scope.

    Line 9: Element '{http://schemas.xmlsoap.org/wsdl/}part', attribute 'element': 'ssp:CustomElement' is not a valid value of the atomic type 'xs:QName'.


=== Testing with old DOMDocument (for comparison) ===

[Direct custom.xsd] DOMDocument → ✓ VALID

But I expected this output instead:

=== Testing with new Dom\XMLDocument (PHP 8.4+) ===

[Direct custom.xsd] Dom\XMLDocument → ✓ VALID

=== Testing with old DOMDocument (for comparison) ===

[Direct custom.xsd] DOMDocument → ✓ VALID

PHP Version

PHP 8.4.21 (cli) (built: May  5 2026 16:34:12) (NTS gcc x86_64)
Copyright (c) The PHP Group
Built by Remi's RPM repository <https://rpms.remirepo.net/> #StandWithUkraine
Zend Engine v4.4.21, Copyright (c) Zend Technologies
    with Zend OPcache v8.4.21, Copyright (c), by Zend Technologies

PHP 8.5.6 (cli) (built: May  5 2026 21:19:36) (NTS gcc x86_64)
Copyright (c) The PHP Group
Built by Remi's RPM repository <https://rpms.remirepo.net/> #StandWithUkraine
Zend Engine v4.5.6, Copyright (c) Zend Technologies
    with Zend OPcache v8.5.6, Copyright (c), by Zend Technologies

Operating System

Centos 9

Reproduction files

custom.xsd.xml
test.php
test.xml
wsdl.xsd.xml

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions