PHPackages                             8fold/php-xml-builder - 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. 8fold/php-xml-builder

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

8fold/php-xml-builder
=====================

A library for building XML document and element strings.

2.0.0(3y ago)113.0k↓18.4%[1 issues](https://github.com/8fold/php-xml-builder/issues)4MITPHPPHP ^8.0

Since Oct 7Pushed 2y ago1 watchersCompare

[ Source](https://github.com/8fold/php-xml-builder)[ Packagist](https://packagist.org/packages/8fold/php-xml-builder)[ GitHub Sponsors](https://github.com/8fold)[ GitHub Sponsors](https://github.com/joshbruce)[ RSS](/packages/8fold-php-xml-builder/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (3)Versions (19)Used By (4)

8fold XML Builder for PHP
=========================

[](#8fold-xml-builder-for-php)

XML Builder is designed to build a `string`, not a document object model (DOM) or abstract syntax tree (AST).

For DOM or AST, there are other libraries and native implementations (ex. [PHP:DOM](https://www.php.net/manual/en/book.dom.php) and [SimpleXML](https://www.php.net/manual/en/simplexml.examples-basic.php)).

You might use XML Builder to generate a string you feed into either PHP:DOM or Simple XML. Or, use the string as the body of an HTTP response.

Use the `Element` class to create individual nodes within the document.

Use the `Document` class to generate the doctype declaration and root level element.

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

[](#installation)

`composer require 8fold/php-xml-builder`

Usage
-----

[](#usage)

Warning: Users of this library are responsible for sanitizing content.

```
use Eightfold\XMLBuilder\Document;
use Eightfold\XMLBuilder\Element;
use Eightfold\XMLBuilder\Cdata;

echo Document::create('root',
  Element::create('child',
    Element::create('grandchild')->omitEndTag()->props('name Xavier'),
    Cdata::create('Hello, my name is Xavier!')
  )
);
```

Output:

```

Hello, my name is Xavier!]]>
```

Output (formatted):

```

    Hello, my name is Xavier!]]>

```

Alternatively, there is a shorthand variation.

The shorthand method uses the `__callStatic` PHP magic method.

```
use Eightfold\XMLBuilder\Document;
use Eightfold\XMLBuilder\Element;
use Eightfold\XMLBuilder\Cdata;

echo Document::root(
  Element::child(
    Element::grandchild()->omitEndTag()->props('name Xavier'),
    Cdata::create('Hello, my name is Xavier!')
  )
);

// output: Same as previous example.
```

Comments are available:

```
use Eightfold\XMLBuilder\Document;
use Eightfold\XMLBuilder\Element;
use Eightfold\XMLBuilder\Cdata;

echo Document::create(
  'root',
  Comment::create('comment'),
  Element::create('tag')->omitEndTag()
);
```

Output (unformatted):

```

```

### Compatibility

[](#compatibility)

XML Builder versionPHP version1+8.0+0+7.4+Details
-------

[](#details)

The origins of this library was an experiment where PHP was viewed as a "pure" programming language, not a template engine that grew into being a language.

The primary pain point was to maintain the feel of writing human-readable XML (tabs and spaces) while reducing the risk of human error; specifically, mismatched beginning and end tags.

The secondary pain point was that PHP:DOM and SimpleXML felt cumbersome when generating XML and HTML documents.

Other
-----

[](#other)

- [Code of Conduct](https://github.com/8fold/php-xml-builder/blob/master/.github/CODE_OF_CONDUCT.md)
- [Contributing](https://github.com/8fold/php-xml-builder/blob/master/.github/CONTRIBUTING.md)
- [Governance](https://github.com/8fold/php-xml-builder/blob/master/.github/GOVERNANCE.md)
- [Versioning](https://github.com/8fold/php-xml-builder/blob/master/.github/VERSIONING.md)
- [Security](https://github.com/8fold/php-xml-builder/blob/master/.github/SECURITY.md)

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity26

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity64

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

Recently: every ~5 days

Total

16

Last Release

1255d ago

Major Versions

0.6.3 → 1.0.02022-01-31

1.5.0 → 2.0.02022-12-11

PHP version history (2 changes)0.5PHP ^7.4||^8.0

1.0.0PHP ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/3ff7aa36dc04c5b535cd71eadbf66038401edde0c9dfaa688bec4fc16c6d7e8b?d=identicon)[eightfold](/maintainers/eightfold)

---

Top Contributors

[![joshbruce](https://avatars.githubusercontent.com/u/15252830?v=4)](https://github.com/joshbruce "joshbruce (108 commits)")

---

Tags

domhtmlphpxml

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/8fold-php-xml-builder/health.svg)

```
[![Health](https://phpackages.com/badges/8fold-php-xml-builder/health.svg)](https://phpackages.com/packages/8fold-php-xml-builder)
```

###  Alternatives

[mtdowling/jmespath.php

Declaratively specify how to extract elements from a JSON document

2.0k472.8M135](/packages/mtdowling-jmespathphp)[opis/closure

A library that can be used to serialize closures (anonymous functions) and arbitrary data.

2.6k230.0M284](/packages/opis-closure)[masterminds/html5

An HTML5 parser and serializer.

1.8k242.8M229](/packages/masterminds-html5)[sabberworm/php-css-parser

Parser for CSS Files written in PHP

1.8k191.2M65](/packages/sabberworm-php-css-parser)[michelf/php-markdown

PHP Markdown

3.5k52.4M345](/packages/michelf-php-markdown)[jms/metadata

Class/method/property metadata management in PHP

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

PHPackages © 2026

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