Fast, tiny, standards-compliant XML DOM implementation for node and the browser.
This is a (partial) implementation of the DOM living standard, as last updated 1 March 2019, and the DOM Parsing and Serialization W3C Editor's Draft, as last updated 11 February 2019. See the 'Features' and 'Limitations' sections below for details on what's included and what's not.
The slimdom library can be installed using npm or yarn:
npm install --save slimdom
yarn add slimdom
The package includes both a commonJS bundle (
dist/slimdom.js) and an ES6 module (
Create documents using the slimdom.Document constructor, and manipulate them using the standard DOM API.
;const document = ;document;const xml = slimdom;// -> '<root xmlns=""/>'
Some DOM API's, such as the
DocumentFragment constructor, require the presence of a global document. In these cases, slimdom will use the instance exposed through
slimdom.document. Although you could mutate this document, it is recommended to create your own to avoid conflicts with other code using slimdom in your application.
When using a
Range, make sure to call
This library implements:
- All node types:
Range, which correctly updates under mutations.
XMLSerializer, and read-only versions of
The following features have not yet been implemented:
- No XML parsing (no
outerHTMLare read-only, no
Range). If you need to parse XML, consider using slimdom-sax-parser.
- No CSS selectors, so no
Element. The older non-CSS query methods (
Document) have not yet been implemented either. To query the DOM, consider using FontoXPath.
- No HTML parsing / serialization, but see this example which shows how to connect the parse5 HTML parser.
- No special treatment of HTML documents, including
HTMLElementand its subclasses. This also includes HTML casing behavior for attributes and tagNames, as well as the
- No events, no
- No support for shadow DOM,
- No support for custom elements or the
- No iteration helpers (
NodeFilter, and the
- No DOM modifying methods on Range (
attributeFilterfor mutation observers.
- No notion of URLs (
- No notion of encodings (
- No properties / methods that exist mainly for web compatibility reasons (
Pull requests for missing features or tests, bug reports, questions and other feedback are always welcome! Just open an issue on the github repo, and provide as much detail as you can.
To work on the slimdom library itself, clone the repository and run
npm install to install its dependencies.
This repository includes a full suite of tests based on jest. Run
npm test to run the tests, or
npm run test:debug to debug the tests and code by disabling coverage and enabling the node inspector (see chrome://inspect in Chrome).
An experimental runner for the W3C web platform tests is
included in the temporarily unavailable due to the migration to jest. To use it (when re-enabled), clone the web platform tests repository somewhere and set the
WEB_PLATFORM_TESTS_PATH environment variable to the corresponding path. Then run
npm test as normal. The
webPlatform.tests.ts file contains a blacklist of tests that don't currently run due to missing features.