skills/compare-xml
compare-xml
Use npx @compare-xml/cli to compare two XML values and identify their differences.
Online Playground
Try it out at https://comparexml.com
Usage
npx @compare-xml/cli <base> <contrast> [options]
Each positional argument can be either an inline XML string or a path to an XML file. The CLI resolves the value at runtime: if it matches an existing file, the file is read and parsed; otherwise the argument itself is parsed as XML.
Arguments
<base>— Base XML string or file path<contrast>— Contrast XML string or file path
Options
-a, --array-compare-method <method>— Array compare method, one ofbyIndex(default),lcs,unorderedbyIndex— Compare arrays by index positionlcs— Minimal diff for ordered arrays via Longest Common Subsequenceunordered— Treat arrays as multisets
-k, --key-case-insensitive— Case-insensitive key comparison-v, --value-case-insensitive— Case-insensitive value comparison-j, --json-export— Output as JSON instead of the default table-o, --output <file>— Write the output to a file instead of stdout
Examples
Compare two XML strings:
npx @compare-xml/cli '<root><name>Alice</name></root>' '<root><name>Bob</name></root>'
Compare two XML files:
npx @compare-xml/cli base.xml contrast.xml
Case-insensitive keys:
npx @compare-xml/cli '<root><Name>Alice</Name></root>' '<root><name>Alice</name></root>' -k
LCS array comparison — minimal diff for ordered arrays:
npx @compare-xml/cli '<root><items><item>1</item><item>2</item><item>3</item></items></root>' '<root><items><item>2</item><item>3</item><item>4</item></items></root>' -a lcs
JSON output:
npx @compare-xml/cli base.xml contrast.xml -j
Save output to a file:
npx @compare-xml/cli base.xml contrast.xml -o diff.txt
Combine tolerance options:
npx @compare-xml/cli '<root><Name>Alice</Name></root>' '<root><name>ALICE</name></root>' -k -v
Output Format
By default, results are printed as a Unicode box-drawn table. Each row is labeled with the side that owns the path: (Base) for value changes and deletions, (Contrast) for additions, and (Root) when the top-level value itself differs.
┌──────────────┬──────────────┐
│ Key │ Change Type │
├──────────────┼──────────────┤
│ (Base) a │ valueChanged │
│ (Base) b │ deleted │
│ (Contrast) c │ added │
└──────────────┴──────────────┘
When the two inputs match exactly, the output is simply No differences found.
With --json-export (-j), the same data is emitted as JSON:
[
{
"pathSegments": ["root", "name"],
"pathString": "root.name",
"pathBelongsTo": "both",
"diffType": "valueChanged"
}
]
Difference Types
added— Value exists incontrastbut not inbasedeleted— Value exists inbasebut not incontrastvalueChanged— Value changed between base and contrast
