fast-xml-parser is a robust JavaScript library for parsing XML to JavaScript objects, validating XML syntactically, and historically, building XML from JS objects. It is engineered for speed and efficiency, capable of handling large XML files (tested up to 100MB) without relying on C/C++ native libraries. As of v5.7.1, the package is actively maintained with frequent minor and patch releases, incorporating performance improvements and dependency updates. A key differentiator is its pure JavaScript implementation, broad compatibility (CommonJS, ESM, and browser environments), and extensive support for various XML features including entities, unpaired tags, and customizable parsing options. The XML Builder functionality was separated into a dedicated `fast-xml-builder` package in version v5.4.0, focusing `fast-xml-parser` primarily on parsing and validation.
npm install fast-xml-parserVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to validate an XML string and then parse it into a JavaScript object using common configuration options, and how to access the parsed data.
Install `fast-xml-builder` separately (`npm install fast-xml-builder`) and import `XMLBuilder` from its dedicated package: `import XMLBuilder from 'fast-xml-builder';`
Review and update XML documents or parsing configurations related to entity handling, ensuring compliance with the `@nodable/entities` v2.1.0 documentation. Adjust any logic that relies on specific entity error message strings.
Update any error handling or logging logic that specifically checks for previous entity-related error message strings to reflect the new messages.
If legitimate XML data frequently exceeds default entity limits, configure `XMLParser` options explicitly with higher values for `maxEntitySize`, `maxExpansionDepth`, `maxTotalExpansions`, or `maxExpandedLength` during instantiation (e.g., `new XMLParser({ maxTotalExpansions: Infinity });`).Install `fast-xml-builder` separately (`npm install fast-xml-builder`) and import `XMLBuilder` from its dedicated package: `import XMLBuilder from 'fast-xml-builder';`
Instantiate `XMLParser` with increased entity expansion limits in its options object, for example: `new XMLParser({ maxTotalExpansions: Infinity, maxEntitySize: 50000 });`For CommonJS environments, use object destructuring: `const { XMLParser } = require('fast-xml-parser');`Explicitly configure the `XMLParser` options during instantiation to control attribute handling, value parsing, and other structural aspects. For example, `new XMLParser({ ignoreAttributes: false, attributeNamePrefix: '@_', parseAttributeValue: true });`