DOMParser-parseFromString-xml-internal-subset.html (1315B)
1 <!DOCTYPE html> 2 <title>Parsing and serialization of doctype internal subset</title> 3 <script src="/resources/testharness.js"></script> 4 <script src="/resources/testharnessreport.js"></script> 5 <script> 6 test(function () { 7 // https://www.w3.org/TR/xml11/#sec-prolog-dtd has intSubset as part of the 8 // syntax, which is not represented in the DocumentType interface. Check that 9 // publicId and systemId are not affected. 10 var doc = new DOMParser().parseFromString('<!DOCTYPE foo [ <!ENTITY x "y"> ]><foo>&x;</foo>', 'text/xml'); 11 var doctype = doc.doctype; 12 assert_equals(doctype.name, 'foo', 'doctype name'); 13 assert_equals(doctype.publicId, '', 'doctype publicId'); 14 assert_equals(doctype.systemId, '', 'doctype systemId'); 15 // Check that document itself was parsed correctly. 16 var documentElementString = new XMLSerializer().serializeToString(doc.documentElement); 17 assert_equals(documentElementString, '<foo>y</foo>', 'serialized document element'); 18 // https://w3c.github.io/DOM-Parsing/#xml-serializing-a-documenttype-node also 19 // does not have any notion of the internal subset, so also check that it 20 // isn't serialized by XMLSerializer. 21 var doctypeString = new XMLSerializer().serializeToString(doctype); 22 assert_equals(doctypeString, '<!DOCTYPE foo>', 'serialized doctype'); 23 }); 24 </script>