Skip to content

Dom\XMLDocument::C14N() seems broken compared to DOMDocument::C14N() #20444

@aprat84

Description

@aprat84

Description

The following code:

$xml = <<<EOF
<?xml version="1.0" encoding="UTF-8"?>
<test:root xmlns:test="http://example.com/dummy/ns">
    <test:a/>
    <test:b test:kind="123">abc</test:b>
</test:root>
EOF;

$d = \Dom\XMLDocument::createFromString($xml);
var_dump($d->C14N(true));

Resulted in this output:

<test:root xmlns:test="http://example.com/dummy/ns" xmlns:xmlns="http://www.w3.org/2000/xmlns/" xmlns:test="http://example.com/dummy/ns">
    <test:a></test:a>
    <test:b test:kind="123">abc</test:b>
</test:root>

But I expected this output instead:

<test:root xmlns:test="http://example.com/dummy/ns">
    <test:a></test:a>
    <test:b test:kind="123">abc</test:b>
</test:root>

However, this code works:

$xml = <<<EOF
<?xml version="1.0" encoding="UTF-8"?>
<test:root xmlns:test="http://example.com/dummy/ns">
    <test:a/>
    <test:b test:kind="123">abc</test:b>
</test:root>
EOF;

$d = new DOMDocument();
$d->loadXML($xml);
var_dump($d->C14N(true));

Shouldn't the new \Dom\XMLDocument class give the same result as the "old" \DOMDocument class?

PHP Version

PHP 8.4.14 (cli) (built: Oct 24 2025 19:07:34) (NTS)
Copyright (c) The PHP Group
Built by https://github.com/docker-library/php
Zend Engine v4.4.14, Copyright (c) Zend Technologies
    with Zend OPcache v8.4.14, Copyright (c), by Zend Technologies

Operating System

Alpine Linux v3.22.2 (php:8.4-fpm-alpine docker image)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions