How to compare XML files
Put the two documents in List A and List B. XML Diff parses each one as a tree and lists Added, Removed, and Changed entries with a node type and XPath-like location. The comparison covers elements, attributes, namespaces, text, CDATA, comments, and XML declaration values.
Compare XML files in four steps
- Paste or type the first document in List A and the second in List B. You can also choose the Upload control below each list to load an XML or TXT file.
- Choose By document order (preserves sibling order) or By identity attribute (order-insensitive).
- For identity matching, enter the attribute name in Identity attribute name. The comparison runs once both inputs contain text.
- Review Differences, adjust the change and node type filters, then choose Export JSON or Export CSV. Show all differences restores every entry. Clear inputs removes both documents and resets the controls.
An empty input is rejected. Invalid XML shows a parse error for the affected document, and Differences stays hidden until both documents parse.
How XML Diff matches sibling elements
By document order (preserves sibling order) pairs child nodes by position. Moving a sibling can therefore produce a Removed entry and an Added entry. By identity attribute (order-insensitive) pairs same-tag elements by the value in Identity attribute name when that attribute is present. Elements without that attribute use position. Duplicate values can overwrite one another in the keyed comparison.
List A: <root><item id="1">Alice</item></root>
List B: <root><item id="1">Alicia</item></root>
changed | text | /root[1]/item[1]/text()[1] | Alice -> Alicia
What XML Diff compares and ignores
XML Diff skips whitespace-only text nodes and trims leading and trailing whitespace from text, CDATA, and comment values before comparing them. Attribute order does not create a difference because attributes are matched by name. Declaration changes include version, encoding, and standalone values.
Processing instructions and document type nodes do not appear in the results. Each Differences row has Kind, Node type, Location, and Value. The Added, Removed, Changed, Element, Attribute, Text, CDATA, Comment, Namespace, and Declaration filters change the visible rows and the rows included in Export JSON and Export CSV. Totals are calculated before filtering.
The browser processes pasted XML and uploaded files with DOMParser and FileReader. The page code does not send the document contents in a network request. JSON and CSV reports are created as local downloads.
Where XML comparison comes up
- Check an application configuration before and after a deployment, then filter for Changed elements or attributes.
- Compare two XML exports from a catalog or data pipeline, then export the filtered rows as CSV.
- Compare a migrated document with the original and use an identity attribute such as
idto pair reordered records.
When to use XML Diff
Use XML Compare Tools when you need to choose among XML comparison tasks. XML Diff is for parsed-tree changes with node types, XPath-like locations, and JSON or CSV output. Choose document order when position controls pairing, or identity matching when a shared attribute should pair same-tag siblings.
Frequently asked questions
How do I compare two XML files by structure?
Paste the documents into List A and List B, then review the parsed-tree entries in Differences. Each row identifies the change kind, node type, location, and value.
Does XML Diff ignore indentation and attribute order?
Yes. Whitespace-only text nodes are skipped, collected text values are trimmed at the edges, and attributes are matched by name rather than position.
What does By identity attribute do in XML Diff?
It pairs same-tag elements by the value in the selected identity attribute when present. Elements without that attribute use positional matching, and duplicate values can overwrite one another.
Can I export an XML diff report?
Yes. Choose Export JSON or Export CSV after filtering the Differences table. The export contains the rows that match the selected change and node type filters.