Skip to content

Fast XML-parser for parsing simple XML structures into JSON. Optimised for speed, low memory usage and GC-avoidance.

License

Notifications You must be signed in to change notification settings

chcederquist/rapid-xml-to-json

Repository files navigation

rapid-xml-to-json

rapid-xml-to-json is a fast, lightweight XML parser designed for simple hierarchical XML data.

Features

This library is built for performance and simplicity. Below is a summary of what it can and cannot do:

✅ Features

  • Parses well-formed XML into a nested JavaScript object.
  • Handles basic XML structures with child elements.
  • Sets attributes on elements ($attrs)
  • Supports CDATA sections.
  • Skips comments, processing instructions (<?...?>), and <!DOCTYPE> declarations.

❌ Limitations

  • Does not handle mixed content (text between and around child elements). (To be implemented)
  • Does not validate XML (assumes input is well-formed).

Installation

You can install the library via npm:

npm install rapid-xml-to-json

Usage

Here’s how you can use rapid-xml-to-json:

import { xlmToJson } from 'rapid-xml-to-json';

const xml = `
<root>
  <item>
    <![CDATA[Some content here]]>
  </item>
  <item>
    <subitem>Another piece of content</subitem>
  </item>
</root>
`;

const parsed = xmlToJson(xml);

console.log(parsed);
// Output:
// {
//   root: {
//     item: [
//       "Some content here",
//       { subitem: "Another piece of content" }
//     ]
//   }
// }

Performance

rapid-xml-to-json is optimized for speed and low memory usage, skipping some XML features to avoid overhead.

API

xmlToJson(xml: string): object

Parses a well-formed XML string into a JavaScript object.

Parameters

  • xml (string): The well-formed XML string to parse.

Returns

  • A nested JavaScript object representing the XML structure.

Benchmarks

Soon(tm)

Contributing

Contributions are welcome! If you encounter any issues or have suggestions for improvement, feel free to open an issue or a pull request.

License

This library is licensed under the MIT License. See the LICENSE file for more information.

About

Fast XML-parser for parsing simple XML structures into JSON. Optimised for speed, low memory usage and GC-avoidance.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published