rapid-xml-to-json is a fast, lightweight XML parser designed for simple hierarchical XML data.
This library is built for performance and simplicity. Below is a summary of what it can and cannot do:
- 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.
- Does not handle mixed content (text between and around child elements). (To be implemented)
- Does not validate XML (assumes input is well-formed).
You can install the library via npm:
npm install rapid-xml-to-json
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" }
// ]
// }
// }
rapid-xml-to-json is optimized for speed and low memory usage, skipping some XML features to avoid overhead.
Parses a well-formed XML string into a JavaScript object.
xml
(string): The well-formed XML string to parse.
- A nested JavaScript object representing the XML structure.
Soon(tm)
Contributions are welcome! If you encounter any issues or have suggestions for improvement, feel free to open an issue or a pull request.
This library is licensed under the MIT License. See the LICENSE file for more information.