express-xml-bodyparser is a Connect/Express middleware designed to parse incoming raw XML request bodies, converting them into a JavaScript object available on `req.body`. It leverages the `xml2js` library for XML parsing. The current stable version is 0.4.1. The package has a slow release cadence, with updates typically addressing dependencies or minor fixes, rather than frequent feature additions. Key differentiators include its ability to parse data only once even if called multiple times, gracefully skip parsing for empty bodies, and accept a wide range of XML-based content-types (e.g., `application/rss+xml`). It provides custom configuration options that are merged with opinionated defaults to normalize the resulting JSON structure, such as trimming whitespace and lowercasing tag names, which users need to be aware of if they desire standard `xml2js` behavior. TypeScript type definitions are available via `@types/express-xml-bodyparser`.
npm install express-xml-bodyparserVerified import paths — ran on the pinned version, not inferred.
This quickstart initializes an Express application, applies the xml-bodyparser middleware globally, and sets up a route to handle incoming XML requests, demonstrating how to access the parsed `req.body` and how to apply the middleware with custom `xml2js` options on specific routes.
Review applications that use custom XML MIME types to ensure they function as expected after upgrading to v0.3.0 or later. Adjust `Content-Type` handling if necessary.
Avoid directly mutating `xmlparser.regexp`. If custom MIME-type detection is required, consider alternative middleware or preprocessing the request before passing it to `express-xml-bodyparser`.
Ensure `async: false` is used (which is the default) or implement rigorous XML input validation if you choose to override this default. Monitor upstream `node-xml2js` for resolutions to this issue if `async: true` is critical for your use case.
If you require `xml2js`'s default behavior, you must explicitly set the `express-xml-bodyparser` opinionated defaults to `false` in your options object (e.g., `{ explicitArray: false, normalize: false, normalizeTags: false }`). Update any client-side logic expecting a 411 status for empty bodies.Ensure the client sends `Content-Type: application/xml` (or another recognized XML MIME type like `application/rss+xml`). Verify that `app.use(xmlparser())` or `xmlparser()` is correctly placed before your route handler.
Ensure `async: false` is set (which is the default behavior in recent versions) or implement robust try-catch blocks around XML parsing if you explicitly require asynchronous processing and anticipate malformed input.
To override these opinionated defaults and use `xml2js`'s standard behavior, explicitly set the desired options to `false` in your configuration object, e.g., `xmlparser({ explicitArray: false, normalize: false, normalizeTags: