PHPackages                             aydin-hassan/xml-fuse - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. aydin-hassan/xml-fuse

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

aydin-hassan/xml-fuse
=====================

Small Library to turn merge data using XPaths

0.4.0(10y ago)15.7kMITPHPPHP &gt;=5.4

Since Jul 5Pushed 10y ago1 watchersCompare

[ Source](https://github.com/AydinHassan/XmlFuse)[ Packagist](https://packagist.org/packages/aydin-hassan/xml-fuse)[ RSS](/packages/aydin-hassan-xml-fuse/feed)WikiDiscussions master Synced today

READMEChangelog (4)Dependencies (3)Versions (7)Used By (0)

XmlFuse
=======

[](#xmlfuse)

[![Build Status](https://camo.githubusercontent.com/1ee09f1bc96acd3cb3f51b06799569a5d5341de78e457b3793f9e560c3f8b3a9/68747470733a2f2f7472617669732d63692e6f72672f417964696e48617373616e2f586d6c467573652e737667)](https://travis-ci.org/AydinHassan/XmlFuse)[![Coverage Status](https://camo.githubusercontent.com/63f53b2ff1b63a210c552a2dc9dc2130782e067386697b29fab025a73331b83d/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f417964696e48617373616e2f586d6c467573652e737667)](https://coveralls.io/r/AydinHassan/XmlFuse)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/3c0ce1f37836714af3b1ba5669e7242f4c67479d51fad571ce20082746ce7bd8/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f417964696e48617373616e2f586d6c467573652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/AydinHassan/XmlFuse/?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/f0fc47fcd7e19daa7a8a6b55ee4f46f3bb260ee0a68db05f0b900805bb6c1efe/68747470733a2f2f706f7365722e707567782e6f72672f617964696e2d68617373616e2f786d6c2d667573652f76657273696f6e2e737667)](https://packagist.org/packages/aydin-hassan/xml-fuse)[![Latest Untable Version](https://camo.githubusercontent.com/6e24b6e218de53ee90e22e5b59af30c491ce5a0ceb8ec4c7ad8e4ad4e4c820c6/68747470733a2f2f706f7365722e707567782e6f72672f617964696e2d68617373616e2f786d6c2d667573652f762f756e737461626c652e706e67)](https://packagist.org/packages/aydin-hassan/xml-fuse)

A Small library for merging scalar data from multiple XPaths's. Similar to an SQL Join, but using XML.

This library is useful if you want to convert XML data into a flat format. This is useful for a source agnostic approach. For example, you may process data from multiple source but want to normalise them all to a similar format.

This library aims to convert 3 dimensional data in to a flat array. Take the following XML as an example:

```

    01
    aydin@hotmail.co.uk

            1
            2
            despatched

            5
            1
            despatched

```

Imagine an import which updates the status of each item associated with an order. The import only accepts a flat array of data and can only process one item at a time. In order to update the status of an Item, the import must also know the order ID in order to load it and interact with its items.

We could use an xpath to loop each order item like so: `//order/lines/line` and this would give us all the item information, but we still don't have the order ID in the data. What if we could get the data like so:

```
array(2) {
  [0] =>
  array(5) {
    'orderId' => string(2) "01"
    'customerEmail' => string(19) "aydin@hotmail.co.uk"
    'id' => string(1) "1"
    'qty' => string(1) "2"
    'status' => string(10) "despatched"
  }
  [1] =>
  array(5) {
    'orderId' => string(2) "01"
    'customerEmail' => string(19) "aydin@hotmail.co.uk"
    'id' => string(1) "5"
    'qty' => string(1) "1"
    'status' => string(10) "despatched"
  }
}
```

This data structure is each of the nodes within each `` embedded with the parent node's data. We can succesfully pass each of these data structures to our order status updater class, and it has all the data it needs to do its work.

Installation
------------

[](#installation)

### Composer

[](#composer)

```
composer require aydin-hassan/xml-fuse
```

Usage
-----

[](#usage)

To use the tool you should instantiate the XmlFuser class, passing in your XML and the XPath's you want to combine. You can then call `parse()` to get an array of records back.

#### Example:

[](#example)

```
$xml = '

    01
    aydin@hotmail.co.uk

            1
            2
            despatched

            5
            1
            despatched

';

$xPaths = [
    '//order',
    'lines/line'
];

$fuser = new \AydinHassan\XmlFuse\XmlFuse($xml, $xPaths);
$res = $fuser->parse();

var_dump($res);

//Output
array(2) {
  [0] =>
  array(5) {
    'orderId' => string(2) "01"
    'customerEmail' => string(19) "aydin@hotmail.co.uk"
    'id' => string(1) "1"
    'qty' => string(1) "2"
    'status' => string(10) "despatched"
  }
  [1] =>
  array(5) {
    'orderId' => string(2) "01"
    'customerEmail' => string(19) "aydin@hotmail.co.uk"
    'id' => string(1) "5"
    'qty' => string(1) "1"
    'status' => string(10) "despatched"
  }
}
```

### What's going on?

[](#whats-going-on)

Each of the XPath's passed in to the parser are processed in the order they are given. So the XML will be loaded and the first XPath search will be performed. This will produce an array of nodes (of which there is one).

Each piece of data in the node, which isn't a nested structure will be moved to an array. So we have: orderId &amp; customerEmail:

```
[
   'orderId' => 1,
   'customerEmail' => 'aydin@otmail.co.uk',
]
```

 is skipped because it is a nested structure.

Now from this point, the next XPATH is searched, remember our current position? (). Our second XPath is: `lines/line` this will return an array of nodes.

Now each nodes scalar data (non-nested) is converted to an array. Eg:

```
[
   'id' => '1',
   'qty' => '1',
   'status' => 'despatched',
]
```

It is then merged with the data from the parent search, the node. Which will leave us with:

```
[
   'orderId' => 1,
   'customerEmail' => 'aydin@otmail.co.uk',
   'id' => '1',
   'qty' => '1',
   'status' => 'despatched',
]
```

This is then repeated for each node.

Notes
-----

[](#notes)

1. Any amount of XPaths can be given, if they return no results, then no merging will be done, the parent will be returned instead.
2. You can use the `setXPaths()` method to pass in a new set of XPaths, and call the `parse()` method to reparse the XML.

Contributing &amp; Running Tests
--------------------------------

[](#contributing--running-tests)

```
git clone git@github.com:AydinHassan/XmlFuse.git
cd XmlFuse
composer install
./vendor/bin/phpunit

//make sure you run the lint process aswell
./vendor/bin/phpcs --standard=PSR2 ./src
./vendor/bin/phpcs --standard=PSR2 ./test
```

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

Every ~97 days

Total

5

Last Release

3991d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2817002?v=4)[Aydin Hassan](/maintainers/AydinHassan)[@AydinHassan](https://github.com/AydinHassan)

---

Top Contributors

[![AydinHassan](https://avatars.githubusercontent.com/u/2817002?v=4)](https://github.com/AydinHassan "AydinHassan (15 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/aydin-hassan-xml-fuse/health.svg)

```
[![Health](https://phpackages.com/badges/aydin-hassan-xml-fuse/health.svg)](https://phpackages.com/packages/aydin-hassan-xml-fuse)
```

PHPackages © 2026

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