PHPackages                             decodelabs/exemplar - 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. decodelabs/exemplar

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

decodelabs/exemplar
===================

Powerful XML tools

v0.5.11(6mo ago)41.7kMITPHPPHP ^8.4CI passing

Since Mar 31Pushed 2w ago2 watchersCompare

[ Source](https://github.com/decodelabs/exemplar)[ Packagist](https://packagist.org/packages/decodelabs/exemplar)[ RSS](/packages/decodelabs-exemplar/feed)WikiDiscussions develop Synced 6d ago

READMEChangelog (10)Dependencies (7)Versions (29)Used By (0)

Exemplar
========

[](#exemplar)

[![PHP from Packagist](https://camo.githubusercontent.com/e8a2ebe31b13678a91bd3668474a0206ad5a4460bd98beef20dbf6a7e3d019d8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6465636f64656c6162732f6578656d706c61723f7374796c653d666c6174)](https://packagist.org/packages/decodelabs/exemplar)[![Latest Version](https://camo.githubusercontent.com/c67b23fffcd5507183b3a3c0ea60688c7f491228c30c67b0adef96fb06b89567/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6465636f64656c6162732f6578656d706c61722e7376673f7374796c653d666c6174)](https://packagist.org/packages/decodelabs/exemplar)[![Total Downloads](https://camo.githubusercontent.com/e3e5d90ae1b7cdda88332843cc5dacb958b2334103877f7b0c39448d69e994be/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6465636f64656c6162732f6578656d706c61722e7376673f7374796c653d666c6174)](https://packagist.org/packages/decodelabs/exemplar)[![GitHub Workflow Status](https://camo.githubusercontent.com/c091a2d3bc23b22cf0ff6ff939ed9ee4b21cc6ec165d3892140af4e3df37da82/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6465636f64656c6162732f6578656d706c61722f696e746567726174652e796d6c3f6272616e63683d646576656c6f70)](https://github.com/decodelabs/exemplar/actions/workflows/integrate.yml)[![PHPStan](https://camo.githubusercontent.com/e25c14ce011edabdd0fbd2e10415b41cc5d66ed11ef3e5b7edd074c5bdd35a2d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d656e61626c65642d3434434331312e7376673f6c6f6e6743616368653d74727565267374796c653d666c6174)](https://github.com/phpstan/phpstan)[![License](https://camo.githubusercontent.com/7305d2dff16785b6ad29516fde052ffc4109a1ec0de7ad67963f617f0eb3eea1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6465636f64656c6162732f6578656d706c61723f7374796c653d666c6174)](https://packagist.org/packages/decodelabs/exemplar)

### Powerful XML tools for PHP.

[](#powerful-xml-tools-for-php)

Exemplar provides a set of exhaustive and intuitive interfaces for reading, writing and manipulating XML documents and fragments.

---

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

[](#installation)

This package requires PHP 8.4 or higher.

Install via Composer:

```
composer require decodelabs/exemplar
```

Usage
-----

[](#usage)

### Reading &amp; manipulating

[](#reading--manipulating)

Access and manipulate XML files with a consolidated interface wrapping the DOM functionality available in PHP:

```
use DecodeLabs\Exemplar\Element as XmlElement;

$element = XmlElement::fromFile('/path/to/my/file.xml');

if($element->hasAttribute('old')) {
    $element->removeAttribute('old');
}

$element->setAttribute('new', 'value');

foreach($element->scanChildrenOfType('section') as $sectTag) {
    $inner = $sectTag->getFirstChildOfType('title');
    $sectTag->removeChild($inner);

    // Flatten to plain text
    echo $sectTag->getComposedTextContent();
}

file_put_contents('newfile.xml', (string)$element);
```

See [Element.php](./src/Element.php) for the full interface.

### Writing

[](#writing)

Programatically generate XML output with a full-featured wrapper around PHP's XML Writer:

```
use DecodeLabs\Exemplar\Writer as XmlWriter;

$writer = new XmlWriter();
$writer->writeHeader();

$writer->{'ns:section[ns:attr1=value].test'}(function ($writer) {
    $writer->{'title#main'}('This is a title');

    $writer->{'@body'}('This is an element with content wrapped in CDATA tags.');
    $writer->writeCData('This is plain CDATA');
});

echo $writer;
```

This creates:

```

    This is a title
    This is an element with content wrapped in CDATA tags.]]>
This is plain CDATA]]>
```

See [Writer.php](./src/Writer.php) for the full interface.

Licensing
---------

[](#licensing)

Exemplar is licensed under the MIT License. See [LICENSE](./LICENSE) for the full license text.

###  Health Score

50

—

FairBetter than 96% of packages

Maintenance84

Actively maintained with recent releases

Popularity23

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity70

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

Recently: every ~39 days

Total

27

Last Release

186d ago

PHP version history (4 changes)v0.1.0PHP ^7.2|^8.0

v0.3.0PHP ^8.0

v0.4.0PHP ^8.1

v0.5.0PHP ^8.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/8a241d64d12b3b5ee94197862ec1ec30b82ed2efa34a0cd7f4c3565a021daddd?d=identicon)[betterthanclay](/maintainers/betterthanclay)

---

Top Contributors

[![betterthanclay](https://avatars.githubusercontent.com/u/1273586?v=4)](https://github.com/betterthanclay "betterthanclay (146 commits)")

---

Tags

phpxmlxmlmarkup

### Embed Badge

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

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

###  Alternatives

[masterminds/html5

An HTML5 parser and serializer.

1.8k242.8M229](/packages/masterminds-html5)[jms/serializer

Library for (de-)serializing data of any complexity; supports XML, and JSON.

2.3k135.8M851](/packages/jms-serializer)[jms/metadata

Class/method/property metadata management in PHP

1.8k152.8M88](/packages/jms-metadata)[jms/serializer-bundle

Allows you to easily serialize, and deserialize data of any complexity

1.8k89.3M627](/packages/jms-serializer-bundle)[sabre/xml

sabre/xml is an XML library that you may not hate.

52832.2M131](/packages/sabre-xml)[goetas-webservices/xsd2php-runtime

Convert XSD (XML Schema) definitions into PHP classes

4910.9M36](/packages/goetas-webservices-xsd2php-runtime)

PHPackages © 2026

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