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

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

aircury/xml
===========

XML manipulation with PHP made easy

0571PHPCI failing

Since Jul 17Pushed 5y ago1 watchersCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

[![Build status](https://camo.githubusercontent.com/a7b5bc2e341befdcd8a31254b5ae3fa0782cfe5785fd34f55f8f75bb5e80465d/68747470733a2f2f636972636c6563692e636f6d2f67682f616972637572792f786d6c2e7376673f7374796c653d736869656c6426636972636c652d746f6b656e3d3a636972636c652d746f6b656e)](https://circleci.com/gh/aircury/xml)

XML
===

[](#xml)

XML manipulation with PHP made easy

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

[](#installation)

### Download the library

[](#download-the-library)

This library makes use of Composer. You need to have it on your machine. See [Composer](https://getcomposer.org/download/) for instructions. Here we are assuming that you have Composer installed globally.

```
$ composer require aircury/xml
```

Documentation
-------------

[](#documentation)

### Class documentation

[](#class-documentation)

#### Xml

[](#xml-1)

- `parseString(string $xmlString): Node` Given an xml string, parses that string into a Node object.
- `parseFile(string $path): Node` Given a path, parses that file into a Node object.
- `dump(Node $node): string` Giving any Node, will dump it into an xml string.

#### Node

[](#node)

Node is the base class.

If you want to set some attributes, there are three options:

1. You can pass them to the constructor. E.g. `new Node('pizza', ['crust' => 'classic'])`
2. Node implements \\ArrayAccess, so you can use `$pizza['crust']` for setting or reading the attributes.
3. Node has a public attribute called `attributes`, so you can access them directly. `$pizza->attributes['crust'] = 'classic';`

#### NodeCollection

[](#nodecollection)

It is a collection of nodes.

##### Methods

[](#methods)

- `indexByAttribute(string $attribute): NodeCollection` Given an attribute it will index the collection by it
- `getNamedChildren(string $childName, array $attributes = [], bool $createIfMissing = false): NodeCollection` Get a subset of the child nodes, filtered by `$attributes`. If `$createIfMissing` is passed, it will ensure it is created if there are no matches.
- `getNamedChild(string $childName, array $attributes = [], bool $createIfMissing = true): Node` Same as `getNamedChildren` but expecting only one match.

### Example

[](#example)

```
$pizza = new Node('pizza'); // Create a new 'pizza' node.

$peperoni = new Node('ingredient', ['name' => 'peperoni', 'spicy' => 'true']);
$slice = new Node('slice');

$pizza->addChild($peperoni);
$pizza->addChild(new Node('ingredient', ['name' => 'cheese', 'type' => 'cheddar']));
$pizza->addChild(new Node('ingredient', ['name' => 'cheese', 'type' => 'camembert']));
$pizza->addChild($slice);

$pizza['crust'] = 'classic'; // Set the crust attribute of the pizza node

unset($peperoni['spicy']); // Remove an attirbute from the peperoni ingredient node

if (isset($peperoni['spicy'])) {
    // ...
}

// Get all the 'ingredient' nodes of the 'pizza'
$ingredients = $pizza->namedChildren['ingredient'];

// Access the peperoni ingredient
$pizza->namedChildren['ingredient'][0];

// If you want to access them by any of the attributes, you can index them by that attribute
$pizza->indexByAttribute('ingredient', 'name');
$pizza->namedChildren['ingredient']['peperoni'];

// If you want to filter the child nodes by an attribute, you can use `getNamedChildren`
$cheeses = $pizza->getNamedChildren('ingredient', ['name' => 'cheese']); // Will return a NodeCollection with two elements

// By default, if the children that you are after don't exist, it will create them. if you don't want them to be created
// pass the third argument as false
$emptyCollection = $pizza->getNamedChildren('ingredient', ['name' => 'mushroom'], false);

// If there is only one child, you can also use `getNamedChild`
$slice = $pizza->getNamedChild('slice');
```

License
-------

[](#license)

This software is published under the [MIT license](LICENSE).

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity33

Early-stage or recently created project

 Bus Factor1

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

### Community

Maintainers

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

---

Top Contributors

[![j-d](https://avatars.githubusercontent.com/u/1140726?v=4)](https://github.com/j-d "j-d (26 commits)")[![PaJuarez](https://avatars.githubusercontent.com/u/15326163?v=4)](https://github.com/PaJuarez "PaJuarez (2 commits)")[![aircury-bot](https://avatars.githubusercontent.com/u/32492530?v=4)](https://github.com/aircury-bot "aircury-bot (1 commits)")

### Embed Badge

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

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

PHPackages © 2026

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