Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
- This WPT test may be referenced by the following Test IDs:
- /domparsing/xml-parse-serialize-roundtrip.html - WPT Dashboard Interop Dashboard
<!DOCTYPE html>
<link rel=author href="mailto:jarhar@chromium.org">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
function runTest(xmlString, testName) {
test(() => {
const xmlDoc = (new DOMParser()).parseFromString(xmlString, 'text/xml');
const result = (new XMLSerializer()).serializeToString(xmlDoc);
assert_equals(result, xmlString);
}, `DOMParser and XMLSerializer should round trip with CDATA sections: ${testName}`);
}
runTest(
`<root><![CDATA[
12345678901234567890123456789012345678901234567890123456789012345678901234567890
12345678901234567890123456789012345678901234567890123456789012345678901234567890
12345678901234567890123456789012345678901234567890123456789012345678901234567890
12345678901234567890123456789012345678901234567890123456789012345678901234567890
12345678901234567890123456789012345678901234567890123456789012345678901234567890
12345678901234567890123456789012345678901234567890123456789012345678901234567890
12345678901234567890123456789012345678901234567890123456789012345678901234567890
12345678901234567890123456789012345678901234567890123456789012345678901234567890
12345678901234567890123456789012345678901234567890123456789012345678901234567890
12345678901234567890123456789012345678901234567890123456789012345678901234567890
12345678901234567890123456789012345678901234567890123456789012345678901234567890
]]></root>`,
'large CDATA');
runTest(
'<root><htmlDefn><![CDATA[<div><![CDATA[ Just Rubbish Data $#$^#^$ ]]]]><![CDATA[></div><div></div>]]></htmlDefn></root>',
'multiple CDATAs');
</script>