Disassemble large XML files into smaller, modular files in formats like XML, INI, JSON, JSON5, TOML, or YAML—then reassemble them as needed.
Designed for improved version control, cleaner diffs, and easier team collaboration when dealing with complex XML structures.
- Disassemble XML Files – Break down XML into smaller components.
- Reassemble XML – Rebuild the original XML from disassembled parts.
- Multiple Output Formats – Choose XML, INI, JSON, JSON5, TOML, or YAML.
-
Two Disassembly Strategies – Choose between
unique-id
(default) orgrouped-by-tag
. - Ignore Rules – Exclude files from processing using an ignore file.
-
Logging – Log errors and debug information using
log4js
. - Salesforce Integration – Supports use cases like Salesforce metadata processing.
Note: Reassembly guarantees element-level fidelity, but element order may vary—especially when using TOML.
Table of Contents
Managing large XML files—especially those generated by tools—can be painful. xml-disassembler
solves this by splitting them into digestible pieces, optimized for Git diffs and team workflows.
No need for complex diffing tools—just structured directories with format-flexible files.
Install the package using NPM:
npm install xml-disassembler
import { DisassembleXMLFileHandler } from "xml-disassembler";
const handler = new DisassembleXMLFileHandler();
await handler.disassemble({
filePath: "test/baselines/general",
uniqueIdElements:
"application,apexClass,name,externalDataSource,flow,object,apexPage,recordType,tab,field",
prePurge: true,
postPurge: true,
ignorePath: ".xmldisassemblerignore",
format: "json",
strategy: "unique-id",
});
Option | Description |
---|---|
filePath |
Path to the XML file or directory |
uniqueIdElements |
Comma-separated list of UID elements for naming nested files |
prePurge |
Delete previous disassembly output before running (true or false , default false ) |
postPurge |
Delete the original XML after disassembly (true or false , default false ) |
ignorePath |
Path to the ignore file (default .xmldisassemblerignore ) |
format |
Output format: xml , ini , json , json5 , toml , yaml
|
strategy |
Disassembly strategy: unique-id or grouped-by-tag
|
This is the strategy all previous versions of the
xml-disassembler
follow.
Each nested element is written to a separate file based on its unique identifier—or a SHA-256 hash fallback. Leaf elements remain grouped in a file named after the original XML.
Best for detailed diffs and granular version control.
Example Outputs
Format | UID Example | Hash Example |
---|---|---|
XML |
![]() |
![]() |
YAML |
![]() |
![]() |
JSON |
![]() |
![]() |
JSON5 |
![]() |
![]() |
TOML |
![]() |
![]() |
INI |
![]() |
![]() |
Groups all nested elements by tag into a single file. Leaf elements still go into a base file named after the original XML.
Best for fewer files and easier manual inspection.
Example Outputs
Format | Grouped by Tag Example |
---|---|
XML |
![]() |
YAML |
![]() |
JSON |
![]() |
JSON5 |
![]() |
TOML |
![]() |
INI |
![]() |
import { ReassembleXMLFileHandler } from "xml-disassembler";
const handler = new ReassembleXMLFileHandler();
await handler.reassemble({
filePath: "test/baselines/general/HR_Admin",
fileExtension: "permissionset-meta.xml",
postPurge: true,
});
Option | Description |
---|---|
filePath |
Directory containing disassembled files to reassemble |
fileExtension |
Extension for the output XML file (default: .xml ) |
postPurge |
Delete disassembled files after successful reassembly (true or false , default false ) |
See sf-decomposer
for a Salesforce CLI use case.
Create an ignore file, similar to a .gitignore
, to exclude XMLs from disassembly.
uses
node-ignore
Uses fast-xml-parser
with support for:
- Character Data (CDATA):
"![CDATA["
- Comments:
"!---"
- Attributes:
"@__**"
Logging uses log4js
. Logs are written to disassemble.log
.
import { setLogLevel } from "xml-disassembler";
setLogLevel("debug"); // Enables verbose logging
Contributions are welcome! See Contributing.
This project was created from a template by Allan Oricil.
His original license remains in this project.