Getting Started

Install the libxml2-wasm npm package in your most convenient way, e.g.

npm install libxml2-wasm

libxml2-wasm is an ES module, importing it are different between ES module and commonJS module.

Import it directly.

import { XmlDocument } from 'libxml2-wasm';
const doc = XmlDocument.fromString('<note><to>Tove</to></note>');
doc.dispose();

Dynamic import is needed:

import('libxml2-wasm').then(({ XmlDocument }) => {
const doc = XmlDocument.fromString('<note><to>Tove</to></note>');
doc.dispose();
});

IMPORTANT: dispose() is required to avoid memory leak. For more details please see Memory Management.

Troubleshooting: If the target environment set too low, the transpiler(typescript, or babel etc) may convert import to a call to the function require(), which may lead to runtime error.