PHPackages                             mehr-it/easy-xml - 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. mehr-it/easy-xml

ActiveLibrary

mehr-it/easy-xml
================

Easy XML handling (read/write) for large files

2.2.0(2y ago)09.9k—0%MITPHPPHP &gt;=7.1.0CI failing

Since Mar 6Pushed 2y agoCompare

[ Source](https://github.com/mehr-it/easy-xml)[ Packagist](https://packagist.org/packages/mehr-it/easy-xml)[ RSS](/packages/mehr-it-easy-xml/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (2)Versions (27)Used By (0)

Easy-XML
========

[](#easy-xml)

Writing XML files
-----------------

[](#writing-xml-files)

The `XMLBuilder` class offers a similar API as the PHP's `XMLWriter`. In fact it utilizes it internally. But most of the time this way of generating XML is not very intuitive and your source code does not reveal the XML structure clearly.

Therefore the `XMLBuilder` offers a powerful array based interface which reveals the XML structure in your PHP code. It's always a good idea if your source code reveals it's purpose at first glance.

### Getting started

[](#getting-started)

The following example demonstrates how to create a basic XML with nested nodes:

```
$builder = new XMLBuilder();
$builder
	->beginDocument()
	->write([
		'root' => [
			'child'        => 'content',
			'anotherChild' => 15
	]);

```

The tag name is represented by the array key. The content is determined by the array value:

```

	content
	15

```

#### Adding attributes

[](#adding-attributes)

To add attributes to our XML nodes, we prefix the key with an open XML bracket ("&lt;") and pass an array with attribute names as keys prefixed with "@". The content is defined by the item simply named "@". Or you use an numeric array and specify the the tag name inside using the "&gt;" key:

```
$builder->write([
	''    => 'wife',
				'@age' => 36,
				'@'    => 'Lisa'
			]
		]
	]
]);

```

As you see, you even can mix the different methods of defining XML nodes. The resulting XML would look like this:

```

	content
	Lisa

```

#### Multiple nodes with same name

[](#multiple-nodes-with-same-name)

Sometimes you need to define multiple siblings with the same name. There are two ways to do so. Either you wrap each node in an array or you use the "&gt;" key to define the tag name:

```
$builder->write([
	'root' => [
		['child' => 'Lukas'],
		['child' => 'Sophie'],

		// alternative syntax:

		[
			'>' => 'child',
			'@' => 'Michael'
		],
		[
			'>' => 'child',
			'@' => 'Zoe'
		]
	]
]);

```

#### Passing closures

[](#passing-closures)

Often the XML structure depends on the data to write. To keep a fluent interface and a visual structure of the XML in your source, you may pass a Closure to generate dynamic parts of your XML:

```
$builder->write([
	'root' => function(XMLBuilder $bld) use ($person) {
		if ($person instanceof Child)
			$bld->write(['child' => $person->getName()];
		else
			$bld->write(['adult' => $person->getName()];
	});

```

Upgrade notes
-------------

[](#upgrade-notes)

### 2.x

[](#2x)

- Starting with version 2.x, all given paths and attribute name are expected to be UTF-8 encoded. Automatic encoding conversion was removed to increase performance.

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity65

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

Recently: every ~264 days

Total

26

Last Release

831d ago

Major Versions

1.16.1 → 2.0.02021-03-17

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/44973729?v=4)[mehr.IT GmbH](/maintainers/mehr-it)[@mehr-it](https://github.com/mehr-it)

---

Top Contributors

[![chmgr](https://avatars.githubusercontent.com/u/94837732?v=4)](https://github.com/chmgr "chmgr (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mehr-it-easy-xml/health.svg)

```
[![Health](https://phpackages.com/badges/mehr-it-easy-xml/health.svg)](https://phpackages.com/packages/mehr-it-easy-xml)
```

PHPackages © 2026

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