パッケージの詳細

xml-disassembler

mcarvin81.4kMIT1.10.15

Disassemble XML files into smaller, more manageable files and reassemble the XML when needed.

xml, transform, transformers, disassemble

readme

xml-disassembler

NPM License Downloads/week Maintainability Code Coverage Known Vulnerabilities

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.


Features

  • 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) or grouped-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.

<summary>Table of Contents</summary> - Background - Install - Disassembling Files - Disassembly Strategies - unique-id (default) - grouped-by-tag - Reassembling Files - Use Case - Ignore File - XML Parser - Logging - Contributing - Template & License

Background

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

Install the package using NPM:

npm install xml-disassembler

Disassembling Files

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

Disassembly Strategies

unique-id (default)

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 XML UID
XML Hash
YAML YAML UID
YAML Hash
JSON JSON UID
JSON Hash
JSON5 JSON5 UID
JSON5 Hash
TOML TOML UID
TOML Hash
INI INI UID
INI Hash

grouped-by-tag

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 XML tag
YAML YAML tag
JSON JSON tag
JSON5 JSON5 tag
TOML TOML tag
INI INI tag

Reassembling Files

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)

Use Case

See sf-decomposer for a Salesforce CLI use case.


Ignore File

Create an ignore file, similar to a .gitignore, to exclude XMLs from disassembly.

uses node-ignore


XML Parser

Uses fast-xml-parser with support for:

  • Character Data (CDATA): "![CDATA["
  • Comments: "!---"
  • Attributes: "@__**"

Logging

Logging uses log4js. Logs are written to disassemble.log.

import { setLogLevel } from "xml-disassembler";

setLogLevel("debug"); // Enables verbose logging

Contributing

Contributions are welcome! See Contributing.


Template & License

This project is based on a template by Allan Oricil and licensed under the ISC license. The original code remains under the ISC license.

All contributions specific to the xml-disassembler is licensed under the MIT license.

更新履歴

Changelog

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

1.10.15 (2025-06-01)

Bug Fixes

1.10.14 (2025-06-01)

Bug Fixes

1.10.13 (2025-05-22)

Bug Fixes

  • add type to write leaf file (d436497)
  • reduce complexity in reassemble handler (94e2886)

1.10.12 (2025-05-21)

Bug Fixes

  • merge build and parse functions (db7fce3)
  • validate strategy is supported when disassembling (dc944cc)

1.10.11 (2025-05-19)

Bug Fixes

  • merge build disassemble file functions (78c4c24)

1.10.10 (2025-05-18)

Bug Fixes

  • remove parsing direct xml string (d62f159)

1.10.9 (2025-05-17)

Bug Fixes

  • normalize leaf content as arrays to simplify merging logic (2eb7ad5)

1.10.8 (2025-05-17)

Bug Fixes

  • assert non-null on root element and remove default declaration (9bd9fbd)

1.10.7 (2025-05-14)

Bug Fixes

  • write other formats directly without creating a temp xml (9717caf)

1.10.6 (2025-05-13)

Bug Fixes

  • correctly classify single nested elements on grouped by tag strategy (579360b)

1.10.5 (2025-05-13)

Bug Fixes

  • add declaration to types (1831ebe)
  • pull reassemble declaration from merged results (b6227ea)

1.10.4 (2025-05-13)

Bug Fixes

  • reassemble using xmlelement type (8ffddd3)

1.10.3 (2025-05-09)

Bug Fixes

  • use xmlelement when building leaf files (92195c3)

1.10.2 (2025-05-09)

Bug Fixes

  • build nested files using xmlelement type (877ff02)

1.10.1 (2025-05-07)

Bug Fixes

  • parse nested content directly (194c025)

1.10.0 (2025-05-07)

Features

  • update parseXML to accept a string or file (a4ec983)

1.9.3 (2025-05-07)

Bug Fixes

  • indenting on disassembled nested files (5aae642)

1.9.2 (2025-05-07)

Bug Fixes

  • remove extra indenting (f30b7b6)
  • update xml parser options (c0420c0)

1.9.1 (2025-05-06)

Bug Fixes

  • deps: bump ignore from 7.0.3 to 7.0.4 (95cf6d1)
  • deps: bump smol-toml from 1.3.1 to 1.3.4 (0e40592)

1.9.0 (2025-04-21)

Features

  • export the transformers (46ad06b)

1.8.0 (2025-04-18)

Features

  • add new disassemble strategy (9f65e31)

1.7.0 (2025-04-12)

Features

  • add ini as a disassembled format (de91154)

1.6.0 (2025-04-12)

Features

  • add toml as a disassembled format (9d0e6b8)

1.5.1 (2025-04-11)

Bug Fixes

  • upgrade fast-xml-parser (bae93c6)

1.5.0 (2025-04-11)

Features

  • add multiple disassemble file formats (09ae868)

1.4.0 (2025-04-02)

Features

  • dynamically determine xml declaration (15e8650)

1.3.15 (2025-03-18)

Bug Fixes

  • deps: bump ignore from 5.3.2 to 7.0.3 (d50e3df)

1.3.14 (2025-03-18)

Bug Fixes

  • deps: bump fast-xml-parser from 5.0.8 to 5.0.9 (c953a92)

1.3.13 (2025-03-04)

Bug Fixes

  • deps: bump fast-xml-parser from 5.0.6 to 5.0.8 (29ac5c6)

1.3.12 (2025-02-24)

Bug Fixes

  • deps: bump fast-xml-parser from 4.5.1 to 5.0.6 (6309db6)

1.3.11 (2025-01-21)

Bug Fixes

  • revert to 1.3.8 to remove parallel processing (876ff0c)

1.3.10 (2025-01-21)

Bug Fixes

  • export get concurrency threshold (1cb7cae)
  • use concurrency limit function (a8e53b8)

1.3.9 (2025-01-21)

Bug Fixes

  • add parallel processing to handlers (75ff605)

1.3.8 (2025-01-10)

Bug Fixes

  • export the xmlelement type for build xml function (f1fff2b)

1.3.7 (2025-01-10)

Bug Fixes

  • use relative imports in exported functions (c43c009)

1.3.6 (2025-01-04)

Bug Fixes

  • export parse and build xml functions (f2d08ec)

1.3.5 (2025-01-04)

Bug Fixes

  • deps: bump fast-xml-parser from 4.3.4 to 4.5.1 (f133c15)

1.3.4 (2024-12-15)

Bug Fixes

  • changelog formatting and build process (b39b482)

1.3.3 (2024-12-15)

Bug Fixes

  • normalize paths to unix style (ef0ec01)

1.3.2 (2024-05-22)

Bug Fixes

  • fix logger warning for ignore file (c462893)

1.3.1 (2024-05-22)

Bug Fixes

  • set flag for ignorePath (5b5a217)

1.3.0 (2024-05-22)

Features

  • add support for an ignore file during disassembly (553a90a)

1.2.10 (2024-04-24)

Bug Fixes

  • remove extra space in leaf file, normalize variable names, change xmlPath to filePath in classes (61a204c)

1.2.9 (2024-04-24)

Bug Fixes

  • remove leaf content sorting due to issues with multi-line leaf tags (eacc56d)

1.2.8 (2024-04-08)

Bug Fixes

  • define functions from each import over using a wildcard (1246857)
  • parse XML separately to reduce complexity (aaefd04)

1.2.7 (2024-04-08)

Bug Fixes

  • refactor processElement to not exceed arguments limit (db2bd59)

1.2.6 (2024-04-08)

Bug Fixes

  • import XmlElement type with a relative path (62d056a)
  • refactor leaf/nested element check into a function (90d8b10)
  • remove await on non-promise (39cd843)

1.2.5 (2024-04-07)

Bug Fixes

  • add newlines after root element in leaf files (c186ba8)
  • allow attributes in nested elements (6cfbc95)

1.2.4 (2024-04-01)

Bug Fixes

  • findUniqueIdElement should always return a string (e20584e)
  • switch disassembled files to async (e4c5cbc)

1.2.3 (2024-03-31)

Bug Fixes

  • preserve any attribute in the root element header (2926e59)

1.2.2 (2024-03-30)

Bug Fixes

  • set XML validator flag to true when parsing XMLs (9682cbe)

1.2.1 (2024-03-28)

Bug Fixes

  • correct sonarlint concerns (7503c2a)

1.2.0 (2024-03-28)

Features

  • allow users to delete disassembled files after reassembly (a2f68db)

1.1.5 (2024-03-12)

Bug Fixes

  • check if folder exists before pre-purging it (391d37b)

1.1.5-beta.1 (2024-03-12)

Bug Fixes

  • check if folder exists before pre-purging it (391d37b)

1.1.4 (2024-03-12)

Bug Fixes

  • fix postPurge statement placement in buildDisassembledFiles (89a7600)

1.1.4-beta.1 (2024-03-12)

Bug Fixes

  • fix postPurge statement placement in buildDisassembledFiles (89a7600)

1.1.3 (2024-03-11)

Bug Fixes

  • allow file-path to be accepted by disassemble (31ecd17)

1.1.2 (2024-03-11)

Bug Fixes

  • copy XmlElement interface into reassemble file (25e5599)
  • revert class to use fast xml parser and move build nested elements function to class (0febc42)
  • use buildNestedElements function with different starting indent level (d611430)

1.1.2-beta.3 (2024-03-11)

Bug Fixes

  • use buildNestedElements function with different starting indent level (d611430)

1.1.2-beta.2 (2024-03-11)

Bug Fixes

  • copy XmlElement interface into reassemble file (25e5599)

1.1.2-beta.1 (2024-03-10)

Bug Fixes

  • revert class to use fast xml parser and move build nested elements function to class (0febc42)

1.1.1 (2024-03-10)

Bug Fixes

  • move xmlParser constant (628f826)
  • revert reassemble class due to TS2307: Cannot find module '@src/helpers/types' (74a3300)

1.1.1-beta.2 (2024-03-10)

Bug Fixes

  • revert reassemble class due to TS2307: Cannot find module '@src/helpers/types' (74a3300)

1.1.1-beta.1 (2024-03-10)

Bug Fixes

  • move xmlParser constant (628f826)

1.1.0 (2024-03-10)

Features

  • rename purge flag to prePurge and add postPurge flag to disassemble class (ff9fdc3)
  • use fast xml parser for reassembly (bf045a9)

1.1.0-beta.1 (2024-03-10)

Features

  • rename purge flag to prePurge and add postPurge flag to disassemble class (ff9fdc3)
  • use fast xml parser for reassembly (bf045a9)

1.0.10 (2024-03-07)

Bug Fixes

  • sort files based on name in root path (f21c989)

1.0.10-beta.1 (2024-03-07)

Bug Fixes

  • sort files based on name in root path (f21c989)

1.0.9 (2024-03-07)

Bug Fixes

  • ensure root element name is not empty when disassembling (41fdd6f)

1.0.8 (2024-03-07)

Bug Fixes

  • do not disassemble files if the file only has leaf elements (ca9efbb)

1.0.7 (2024-03-04)

Bug Fixes

  • fix root element name check, improve logging messages to reach full code coverage (9a4de6b)

1.0.6 (2024-02-23)

Bug Fixes

  • configure logging with log4js (65b106a)

1.0.6-release.1 (2024-02-23)

Bug Fixes

  • configure logging with log4js (65b106a)

1.0.5 (2024-02-22)

Bug Fixes

  • dynamically get xml namespace and add to disassembled/reassembled files if defined (59544ee)

1.0.4 (2024-02-22)

Bug Fixes

  • add purge flag to disassemble to remove any pre-existing disassembled files (c0d6049)

1.0.3 (2024-02-22)

Bug Fixes

  • switch to relative path in index (25acde7)

1.0.3-release.1 (2024-02-22)

Bug Fixes

  • switch to relative path in index (25acde7)

1.0.2 (2024-02-21)

Bug Fixes

  • ensure xmlPath is a directory (5076799)
  • remove the root xml element as a reassemble flag and dynamically get it from a disassembled file in the path (849cf3b)

1.0.1 (2024-02-21)

Bug Fixes

  • ensure all matches of duplicate parent elements are removed in the reassembled file, including opening tags which have the namespace in them (f9e7919)
  • include root element tags in all disassembled files (2a24cd2)
  • remove xmlElement flag. this can be found in the original XML file and set dynamically in the leaf file. (847f4ed)
  • update tsconfig includes value (d92afcb)
  • use the full name of the original file to name the disassembled leaf file (1f56382)

1.0.1-release.2 (2024-02-21)

Bug Fixes

  • update tsconfig includes value (d92afcb)

1.0.1-release.1 (2024-02-21)

Bug Fixes

  • ensure all matches of duplicate parent elements are removed in the reassembled file, including opening tags which have the namespace in them (f9e7919)
  • include root element tags in all disassembled files (2a24cd2)
  • remove xmlElement flag. this can be found in the original XML file and set dynamically in the leaf file. (847f4ed)
  • use the full name of the original file to name the disassembled leaf file (1f56382)

1.0.0 (2024-02-21)

Bug Fixes

  • add jests to tsconfig (d90f1ec)
  • add types node to tsconfig.json (9fb9a64)
  • re-add index file, rename package due to existing xml-transformer package (9d67cdc)

Features