domino
domino copied to clipboard
Implement XMLSerializer
Not sure if this complies with the specification but it's definitely needed when dealing with XML content.
The spec for the HTML serialization algorithm is found at http://www.whatwg.org/specs/web-apps/current-work/multipage/the-end.html#serializing-html-fragments
Your addition is not spec compliant (and doesn't pass our test suite). I would consider adding this as an optional feature, though, if you can think of a reasonable way to enable it.
You should ensure that it passes the test suite even with the feature enabled, though: in particular, according to the test suite you seem to be emitting an unnecessary xmlns
attribute when the namespace is xhtml.
The following code outputs the same result in Chrome, Firefox and IE9:
var namespace = 'http://schemas.xmlsoap.org/soap/envelope/';
var qualifiedName = 'Envelope';
var doc = document.implementation.createDocument(namespace, qualifiedName, null);
var str = new XMLSerializer().serializeToString(doc);
console.log(str); // <Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"/>
The equivalent in domino doesn't respect the namespace and the self-closing:
var impl = domino.createDOMImplementation();
var namespace = 'http://schemas.xmlsoap.org/soap/envelope/';
var qualifiedName = 'Envelope';
var doc = impl.createDocument(namespace, qualifiedName, null);
console.log(doc.serialize()); // <Envelope></Envelope>
The latter is not that important but the lack of namespaces can be a deal breaker. I'll see if I can come up with a change that doesn't break the existing tests.
Again, your addition is not spec compliant (and doesn't pass the test suite). There are specs for XML serialization, see http://www.w3.org/TR/DOM-Parsing/#the-xmlserializer-interface -- that's what you should implement if you want an XML serialization of the document.
See also https://www.w3.org/Bugs/Public/show_bug.cgi?id=13410 and https://www.w3.org/Bugs/Public/show_bug.cgi?id=25225