PHPackages                             graze/xml-utils - 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. graze/xml-utils

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

graze/xml-utils
===============

XML utilities, mainly conversion between XML &lt;=&gt; array.

v1.1.0(8y ago)118.6k↓34.6%11MITPHPPHP &gt;=5.5CI failing

Since Mar 7Pushed 8y ago10 watchersCompare

[ Source](https://github.com/graze/xml-utils)[ Packagist](https://packagist.org/packages/graze/xml-utils)[ Docs](https://github.com/graze/xml-utils)[ RSS](/packages/graze-xml-utils/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (2)Dependencies (3)Versions (4)Used By (1)

xml-utils
=========

[](#xml-utils)

[![Latest Version on Packagist](https://camo.githubusercontent.com/84b1922c8a78622fd5fa589a0fcd37067ee9b523021ffdc078e130febb110ad1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6772617a652f786d6c2d7574696c732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/graze/xml-utils)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Build Status](https://camo.githubusercontent.com/e283b149a08c4686328ad297ba07e6ea6447c8c74c2652e9607b7f508fc1ae66/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6772617a652f786d6c2d7574696c732f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/graze/xml-utils)[![Coverage Status](https://camo.githubusercontent.com/4d8c4675413db0817677c906363d44de15dc86bcefed253df121a7e56e29abf7/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f6772617a652f786d6c2d7574696c732e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/graze/xml-utils/code-structure)[![Quality Score](https://camo.githubusercontent.com/b4d16cdb0f1bd3076547b3bfdba0d3f298c213013b90311c3b8c39eb37ae3719/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6772617a652f786d6c2d7574696c732e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/graze/xml-utils)[![Total Downloads](https://camo.githubusercontent.com/3c14776f4d3208423d074b360c0991bcecc11a9ed565215ac2e45f5e0e079146/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6772617a652f786d6c2d7574696c732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/graze/xml-utils)

XML utilities, mainly conversion between XML &lt;=&gt; array.

Install
-------

[](#install)

Via Composer

```
$ composer require graze/xml-utils
```

Usage
-----

[](#usage)

### Converting an array to XML

[](#converting-an-array-to-xml)

```
$array = [
    'child1' => 111,
    'child2' => 222
];

$xmlElement = new SimpleXMLElement('');

$xmlConverter = new Graze\XmlUtils\XmlConverter();
$xmlConverter->addArrayAsChildren($array, $xmlElement);

echo $xmlElement->asXml();
```

result:

```
?xml version="1.0"?>
111222

```

#### Attributes

[](#attributes)

Attributes are supported by using `@attributes` key with an array of attribute name =&gt; value.

```
$array = [
    'child1' => [
        '@attributes' => [
            'id' => 123
        ]
    ]
];

```

result:

```

```

#### Attributes with value

[](#attributes-with-value)

If a value needs to be set for an element with an attribute then the `@value` key should be used.

```
$array = [
    'child1' => [
        '@attributes' => [
            'id' => 123
        ],
        '@value' => 'some description'
    ]
];

```

result:

```
some description

```

#### Repeated elements

[](#repeated-elements)

Repeated elements are supported with indexed arrays.

```
$array = [
    'child' => [
        'first',
        'second'
    ]
];

```

result:

```
firstsecond

```

### Converting XML to an array

[](#converting-xml-to-an-array)

```
$xml = '123456';

$xmlElement = new SimpleXMLElement($xml);

$xmlConverter = new XmlConverter();
$array = $xmlConverter->convertToArray($xmlElement);

```

result:

```
[
    'child1' => '123',
    'child2' => [
        '@attributes' => [
            'id' => '1'
        ],
        'subchild1' => '456'
    ]
];

```

### Formatting XML

[](#formatting-xml)

Formats XML so it is easier to read.

```
$unformattedXml = '123456';

$xmlFormatter = new XmlFormatter();
$formattedXml = $xmlFormatter->format($unformattedXml);

```

result:

```

  123

    456

```

Change log
----------

[](#change-log)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Testing
-------

[](#testing)

```
make build test
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Brendan Kay](https://github.com/brendankay)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity60

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

Total

3

Last Release

3017d ago

PHP version history (2 changes)v1.0.0PHP &gt;=5.6

v1.0.1PHP &gt;=5.5

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/637788?v=4)[graze.com](/maintainers/graze)[@graze](https://github.com/graze)

---

Top Contributors

[![brendankay](https://avatars.githubusercontent.com/u/641490?v=4)](https://github.com/brendankay "brendankay (5 commits)")

---

Tags

grazexml-utils

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/graze-xml-utils/health.svg)

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

###  Alternatives

[graze/telnet-client

Telnet client written in PHP

48242.5k4](/packages/graze-telnet-client)[agencetwogether/hookshelper

Simple plugin to toggle display hooks available in current page.

2714.0k](/packages/agencetwogether-hookshelper)[nguyendachuy/laravel-menu

Laravel Menu Builder | Drag &amp; Drop | Bootstrap | Laravel 7 | Laravel 8 | Laravel 9 | Laravel 10 | Laravel 11 | Laravel 12

162.2k](/packages/nguyendachuy-laravel-menu)

PHPackages © 2026

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