PHPackages                             vregistry/mergexml - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. vregistry/mergexml

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

vregistry/mergexml
==================

Merge multiple XML sources from strings, files, DOM objects

1.1.2(6y ago)91.3k8[2 issues](https://github.com/hareko/php-merge-xml/issues)MITPHPPHP &gt;=5.3.0

Since Jul 15Pushed 6y ago4 watchersCompare

[ Source](https://github.com/hareko/php-merge-xml)[ Packagist](https://packagist.org/packages/vregistry/mergexml)[ Docs](https://github.com/hareko/php-merge-xml)[ RSS](/packages/vregistry-mergexml/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)DependenciesVersions (2)Used By (0)

PHP MergeXML class
==================

[](#php-mergexml-class)

The class allows to merge the XML sources (files, strings, objects) into single DOM XML object. The merging is performed recursively on the node level adding new elements and replacing existing ones. The nodes with the same path/name are replaced/added sequentially and the modification can be controlled by the options.

MergeXML could be useful in cases where it is necessary to gather XML data from multiple sources. For example, to join the configuration files of different subsystems depending on the system operation.

The usage
---------

[](#the-usage)

**$oMX = new MergeXML(\[$opts\]);**

$opts - the options array:

- join - common root name if any source has different root name (default is *root*, specifying *false* denies different names)
- updn - traverse the nodes by name sequence (*true*, default) or overall sequence (*false*)
- stay - the destination node *stay* attribute value to deny overwriting of specific node (default is *all*, can be array of values or empty)
- keep - the source node *keep* attribute value to deny overwriting of specific node (default is *all*, can be array of values or empty)

**$oMX-&gt;AddFile($file)**;

> $file - XML file's pathed name

**$oMX-&gt;AddSource($source)**;

> $source - XML string or DOM object

The methods merge a sequent source and return the final object or *false* if failed (see *error* property below).

You can search in the result object:

**$oMX-&gt;Query($expr)**;

> $expr - XPath query expression

You can get the XML result tree:

**$oMX-&gt;Get(\[0|1|2\])**;

- 0 - object (default)
- 1 - text
- 2 - html

The result object can be accessed also via *$oMX-&gt;dom* property. The properties available:

- **dom** - result XML DOM object
- **dxp** - result XPath object
- **nsp** - namespaces array (prefix =&gt; URI)
- **count** - number of sources merged
- **error** - error information
    - error-&gt;code ('' is ok)
    - error-&gt;text

The sources must have the same default namespace (if have at all). Prefix '\_' is reserved to handle default namespace.

The package
-----------

[](#the-package)

The following files are included:

1. *mergexml.php* - the MergeXML class; requires PHP 5.3+;
2. *example.html* - client-side to select the xml files and display result;
3. *example.php* - server-side to receive &amp; pass the xml data and return result;
4. *test1.xml, test2.xml* - test data for the example;
5. *packxml.php* - utility class to minify XML source.

The MergeXML is realized also in JavaScript (see [github.com](http://www.github.com/hareko/js-merge-xml)).

ChangeLog
---------

[](#changelog)

May 2014

- *mergexml.php*
    - *stay* parameter is added for *AddFile* and *AddSource* methods
    - *NameSpaces* method is added to register/xpath 1st (single) source

September 2015

- *mergexml.php*
    - *fmt* and *enc* parameters are added
- *packxml.php* utility is added to compress the XML string

December 2015

- *mergexml.php*
    - *keep* parameter is added for *\_\_construct*, *AddFile* and *AddSource* methods

April 2017

- *mergexml.php*
    - [PackApp](http://vregistry.com/packapp) obfuscation compatibility

May 2018

- *mergexml.php*
    - case-insensitive encoding checking

July 2019

- *example.html*
    - select multiple files (html5)

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance16

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 93.8% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

2499d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/d36bf0a3df1c41c0f7cd65312cb63103afef04f7615685f45b23b34752536d03?d=identicon)[hareko](/maintainers/hareko)

---

Top Contributors

[![hareko](https://avatars.githubusercontent.com/u/5305047?v=4)](https://github.com/hareko "hareko (45 commits)")[![thefzn](https://avatars.githubusercontent.com/u/6424158?v=4)](https://github.com/thefzn "thefzn (3 commits)")

---

Tags

xmlmerge

### Embed Badge

![Health badge](/badges/vregistry-mergexml/health.svg)

```
[![Health](https://phpackages.com/badges/vregistry-mergexml/health.svg)](https://phpackages.com/packages/vregistry-mergexml)
```

###  Alternatives

[masterminds/html5

An HTML5 parser and serializer.

1.8k242.8M229](/packages/masterminds-html5)[jms/serializer

Library for (de-)serializing data of any complexity; supports XML, and JSON.

2.3k135.8M851](/packages/jms-serializer)[jms/metadata

Class/method/property metadata management in PHP

1.8k152.8M88](/packages/jms-metadata)[jms/serializer-bundle

Allows you to easily serialize, and deserialize data of any complexity

1.8k89.3M627](/packages/jms-serializer-bundle)[hassankhan/config

Lightweight configuration file loader that supports PHP, INI, XML, JSON, and YAML files

97513.5M170](/packages/hassankhan-config)[sabre/xml

sabre/xml is an XML library that you may not hate.

52832.2M131](/packages/sabre-xml)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
