PHPackages                             edujugon/xml-mapper - 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. edujugon/xml-mapper

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

edujugon/xml-mapper
===================

XMLMapper for Laravel and PHP

1.6.0(8y ago)26661MITPHP

Since Oct 29Pushed 8y ago2 watchersCompare

[ Source](https://github.com/Edujugon/XMLMapper)[ Packagist](https://packagist.org/packages/edujugon/xml-mapper)[ RSS](/packages/edujugon-xml-mapper/feed)WikiDiscussions master Synced 2w ago

READMEChangelog (10)Dependencies (2)Versions (17)Used By (0)

XMLMapper for Laravel and PHP
=============================

[](#xmlmapper-for-laravel-and-php)

Are you working with xml data? then this package is for you. This is the simplest API to interact with XML data.

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

[](#installation)

type in console:

```
composer require edujugon/xml-mapper

```

Laravel 5.\*
------------

[](#laravel-5)

**Laravel 5.5 or higher?**

Then you don't have to either register or add the alias, this package uses Package Auto-Discovery's feature, and should be available as soon as you install it via Composer.

(Laravel &lt; 5.5) Register the XMLMapper service by adding it to the providers array.

```
'providers' => array(
    ...
    Edujugon\XMLMapper\Providers\XMLMapperServiceProvider::class
)
```

(Laravel &lt; 5.5) Let's add the Alias facade, add it to the aliases array.

```
'aliases' => array(
    ...
    'XMLMapper' => Edujugon\XMLMapper\Facades\XMLMapper::class,
)
```

Usage samples
-------------

[](#usage-samples)

```
$mapper = new Edujugon\XMLMapper\XMLMapper();
$mapper->loadXML($xmlData);
```

or

```
$mapper = new Edujugon\XMLMapper\XMLMapper($xmlData);
```

or with Laravel Facade

```
$mapper = XMLMapper::loadXML($xmlData);
```

> Don't forget to use the facade use statement at the top of your class: `use Edujugon\XMLMapper\Facades\XMLMapper;`

#### Get value

[](#get-value)

> You must know the tags path. Otherwise you should use [findValue](https://github.com/edujugon/XMLMapper#find-value).

```
$value = $mapper->getvalue(['first-tag','second-tag','my-tag']);
```

The above example takes the value of the tag with name **my-tag**.

> If no parameter passed to the method it looks up the value of the first (parent) tag.

#### Get attribute

[](#get-attribute)

> You must know the tags path. Otherwise you should use [findAttribute](https://github.com/edujugon/XMLMapper#find-attribute).

```
$att = $mapper->getAttribute('id',['first-tag','second-tag','my-tag']);
```

The above example returns the value of the **id** attribute in **my-tag**.

#### Get element

[](#get-element)

Get a new instance of XMLMapper but with the **tag-name** element as base xml.

```
$newXmlMapper = $mapper->getElement('tag-name');
```

#### Get elements

[](#get-elements)

Get an array of XMLMapper objects based on the **tag-name** xml element.

```
$arrayOFXmlMappers = $mapper->getElement('tag-name');
```

#### Find value

[](#find-value)

```
$value = $mapper->findValue('my-tag');
```

It looks for the first tag called **my-tag** and returns its value.

#### Find attribute

[](#find-attribute)

Get the attribute value of a tag.

```
$att = $mapper->findAttribute('my-att','my-tag');
```

It looks for the first tag called **my-tag**, then try to find **my-att** as attribute and returns its value.

If no tag passed, it takes the first attribute matching the provided attribute name:

```
$att = $mapper->findAttribute('my-att');
```

#### Find attribute by condition

[](#find-attribute-by-condition)

Loop through all elements trying to match the condition/s. When found, returns the value of the provided attribute.

```
$att = $mapper->findAttributeWhere('my-att',['id'=>1,'dev'=> 'edu',['name','!=','john']])
```

> [Check allowed where operators](https://github.com/edujugon/XMLMapper#where-operators)

#### Find attributes of a tag

[](#find-attributes-of-a-tag)

Get an object with those attributes as object properties. First it searches the tag and then retrieves the requested attributes.

```
$obj = $mapper->findAttributes(['att-1','att-2'],'my-tag')

$name = $obj->name;
$dev = $obj->dev;
```

If no tag provided, it takes the first tag that has those attributes and return the values.

#### Find attributes by condition

[](#find-attributes-by-condition)

Loop through all elements trying to match the condition/s. When found, returns an object with those attributes as object properties.

```
$obj = $mapper->findAttributesWhere(['att-1','att-2'],['dev'=> 'edu',['name','!=','john']])
```

> [Check allowed where operators](https://github.com/edujugon/XMLMapper#where-operators)

#### Find all attributes of a tag

[](#find-all-attributes-of-a-tag)

Get an array of objects with the tag attributes as properties

```
$list = $mapper->findAllAttributesOf('tag-name');
```

#### Find all attributes of a tag by condition

[](#find-all-attributes-of-a-tag-by-condition)

Get an array of objects with attributes as properties matching the provided tag name and condition.

```
$list = $mapper->findAllAttributesOfWhere('tag-name',['dev'=> 'edu',['name','!=','john']])
```

> [Check allowed where operators](https://github.com/edujugon/XMLMapper#where-operators)

#### Where operators

[](#where-operators)

Allowed where syntax.

Default:

- **key =&gt; value** pair. Will be treated as **==**

```
 ['id' => 1,'name' => 'my name']

```

Custom:

- !=
- !==
- ===
- contains
- containsCaseInsensitive

```
[['name','!=','john'],['id','!=',7]]
[['name','contains','john']]

```

They can be combined

```
['id' => 1,['name','!=','john']]

```

#### Replace tag names

[](#replace-tag-names)

You can easily replace any tag name of the xml for an easier access.

```
$mapper->replaceTagName(
    [
        'a10:author' => 'author',
        'a10:name' => 'name',
        'a10:updated' => 'updated'
    ]
);
```

The above snippet replaces all tags with names matching the keys and sets their values as new tag names. Also updates the underlying object based on the new xml.

#### Merge a new xml into the existing one

[](#merge-a-new-xml-into-the-existing-one)

You can easily merge a new xml into the existing one. It sets it as child of the provided tag.

```
$mapper->mergeXML($newXml, 'desiredParentTag');
```

#### Wrap the current xml with a custom tag

[](#wrap-the-current-xml-with-a-custom-tag)

```
$mapper->wrapWith('tagName');
```

#### Add attributes

[](#add-attributes)

```
$mapper-addAttributes(['attr1' => 'value1', 'attr2' => 'value2']);
or
$mapper-addAttributes(['attr1' => 'value1', 'attr2' => 'value2'], 'tagName');
```

Enjoy :)

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity71

Established project with proven stability

 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 ~14 days

Recently: every ~5 days

Total

15

Last Release

3014d ago

Major Versions

0.1.0 → 1.0.02018-04-07

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/4853751?v=4)[Eduardo Marcos](/maintainers/edujugon)[@Edujugon](https://github.com/Edujugon)

---

Top Contributors

[![Edujugon](https://avatars.githubusercontent.com/u/4853751?v=4)](https://github.com/Edujugon "Edujugon (30 commits)")

---

Tags

xmldata

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/edujugon-xml-mapper/health.svg)

```
[![Health](https://phpackages.com/badges/edujugon-xml-mapper/health.svg)](https://phpackages.com/packages/edujugon-xml-mapper)
```

PHPackages © 2026

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