Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
- This WPT test may be referenced by the following Test IDs:
- /xml/retain_redundant_xmlns.html - WPT Dashboard Interop Dashboard
<!DOCTYPE html>
<meta charset="utf-8">
<title>XML Redundant Namespace Declaration Attribute Retention</title>
<meta name="assert" content="For web compatibility, the parser should reproduce xmlns attributes on elements even if the same namespace was already in scope.">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
'use strict';
const testCases = [
{
description: 'Non-prefixed: xmlns attribute is retained when same default namespace is already in scope on parent',
attributeName: 'xmlns',
},
{
description: 'Non-prefixed: xmlns attribute is retained when intermediate element has no explicit namespace declaration',
xml: '<root xmlns="http://example.com"><intermediate><child xmlns="http://example.com"/></intermediate></root>',
attributeName: 'xmlns',
},
{
description: 'Prefixed: xmlns:p attribute is retained when same prefix namespace is already in scope on parent',
attributeName: 'xmlns:p',
},
];
for (const { description, xml, attributeName, expectedValue } of testCases) {
test(() => {
const doc = new DOMParser().parseFromString(xml, 'text/xml');
const child = doc.getElementsByTagName('child')[0];
assert_true(child.hasAttribute(attributeName), `child should have '${attributeName}' attribute`);
assert_equals(child.getAttribute(attributeName), expectedValue);
}, description);
}
</script>