PHPackages                             xttribute/xttribute - 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. xttribute/xttribute

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

xttribute/xttribute
===================

XML to DTO, nicely!

1.1.1(2y ago)6329.1k↓34.6%2[3 issues](https://github.com/BennyC/xttribute/issues)MITPHPPHP &gt;=8.1

Since Jul 30Pushed 2y ago2 watchersCompare

[ Source](https://github.com/BennyC/xttribute)[ Packagist](https://packagist.org/packages/xttribute/xttribute)[ RSS](/packages/xttribute-xttribute/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (4)Versions (7)Used By (0)

xttribute
=========

[](#xttribute)

[![Tests & PHP CodeSniffer](https://github.com/BennyC/xttribute/actions/workflows/php.yml/badge.svg)](https://github.com/BennyC/xttribute/actions/workflows/php.yml/badge.svg)[![GitHub tag](https://camo.githubusercontent.com/be0a3c96dcfbfc07fde01e5e33ff3c5571c90060dbec9e9ba8bdf29113cb8860/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f7461672f42656e6e79432f7874747269627574652e737667)](https://GitHub.com/BennyC/xttribute/tags/)

xttribute will make dealing with XML a breeze! DOMDocuments can now be cast to classes with PHP 8.1 attributes!

Getting started
---------------

[](#getting-started)

### Requirements

[](#requirements)

- PHP 8.1

### Installation

[](#installation)

Use [composer](https://getcomposer.org/) to install

```
composer require xttribute/xttribute
```

### Usage

[](#usage)

Given the following XML

```

  Tove
  Jani
  Reminder
  Don't forget me this weekend!

```

We can translate this easily to the following class with some attributes!

```
use Xttribute\Xttribute\Castables\Str;

class Note
{
    public function __construct(
        #[Str('/note/to')]
        public readonly string $to,
        #[Str('/note/from')]
        public readonly string $from,
        #[Str('/note/heading')]
        public readonly string $heading,
        #[Str('/note/body')]
        public readonly string $body,
    ) {
    }
}
```

Then we can run it through our `DomDocumentCaster` and get our hydrated object!

```
use Xttribute\Xttribute\DOMDocumentCaster;

// populate $source here with however you're receiving your XML

$doc = new DOMDocument();
$doc->loadXML($source);

$caster = new DOMDocumentCaster();
$note = $caster->cast($doc, Note::class);

// Work with $note hydrated DTO...
```

Other ways of using this package can be found in our [examples](https://github.com/BennyC/xttribute/tree/main/examples).

---

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

[](#contributing)

Pull requests are welcome! For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

### Testing

[](#testing)

```
composer test
```

---

### License

[](#license)

[MIT](https://choosealicense.com/licenses/mit/)

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity39

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 90.9% 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 ~112 days

Total

5

Last Release

939d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/849051?v=4)[Ben Colegate](/maintainers/BennyC)[@BennyC](https://github.com/BennyC)

---

Top Contributors

[![BennyC](https://avatars.githubusercontent.com/u/849051?v=4)](https://github.com/BennyC "BennyC (40 commits)")[![devfrey](https://avatars.githubusercontent.com/u/1571879?v=4)](https://github.com/devfrey "devfrey (2 commits)")[![eliashaeussler](https://avatars.githubusercontent.com/u/16313625?v=4)](https://github.com/eliashaeussler "eliashaeussler (1 commits)")[![jacyimp](https://avatars.githubusercontent.com/u/85919441?v=4)](https://github.com/jacyimp "jacyimp (1 commits)")

###  Code Quality

TestsPest

Code StylePHP\_CodeSniffer

### Embed Badge

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

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

PHPackages © 2026

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