XML Diff
Compare two XML files by meaning, with every change listed by its XPath.
By Syed Mubashir Ali · Last updated
An XML diff that ignores formatting and attribute order
Try an example compares two versions of a small product feed. The second has its attributes in another order, a different comment and its tags written over several lines, none of which count. It also has a new date, a price rise, a new tag, a new product and one product out of stock. XML Diff lists those five changes:
~ /catalog/@updated: "2026-10-01" → "2026-11-01" ~ /catalog/product[1]/price/text(): "4.50" → "4.75" + /catalog/product[1]/tags/tag[3]: <tag>strong</tag> + /catalog/product[2]: <product sku="TEA-03" stock="low"><name>Earl Grey</name><price>4.95</price></product> ~ /catalog/product[3]/@stock: "in" → "out"
- JSON Diff: Compare JSON documents the same way, with JSON Patch.
- Diff Checker: Compare the files as plain text, comments and all.
What counts as a difference in XML
An attribute's value changing, or an attribute being added or removed, is reported at its path, such as /catalog/@updated. Text inside an element is reported at …/text(). An element present on only one side is added or removed as a whole, shown as compact markup.
Whitespace between elements and around text is ignored by default, because pretty-printing a file shouldn't look like an edit. Untick Ignore whitespace when spacing matters, as in mixed content where a missing space changes the words. Namespace prefixes are compared as written, so soap:Body and s:Body count as different names even if they point to the same namespace.
How to Use XML Diff
- 1Paste the original XML on the left and the changed XML on the right, or open an .xml file into either side. Try an example fills both with a product feed.
- 2If either side isn't well-formed XML, the line and column of the problem appear under that box, with a caret under it.
- 3Read the Changes list: each difference is listed by its XPath, such as /catalog/product[2]/@stock, with the old and new value. Attribute order, indentation and comments don't count.
- 4Leave Ignore whitespace on to skip formatting differences; tick Ignore child order when the order of child elements doesn't matter.
- 5Switch to Side by side to see both documents written out the same way, attributes in alphabetical order, with only the real changes highlighted.
- 6Copy the changes as text for a ticket or pull request, or copy any single path.
Frequently Asked Questions
Do attribute order, indentation and comments count as changes?
No. Attributes are compared by name, so their order never matters, and comments and processing instructions are left out. With Ignore whitespace on (the default), indentation and line breaks between elements don't count and spacing inside text is tidied, so only changed values show.
How are repeated elements matched?
Children are compared in order, and an element inserted near the top is one addition, not a change to every element after it. When every child carries an id-like attribute (id, key, name, code, sku, ref or uuid), elements are matched by it wherever they moved, and a move shows as one order change. Tick Ignore child order when order doesn't matter.
What do the paths mean?
They're XPath. /catalog/product[2]/@stock is the stock attribute of the second product, and /catalog/product[1]/price/text() is the text inside the first product's price. Numbers in brackets count from 1 among elements of the same name, as XPath does, so you can paste a path into an XPath tool.
Does it handle namespaces, CDATA and DOCTYPEs?
Prefixed names such as soap:Body are compared as written. CDATA is read as text, so <![CDATA[a<b]]> equals a<b. A DOCTYPE is skipped, and entities it declares aren't expanded: a reference to one is reported as an error, which also keeps entity-expansion attacks out.
What happens if my XML is invalid?
The tool shows the line and column of the problem with a caret under it, and says what's wrong: a closing tag that doesn't match, an attribute without quotes, a bare & or < in text, or a second root element. Fix that line and the comparison appears.
Is my XML uploaded anywhere?
No. The XML is read and compared in your browser, so configuration files, feeds and API payloads never leave your device.
About XML Diff
XML that means the same thing can be written many ways: attributes in a different order, a different indent, a comment added, an empty element written as <a></a> instead of <a/>. A line-by-line diff flags all of it. XML Diff reads both documents and compares what they say, so it lists only the elements, attributes and text that actually changed, each with an XPath you can copy.
Children are lined up the way a careful reviewer would: an element inserted near the top is one addition rather than a change to everything below it, and when elements carry an id-like attribute (id, key, name, code, sku, ref, uuid) they're matched by it even if they moved. That suits product feeds, config files, sitemaps, SOAP and API payloads, and Android or .NET project files.
The reader is strict, so it catches the mistakes that break real parsers (a closing tag that doesn't match, an unquoted attribute, a bare &) and says where they are. It never expands entities declared in a DOCTYPE, and it runs entirely in your browser: nothing is uploaded.