xmlserializer icon indicating copy to clipboard operation
xmlserializer copied to clipboard

Consider following https://w3c.github.io/DOM-Parsing/#xml-serialization

Open domenic opened this issue 9 years ago • 4 comments

I'm looking for something that follows the spec browsers use so that I can use it in jsdom. Any thoughts on adding a mode that follows that algorithm more exactly?

domenic avatar Jul 02 '16 19:07 domenic

Hey, as somewhat hinted at in the README, I'm happy to make this thing more standards compliant. We might only need to retain some specifics, for rasterizeHTML.js to force HTML to XML conversion, but hopefully this will get down to being a xmlns override only + the removal of characters invalid in XML. Both could be made optional behaviour.

After a quick glimpse into the linked document, it looks like e.g. the serialisation for empty nodes needs an overhaul. And most likely there's going to be more.

Let me know what you need. Happy to give access to the repo.

cburgmer avatar Jul 03 '16 02:07 cburgmer

Btw, tests/BrowserCompatibilityRunner.html shows how the test cases align with what a browser would currently serialise. Gives a bit of an overview on what's different right now.

cburgmer avatar Jul 03 '16 09:07 cburgmer

@cburgmer @domenic I'm happy to help out also if I can, as we could need this in https://github.com/paperjs/paper.js

lehni avatar Jul 06 '16 09:07 lehni

Indeed xmlserializer seems to behave differently from browsers.

In a browser you can do:

const doctypeStr = new XMLSerializer().serializeToString(document.doctype);

while xmlserializer.serializeToString(document.doctype) results in:

TypeError: Cannot read property 'replace' of undefined
      at removeInvalidCharacters (node_modules/xmlserializer/xmlserializer.js:13:24)
      at Object.serializeToString (node_modules/xmlserializer/xmlserializer.js:126:20)
      at XMLSerializer.serializeToString (test/helper.js:57:29)

tommedema avatar Mar 15 '18 09:03 tommedema