Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement XMLSerializer #42

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Implement XMLSerializer #42

wants to merge 4 commits into from

Conversation

asual
Copy link
Contributor

@asual asual commented Jan 29, 2014

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

Not sure if this complies with the specification but it's definitely needed when dealing with XML content.
@cscott
Copy link
Collaborator

cscott commented Jan 30, 2014

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.

@asual
Copy link
Contributor Author

asual commented Feb 3, 2014

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.

@cscott
Copy link
Collaborator

cscott commented May 13, 2014

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
Copy link
Collaborator

cscott commented May 13, 2014

@cscott cscott changed the title Prints namespaces when serializing nodes Implement XMLSerializer Aug 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants