How to merge two XML documents
Load a base XML document and an incoming XML document as files or pasted text. XML Merge Tool checks that both roots are compatible, applies the selected child-element rule, and shows the merged tree before you export XML or the JSON merge report.
- Drop the base XML file in "Drop base XML file here", or paste it into "Or paste XML".
- Drop the incoming XML file in "Drop incoming XML file here", or paste it into the second "Or paste XML" field.
- Choose a value in "Child-element merge strategy".
- Set "Identity source" and its matching field for replace or key-based merge.
- Review "Merged tree preview" and select "Export merged XML" or "Export merge report (JSON)".
How each merge strategy changes the tree
"Append (incoming children added after base children)" adds incoming root children after the base children. It does not need an identity rule. "Replace (matched elements substituted wholesale)" replaces a matching base child with the incoming child. "Key-based merge (matched elements merged recursively)" combines matching elements and their nested children using the selected policies.
Base: <items><item id="1">Old</item></items>
Incoming: <items><item id="1">New</item></items>
Key-based merge with Selected attribute = id:
<items><item id="1">New</item></items>
An identity value with no base counterpart adds the incoming element. If an element has no identity value, the tool appends it and marks it unmatched. If several base elements share the same identity, the tool leaves the incoming element unmerged and marks it unresolved.
How identity and conflict policies work
For replace and key-based merge, choose "Selected attribute", "Direct child element", or "Supported XPath expression". The supported expressions are @attr, name(), local-name(), a direct child name for its text, and childName/@attr. The tool matches by that value, not by sibling position.
"Attribute conflict policy" and "Text-node conflict policy" can take the incoming value, keep the base value, or flag the difference as unresolved. "Sibling-order policy" either keeps base order and puts new nodes at the end or places new nodes after their matched neighbor in incoming order.
"Comment policy" applies to direct child comments. "CDATA policy" keeps CDATA sections or converts them to text. "XML declaration policy" selects the base declaration, the incoming declaration, or no declaration. "Namespace-prefix policy" keeps the original prefixes or uses the base document's prefix for each namespace URI.
What XML Merge Tool rejects or leaves unchanged
Both sources must be loaded and parse as XML. Their roots must share a local name and namespace URI, or both must have no namespace. The page blocks the merge when the roots differ. Replace and key-based merge also stop when the selected identity field is empty.
The report includes source names, selected options, counts, and added, replaced, unresolved, and unmatched entries with XPath-like locations. Append mode does not record every appended text, CDATA, or comment node. The result is merged XML, while the report is JSON. The tool does not create a compare-only diff or concatenate plain text.
Examples of merge choices
- To update matching catalog items and add new ones, choose "Selected attribute" and enter
id. - To carry a matching configuration child across as a complete element, choose "Replace (matched elements substituted wholesale)".
- To keep both sets of duplicate child records, choose "Append (incoming children added after base children)".
Choose the right XML merge page
Use XML Merge Tool when you have base and incoming documents and need to set matching, conflict, ordering, comment, CDATA, declaration, or namespace-prefix rules. Visit XML Merge Tools to choose another XML merge page.
Frequently asked questions
How do I merge two XML documents?
Load a base document and an incoming document, choose "Child-element merge strategy", then review the merged tree. Replace and key-based merge also require an identity field.
Can I combine XML files without an identity rule?
Yes. Choose "Append (incoming children added after base children)". Replace and key-based merge require "Identity source" plus a value for its field.
How does XML merge by key handle duplicate keys?
When several base elements share an identity value, the tool marks the incoming element unresolved and leaves it unmerged. An incoming element with no identity value is appended and marked unmatched.
What XPath expressions can XML Merge Tool use for identity?
It accepts @attr, name(), local-name(), a direct child name for its text, and childName/@attr. These expressions compute identity values; they do not provide general XPath querying.
Where does XML Merge Tool keep the source documents?
The page reads pasted text and selected files in the browser, then creates downloads with browser Blob objects. Its code contains no request that uploads the source documents.