https://github.com/web-platform-tests/wpt
Raw File
Tip revision: fda5b2f7c785b32ad563e3bf0c28e407d0199bad authored by Florian Rivoal on 30 March 2018, 04:19:15 UTC
[css-align] Fix typo and clean-up markup
Tip revision: fda5b2f
XMLSerializer-serializeToString.html
<!DOCTYPE HTML>
<meta charset=utf-8>
<html>
 <head>
  <title>domparsing Test: XMLSerializer.serializeToString</title>
  <script src="/resources/testharness.js"></script>
  <script src="/resources/testharnessreport.js"></script>
 </head>
 <body>
    <h1>domparsing_XMLSerializer_serializeToString</h1>
  <script>
function createXmlDoc(){
  var input = '<?xml version="1.0" encoding="UTF-8"?><root><child1>value1</child1></root>';
  var parser = new DOMParser();
  return parser.parseFromString(input, 'text/xml');
}

test(function() {
  var serializer = new XMLSerializer();
  var root = createXmlDoc().documentElement;
  var xmlString = serializer.serializeToString(root);
  assert_equals(xmlString, '<root><child1>value1</child1></root>');
}, 'check XMLSerializer.serializeToString method could parsing xmldoc to string');

test(function() {
  var serializer = new XMLSerializer();
  var root = createXmlDoc().documentElement;
  var element = root.ownerDocument.createElementNS('urn:foo', 'another');
  var child1 = root.firstChild;
  root.replaceChild(element, child1);
  element.appendChild(child1);
  var xmlString = serializer.serializeToString(root);
  assert_equals(xmlString, '<root><another xmlns="urn:foo"><child1 xmlns="">value1</child1></another></root>');
}, 'Check if the default namespace is correctly reset.');

test(function() {
  var input = '<root xmlns="urn:bar"><outer xmlns=""><inner>value1</inner></outer></root>';
  var root = (new DOMParser()).parseFromString(input, 'text/xml').documentElement;
  var xmlString = (new XMLSerializer()).serializeToString(root);
  assert_equals(xmlString, '<root xmlns="urn:bar"><outer xmlns=""><inner>value1</inner></outer></root>');
}, 'Check if there is no redundant empty namespace declaration.');

test(function() {
  var serializer = new XMLSerializer();
  var parser = new DOMParser();
  var root = parser.parseFromString('<root />', 'text/xml').documentElement;
  root.setAttribute('attr', '\t');
  assert_in_array(serializer.serializeToString(root), [
    '<root attr="&#9;"/>', '<root attr="&#x9;"/>']);
  root.setAttribute('attr', '\n');
  assert_in_array(serializer.serializeToString(root), [
    '<root attr="&#xA;"/>', '<root attr="&#10;"/>']);
  root.setAttribute('attr', '\r');
  assert_in_array(serializer.serializeToString(root), [
    '<root attr="&#xD;"/>', '<root attr="&#13;"/>']);
}, 'check XMLSerializer.serializeToString escapes attribute values for roundtripping');

</script>
 </body>
</html>
back to top