xml-disassembler
Disassemble large XML files into smaller files and reassemble the original XML. Preserves the XML declaration, root namespace, and element order so that a full round-trip (disassemble → reassemble) reproduces the original file contents.
Note: This is a Rust implementation of the original TypeScript xml-disassembler.
Features
- Disassemble – Split a single XML file (or directory of XML files) into many smaller files, grouped by structure.
- Reassemble – Merge disassembled files back into the original XML. Uses the XML declaration and root attributes from the disassembled files, with sensible defaults when missing.
- Round-trip safe – Disassembled output includes the original XML declaration and
xmlnson the root; reassembly preserves order and content so the result matches the source. - Library API – Use
DisassembleXmlFileHandler,ReassembleXmlFileHandler,parse_xml, andbuild_xml_stringfrom your own Rust code.
Installation
From crates.io
- Install the Rust toolchain (rust-lang.org/tools/install).
- Run:
From source
The binary will be at target/release/xml-disassembler (or xml-disassembler.exe on Windows).
Usage
CLI
# Disassemble an XML file or directory (output written alongside the source)
# Reassemble a disassembled directory (writes one XML file next to the directory)
# Parse and rebuild a single XML file (useful for testing the parser)
Disassemble options
| Option | Description | Default |
|---|---|---|
--unique-id-elements <list> |
Comma-separated element names used to derive filenames for nested elements | (none) |
--prepurge |
Remove existing disassembly output before running | false |
--postpurge |
Delete original file/directory after disassembling | false |
--ignore-path <path> |
Path to the ignore file | .xmldisassemblerignore |
--format <fmt> |
Output format: xml, ini, json, json5, toml, yaml | xml |
--strategy <name> |
unique-id or grouped-by-tag | unique-id |
Reassemble options
| Option | Description | Default |
|---|---|---|
<extension> |
File extension/suffix for the rebuilt XML (e.g. permissionset-meta.xml) | xml |
--postpurge |
Delete disassembled directory after successful reassembly | false |
Examples:
# Creates fixtures/general/HR_Admin/ with disassembled files
# Creates fixtures/general/HR_Admin.xml
As a library
use ;
async
Testing
Run all tests:
- Unit tests – In-module tests for parsers, builders, and merge logic (e.g.
strip_whitespace,merge_xml_elements,extract_root_attributes,parse_xml). - Integration test –
tests/disassemble_reassemble.rsruns a full round-trip: disassemble a fixture XML, reassemble it, and assert the reassembled content equals the original file.
License
Licensed under MIT.
Contribution
See CONTRIBUTING.md.