js2xmlparser is a Node.js module that converts JavaScript objects into XML. It is currently in its stable version 5.0.0 and has a consistent release cadence with significant updates in major versions. The library specializes in parsing JSON-type objects, arrays, and primitive data types, but also supports native JavaScript objects like `Date` and `RegExp` by leveraging their `toString` methods. A key differentiator is its explicit support for ES2015 `Map` and `Set` objects, enabling ordered XML element generation where standard JSON objects would not guarantee it. It also features robust handling of XML-specific constructs such as attributes (using an `@` property), mixed content (using a `#` property), and multiple elements with the same name (through arrays), alongside pretty-printing capabilities.
npm install js2xmlparserVerified import paths — ran on the pinned version, not inferred.
Demonstrates parsing a complex JavaScript object into XML, showcasing attribute handling, nested objects, array elements, and mixed content using the `parse` function.
Migrate all calls to `js2xmlparser.parse(root, data, options)` or `parse(root, data, options)` if using named imports.
Review existing XML output expectations and adjust options as needed (e.g., `selfClosing: false` to disable self-closing tags where not desired, or configure `pretty` options for indentation).
Familiarize yourself with the object structure conventions (`@` for attributes, `#` for mixed content) described in the documentation to correctly represent desired XML structures.
Ensure your project is configured for TypeScript if leveraging its types, and review compilation errors that may arise from stricter type enforcement. Test thoroughly after upgrading.
Verify custom `typeHandlers` to ensure they align with the updated behavior and documentation, especially regarding usage with bare text/attribute values and the restriction with aliases.
Use the `parse` method: `js2xmlparser.parse(root, data, options)` (CommonJS) or `import { parse } from 'js2xmlparser'; parse(root, data, options);` (ESM).Switch to ES module imports: `import { parse } from 'js2xmlparser';` or ensure your environment is configured for CommonJS modules (e.g., `"type": "commonjs"` in `package.json` or use `.cjs` file extension for Node.js).Adjust options passed to the `parse` method. For example, use `{ selfClosing: false, pretty: { indent: ' ' } }` to override these defaults and regain specific formatting.No dependency data recorded yet.