API Reference

xml2js

Converts XML to JavaScript objects and back, with configurable element, attribute, and text handling.

Official Documentation ↗
CompatibilityThis documentation covers version v0.6. Check the official docs for the latest API surface.

Installation

npmnpm install xml2js

Methods

xml2js maps XML elements to properties and exposes attributes under a configurable key such as $.

Key Features

  • explicitArray toggles single-element arrays
  • attrkey and charkey rename attribute and text keys
  • Builder reconstructs XML from objects

Usage Notes

Pin a version and check the official docs for the API surface you depend on before upgrading.

FAQ

How do I disable attribute wrapping?
Set explicitArray: false so single elements are not wrapped in arrays, and rename attrkey from its default $ if you prefer another key.
Is xml2js vulnerable to XXE?
By default the sax parser does not resolve external entities, which avoids classic XXE. Never enable entity expansion on untrusted input.
Can it handle large documents?
It is a streaming SAX-based parser, so yes, but building the whole object tree still uses memory proportional to document size.