📅 You're Invited: Meet the Socket team at RSAC (April 28 – May 1).RSVP
Socket
Sign inDemoInstall
Socket

libxml2-wasm

Package Overview
Dependencies
Maintainers
0
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

libxml2-wasm

WebAssembly-based libxml2 javascript wrapper

0.5.0
latest
Source
npm
Version published
Weekly downloads
3.1K
-1.35%
Maintainers
0
Weekly downloads
 
Created
Source

libxml2-wasm

CI Build on master npm

Why Choose Another XML Library?

When comparing the previous two main approaches — pure JavaScript implementation and traditional C implementation binding — WebAssembly offers a unique combination of advantages. It provides excellent performance while maintaining the best compatibility with modern JavaScript runtimes.

Javascript ImplementationTraditional C BindingWebAssembly
Parsing SpeedAverage1FastFast
C/C++ Toolchain at RuntimeNot requiredRequired2Not Required
Prebuilt BinariesN/AOne for each OS / Runtime / ArchUniversal for all
Prebuilt Binary CompatibilityN/AMay be broken across libc versionsVery Good
Browser CompatibilityYesNoYes

Documentation

https://jameslan.github.io/libxml2-wasm/index.html

Supported Environments

Due to the usage of WebAssembly, ES module and top level await etc, this library requires the minimum version of the following environments,

EnvironmentVersion
Node.jsv16+
ChromeV89+
EdgeV89+
Safariv15+

Features

  • Parsing & Querying
  • Validating
  • Modifying
  • Serializing
  • XInclude and XSD include/import (experimental)

Getting started

Install libxml2-wasm package:

npm i libxml2-wasm

libxml2-wasm is an ES module, the import process differs between ES modules and CommonJS modules.

From ES Module

import fs from 'node:fs';
import { XmlDocument } from 'libxml2-wasm';
const doc1 = XmlDocument.fromString('<note><to>Tove</to></note>');
const doc2 = XmlDocument.fromBuffer(fs.readFileSync('doc.xml'));
doc1.dispose();
doc2.dispose();

From CommonJS

const fs = require('node:fs');
import('libxml2-wasm').then(({ XmlDocument }) => {
    const doc1 = XmlDocument.fromString('<note><to>Tove</to></note>');
    const doc2 = XmlDocument.fromBuffer(fs.readFileSync('doc.xml'));
    doc1.dispose();
    doc2.dispose();
});

IMPORTANT: dispose() is required to avoid memory leak.

For more detail, see the Doc.

Footnotes

  • The performance of different XML libraries can vary significantly. For more information, refer to the benchmark provided.

  • The requirement of a C/C++ toolchain at runtime can be waived if prebuilt binaries are available.

Keywords

xml

FAQs

Package last updated on 02 Jan 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts