`body-parser-xml` is an Express.js middleware that extends the widely used `body-parser` library, enabling applications to seamlessly parse incoming XML-formatted request bodies into JavaScript objects. Currently at stable version 2.0.5, this package integrates an `xml` method directly onto the `body-parser` object, allowing developers to handle XML APIs while working with familiar JSON-like structures. Its release cadence reflects active maintenance, with recent updates addressing Node.js version compatibility (supporting Node 10 and above) and critical security vulnerabilities, including prototype pollution and `xml2js` dependency issues. A key differentiator is its straightforward integration model, piggybacking on `body-parser`'s established middleware pattern and providing extensive options for XML parsing via the underlying `xml2js` library, such as `normalize` and `explicitArray`. This approach simplifies the handling of diverse XML content types in Express applications.
npm install body-parser-xmlVerified import paths — ran on the pinned version, not inferred.
This quickstart initializes an Express server with `body-parser-xml` to parse incoming XML requests into JavaScript objects available on `req.body`. It demonstrates configuring the middleware with `limit` and `xmlParseOptions` and includes a sample route to process and respond to XML data.
Upgrade Node.js to version 10 or newer, or stick to `body-parser-xml` v1.x for legacy Node.js environments.
Upgrade to `body-parser-xml` version 2.0.3 or higher immediately to patch the prototype pollution vulnerability.
Upgrade to `body-parser-xml` version 2.0.4 or higher to benefit from the updated `xml2js` dependency and associated security fixes.
Ensure you call `require('body-parser-xml')(bodyParser);` (or its ESM equivalent) *before* attempting to use `bodyParser.xml()` in your Express application.Ensure you have called `require('body-parser-xml')(bodyParser);` (or `bodyParserXml(bodyParser);` in ESM) after requiring `body-parser`.Increase the `limit` option in `bodyParser.xml({ limit: '5MB' })` or adjust the client payload size. Default limit is '100kb'.Verify that the client is sending well-formed XML and that the `Content-Type` header (e.g., `application/xml`, `text/xml`) is set correctly. If using a custom type, configure the `type` option in `bodyParser.xml({ type: 'application/x-my-xml' })`.