A Node package that parses XML into JavaScript objects and builds XML from objects, using sax-js and xmlbuilder-js under the hood.
Overview
node-xml2js is a small library for turning XML into plain JavaScript structures and back again. It targets developers who want structured data from XML without a full DOM implementation, and notes that a full DOM parser is a different class of tool.
Parsing can be used in a simple callback style or through a Parser instance with extensive configuration. Options control attributes, text nodes, arrays for children, trimming, namespaces, async callbacks, and optional name or value processors. Objects can also be serialized to XML through a Builder with parallel settings for declarations, CDATA, and formatting.
Install through npm or Bower. Typical use is inside Node applications or bundled front-end code where the runtime already provides JavaScript execution. Output can be passed to JSON.stringify for JSON consumers.
The project documents migration differences between major parsing defaults, including explicit root handling and when child tags are always returned as arrays.
Key features
- XML to JavaScript parsing
- JavaScript to XML building
- Configurable parser options
- Promise-friendly usage patterns
- Built-in tag and value processors
- npm and Bower distribution
- Strict SAX parsing mode
- Optional async callbacks
Use cases
- Parse API XML responses in Node
- Generate XML from application data
- Convert config or feed files to objects
- Interop with XML-based legacy services