source: frontend/node_modules/w3c-xmlserializer/README.md

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 1.6 KB
RevLine 
[9af201e]1# w3c-xmlserializer
2
3An XML serializer that follows the [W3C specification](https://w3c.github.io/DOM-Parsing/).
4
5This package can be used in Node.js, as long as you feed it a DOM node, e.g. one produced by [jsdom](https://github.com/jsdom/jsdom).
6
7## Basic usage
8
9Assume you have a DOM tree rooted at a node `node`. In Node.js, you could create this using [jsdom](https://github.com/jsdom/jsdom) as follows:
10
11```js
12const { JSDOM } = require("jsdom");
13
14const { document } = new JSDOM().window;
15const node = document.createElement("akomaNtoso");
16```
17
18Then, you use this package as follows:
19
20
21```js
22const serialize = require("w3c-xmlserializer");
23
24console.log(serialize(node));
25// => '<akomantoso xmlns="http://www.w3.org/1999/xhtml"></akomantoso>'
26```
27
28## `requireWellFormed` option
29
30By 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
31
32```js
33serialize(node, { requireWellFormed: true });
34```
35
36which will cause `Error`s to be thrown when non-well-formed constructs are encountered. [Per the spec](https://w3c.github.io/DOM-Parsing/#dfn-require-well-formed), this largely is about imposing constraints on the names of elements, attributes, etc.
37
38As a point of reference, on the web platform:
39
40* The [`innerHTML` getter](https://w3c.github.io/DOM-Parsing/#dom-innerhtml-innerhtml) uses the require-well-formed mode, i.e. trying to get the `innerHTML` of non-well-formed subtrees will throw.
41* The [`xhr.send()` method](https://xhr.spec.whatwg.org/#the-send()-method) does not require well-formedness, i.e. sending non-well-formed `Document`s will serialize and send them anyway.
Note: See TracBrowser for help on using the repository browser.