domino icon indicating copy to clipboard operation
domino copied to clipboard

Implement XMLSerializer

Open asual opened this issue 10 years ago • 4 comments

Not sure if this complies with the specification but it's definitely needed when dealing with XML content.

asual avatar Jan 29 '14 21:01 asual

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.

cscott avatar Jan 30 '14 16:01 cscott

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.

asual avatar Feb 03 '14 15:02 asual

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.

cscott avatar May 13 '14 21:05 cscott

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

cscott avatar May 13 '14 21:05 cscott