Affiliate
Never lose a file again. Back up everything you make here with pCloud, free to startSecure Swiss cloud storage for your files, on every deviceStart free with pCloud and upgrade only if you need more spaceOne click from download to safe backup. Try pCloud free

Merge XML Files Online

This tool combines multiple XML files into one. Wrap each file in a new root, merge the children of every root under one wrapper tag you choose (for example resources for Android strings.xml), or concatenate files as-is. Runs entirely in your browser, free.

Before & After

Input: Separate XML Files
xml
<!-- products-1.xml -->
<products>
  <product id="1">
    <name>Laptop</name>
    <price>999</price>
  </product>
</products>

<!-- products-2.xml -->
<products>
  <product id="2">
    <name>Mouse</name>
    <price>25</price>
  </product>
</products>
Output: Merged XML
xml
<?xml version="1.0" encoding="UTF-8"?>
<root>
  <products>
    <product id="1">
      <name>Laptop</name>
      <price>999</price>
    </product>
  </products>
  <products>
    <product id="2">
      <name>Mouse</name>
      <price>25</price>
    </product>
  </products>
</root>

How It Works

1

Add your files

Drop .xml files or browse.

2

Choose settings

Pick Wrap, Merge Children or Concatenate, and set the wrapper tag.

3

Download

Merge, then copy the XML or download it as a file.

FAQ

Programmatic Merge

Pythonmerge_xml.py
import xml.etree.ElementTree as ET

def merge_xml_files(files, wrapper_tag="root"):
    root = ET.Element(wrapper_tag)
    
    for filepath in files:
        tree = ET.parse(filepath)
        file_root = tree.getroot()
        
        # Add all children to new root
        for child in file_root:
            root.append(child)
    
    # Create tree and write
    merged_tree = ET.ElementTree(root)
    merged_tree.write("merged.xml", encoding="utf-8", xml_declaration=True)
    print(f"Merged {len(files)} XML files")

files = ["config1.xml", "config2.xml", "config3.xml"]
merge_xml_files(files, wrapper_tag="configurations")
Bashmerge_xml.sh
#!/bin/bash
# Merge XML files with wrapper element

OUTPUT="merged.xml"
WRAPPER="root"

echo '<?xml version="1.0" encoding="UTF-8"?>' > "$OUTPUT"
echo "<$WRAPPER>" >> "$OUTPUT"

for file in configs/*.xml; do
  # Remove XML declaration and extract content
  sed '1d' "$file" | sed '/<\?xml/d' >> "$OUTPUT"
done

echo "</$WRAPPER>" >> "$OUTPUT"
echo "Merged XML files into $OUTPUT"

Complete Guide

How XML merging works - root elements and namespaces

XML requires exactly one root element. When merging two XML files, their root elements cannot both sit at the top. One wraps the other, or both become children of a new root. This is the main technical constraint when merging XML. It is also why GPS tracks need the dedicated GPX Merger: GPX files are XML, but mapping apps expect one <gpx> root, not a wrapper around two.

With the default Wrap in Root strategy, the tool creates a new wrapper element and places each file's root element inside it. For example, two files each with a <users> root become one file with a new <root> element containing both <users> sections. Merge Children goes one level deeper: the <user> records from both files sit directly under the wrapper. The wrapper tag is configurable, so you can name it whatever your target format expects. If one of your sources is a plain-text or CSV list rather than XML, turn it into records with the TXT to XML converter first, then merge.

If your files use XML namespaces (xmlns attributes), source elements keep their declarations when they are carried into the output. Merge Children also copies the first file's root attributes and namespace declarations onto the wrapper; root attributes from the other files are not copied. The tool does not resolve namespace or schema conflicts automatically. For example, if both files declare xmlns:app with different URIs, you will need to fix this.

Before: file1.xml has <users><user id="1">Alice</user></users> and file2.xml has <users><user id="2">Bob</user></users>. After merging: <root><users><user id="1">Alice</user></users><users><user id="2">Bob</user></users></root>.

With Wrap in Root and Merge Children, the merged file is a single well-formed XML document: source XML declarations, DOCTYPEs, and comments outside each root are dropped so they never end up inside the wrapper. Concatenate is different. It joins the files as-is, so the result has one root per file and is not a single well-formed document; use it only for line- or text-based processing that expects documents back to back.

Merging Android resources, Maven POMs, and RSS feeds

Android: to merge strings.xml files from multiple modules, choose Merge Children and set the wrapper tag to resources. The output is one <resources> element containing every <string> entry. Watch for duplicate resource names (like two <string name="app_name"> entries) which Android will reject at build time. You will need to rename duplicates manually after merging.

Maven: the tool does not understand POM semantics. Merging two complete pom.xml files produces duplicate <groupId>, <artifactId>, and <dependencies> sections, which is not a valid POM. To consolidate dependencies, merge files that contain only <dependency> elements using Merge Children with the wrapper tag dependencies, paste the result into your POM, and run mvn validate. If your configuration is YAML rather than XML, such as Kubernetes manifests or Docker Compose files, use the YAML Merger.

RSS/Atom: an RSS file's root is <rss> and its items sit inside <channel>, so Merge Children places each feed's <channel> (with its items) under the wrapper; it does not pull the <item> elements into one channel. That keeps every item in one file for archiving or processing, but feed readers expect a single channel, so use a feed library to build a publishable combined feed. Atom merges more directly: Merge Children with the wrapper tag feed puts every <entry> under one <feed> (along with each source's title and id elements, which you may want to remove).

API responses: combining XML payloads from paginated API calls into one document. If an API returns 100 records per page across 10 pages, Merge Children puts all 1,000 records under one wrapper, as long as the records are direct children of each response's root. For SOAP the root is the Envelope, so Merge Children collects Header and Body elements rather than the body contents; use Wrap to keep each complete message, or extract the body payloads first. If the combined file ends up too large for the system you send it to, the XML File Splitter breaks it back into well-formed chunks.

What to check after merging

Validate the output with an XML validator before using it. Run xmllint --noout file.xml in the terminal (exits with code 0 if the file is well-formed), and add --schema schema.xsd to validate against a schema. Your pipeline's own XML library is the final check. Invalid XML will break parsers and processing tools.

Check for duplicate IDs or attribute values if your schema requires uniqueness. For example, if both source files have <product id="123">, the merged file will have two elements with the same ID, which may violate your schema or cause processing errors.

Check namespace declarations at the root element. If your source files use namespaces, verify that all necessary xmlns declarations are present in the merged output. Missing namespace declarations cause parsing failures in XML processors that validate against schemas.

Related Articles