function testSerializer () {
const de = SpecialPowers.Ci.nsIDocumentEncoder; var encoder = SpecialPowers.Cu.createDocumentEncoder("text/html");
var parser = new DOMParser(); var serializer = new XMLSerializer();
// with content var str = '<?xml version="1.0"?><doc>\n<link xmlns="http://www.w3.org/1999/xhtml"><!-- child nodes --> \n<content xmlns=""/></link>\n</doc>'; var expected = '<?xml version="1.0" encoding="UTF-8"?>\n<doc>\n<link xmlns="http://www.w3.org/1999/xhtml"><!-- child nodes --> \n<content xmlns=""/></link>\n</doc>';
var doc = parser.parseFromString(str,"application/xml"); var result = serializer.serializeToString(doc);
result = result.replace(/\r\n/mg, "\n");
is(result, expected, "serialization of a link element inside an xml document with children");
// with only whitespaces
str = '<?xml version="1.0"?><doc>\n<link xmlns="http://www.w3.org/1999/xhtml"> \n </link>\n</doc>';
expected = '<?xml version="1.0" encoding="UTF-8"?>\n<doc>\n<link xmlns="http://www.w3.org/1999/xhtml"> \n </link>\n</doc>';
doc = parser.parseFromString(str,"application/xml");
result = serializer.serializeToString(doc);
result = result.replace(/\r\n/mg, "\n");
is(result, expected, "serialization of a link element with only whitespaces as content, inside an xml document");
// with only one space as content
str = '<?xml version="1.0"?><doc>\n<link xmlns="http://www.w3.org/1999/xhtml"> </link>\n</doc>';
expected = '<?xml version="1.0" encoding="UTF-8"?>\n<doc>\n<link xmlns="http://www.w3.org/1999/xhtml"> </link>\n</doc>';
doc = parser.parseFromString(str,"application/xml");
result = serializer.serializeToString(doc);
result = result.replace(/\r\n/mg, "\n");
is(result, expected, "serialization of a link element with only one space as content, inside an xml document");
doc = parser.parseFromString(str,"application/xml");
doc.documentElement.firstElementChild.textContent = '';
result = serializer.serializeToString(doc);
result = result.replace(/\r\n/mg, "\n");
is(result, expected, "serialization of a link element on which we removed dynamically the content, inside an xml document");
// with no content but an ended tag
str = '<?xml version="1.0"?><doc>\n<link xmlns="http://www.w3.org/1999/xhtml"></link>\n</doc>';
expected = '<?xml version="1.0" encoding="UTF-8"?>\n<doc>\n<link xmlns="http://www.w3.org/1999/xhtml" />\n</doc>';
doc = parser.parseFromString(str,"application/xml");
result = serializer.serializeToString(doc);
result = result.replace(/\r\n/mg, "\n");
is(result, expected, "serialization of a link element with no content but with an ended tag, inside an xml document");
doc = parser.parseFromString(str,"application/xml");
result = serializer.serializeToString(doc);
result = result.replace(/\r\n/mg, "\n");
is(result, expected, "serialization of a link element with no content, inside an xml document");
doc = $("testframe").contentDocument;
encoder.init(doc, "text/html", de.OutputLFLineBreak);
encoder.setCharset("UTF-8");
result = encoder.encodeToString();
expected = '<html><head><meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\">\n <title>Test</title>\n';
expected += ' <link rel=\"Top\" href=\"\"> ';
expected += ' </head><body>foo \n\n\n <p>Hello world</p>\n</body></html>';
is(result, expected, "serialization of a link element with content, inside an html document");
doc = $("testframe2").contentDocument;
encoder.init(doc, "application/xhtml+xml", de.OutputLFLineBreak);
encoder.setCharset("UTF-8");
result = encoder.encodeToString();
expected = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\n';
expected += '<html xmlns="http://www.w3.org/1999/xhtml">\n<head>\n <meta http-equiv="content-type" content="text/html; charset=UTF-8" />\n <title>Test</title>\n';
expected += ' <link rel="Top" href=""> foo </link>\n';
expected += '\n</head>\n<body>\n <p>Hello world</p>\n</body>\n</html>';
is(result, expected, "serialization of a link element with content, inside an xhtml document");
SimpleTest.finish();
}
SimpleTest.waitForExplicitFinish();
addLoadEvent(testSerializer);
</script>
</pre>
</body>
</html>
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.14 Sekunden
(vorverarbeitet am 2026-04-29)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.