An XML serializer that follows the W3C specification.
This package can be used in Node.js, as long as you feed it a DOM node, e.g. one produced by jsdom.
Assume you have a DOM tree rooted at a node
node. In Node.js, you could create this using jsdom as follows:
const JSDOM = ;const document = window;const node = document;
Then, you use this package as follows:
const serialize = ;console;// => '<akomantoso xmlns=""></akomantoso>'
By default the input DOM tree is not required to be "well-formed"; any given input will serialize to some output string. You can instead require well-formedness via
which will cause
Errors to be thrown when non-well-formed constructs are encountered. Per the spec, this largely is about imposing constraints on the names of elements, attributes, etc.
As a point of reference, on the web platform: