PHPackages                             bupy7/xml-constructor - 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. bupy7/xml-constructor

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

bupy7/xml-constructor
=====================

The array-like constructor of XML document structure.

v2.0.5(4mo ago)1337.9k↓36.5%3BSD-3-ClausePHPPHP &gt;=5.6CI passing

Since Jul 23Pushed 4mo ago1 watchersCompare

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

READMEChangelog (10)Dependencies (1)Versions (20)Used By (0)

xml-constructor
===============

[](#xml-constructor)

[![Stable Version](https://camo.githubusercontent.com/8e21c8731341f6701cb2e4bca56a04248a45c94045050c5f91de237a82179fa7/68747470733a2f2f706f7365722e707567782e6f72672f62757079372f786d6c2d636f6e7374727563746f722f762f737461626c65)](https://packagist.org/packages/bupy7/xml-constructor)[![Build status](https://github.com/bupy7/xml-constructor/actions/workflows/build.yml/badge.svg)](https://github.com/bupy7/xml-constructor/actions/workflows/build.yml)[![Coverage Status](https://camo.githubusercontent.com/a2ab3ca80666395428b0a476572f57c8bbf7eb0e4701770c515bee6b63c494c6/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f62757079372f786d6c2d636f6e7374727563746f722f62616467652e7376673f6272616e63683d6d617374657226736572766963653d676974687562)](https://coveralls.io/github/bupy7/xml-constructor?branch=master)[![Total Downloads](https://camo.githubusercontent.com/1cfe45e5e3f4221bee3805c68fd37957c680d3e14e6174b79670fdc8ae351032/68747470733a2f2f706f7365722e707567782e6f72672f62757079372f786d6c2d636f6e7374727563746f722f646f776e6c6f616473)](https://packagist.org/packages/bupy7/xml-constructor)[![License](https://camo.githubusercontent.com/99b6c8e94f1b1aaf69ccbf5d9b9e40c8815234307f1bc9abe81372aec12d20c5/68747470733a2f2f706f7365722e707567782e6f72672f62757079372f786d6c2d636f6e7374727563746f722f6c6963656e7365)](https://packagist.org/packages/bupy7/xml-constructor)

The array-like constructor of XML document structure.

Supporting PHP from 5.6 up to newest.

Install
-------

[](#install)

Add the following to `require` section of your `composer.json`:

```
"bupy7/xml-constructor": "*"

```

Then do `composer install`;

or execute the command:

```
$ composer require bupy7/xml-constructor

```

Usage
-----

[](#usage)

**Input:**

```
$xml = new XmlConstructor();
$in = [
    [
        'tag' => 'root',
        'elements' => [
            [
                'tag' => 'tag1',
                'attributes' => [
                    'attr1' => 'val1',
                    'attr2' => 'val2',
                ],
            ],
            [
                'tag' => 'tag2',
                'content' => 'content2',
            ],
            [
                'tag' => 'tag3',
                'elements' => [
                    [
                        'tag' => 'tag4',
                        'content' => 'content4',
                    ],
                ],
            ],
            [
                'tag' => 'tag4',
                'content' => 'content4',
                'cdata' => true, // by default - false, see https://en.wikipedia.org/wiki/CDATA
            ],
        ],
    ],
];
echo $xml->fromArray($in)->toOutput();
```

**Output:**

```

    content2

        content4

    content4]]>

```

**Configuration:**

```
$xml = new XmlConstructor([
    // Indent each line in the XML document. 4 space by default.
    'indentString' => '    ',
    /* Header document tag. "" by default. */
    'startDocument' => [
        // version
        '1.0',
        // encoding
        'UTF-8',
    ],
]);
```

You can set up `indentString` and/or `startDocument` as `null` to disable them.

Testing
-------

[](#testing)

Run tests:

```
$ ./vendor/bin/phpunit --no-coverage

```

Run tests with coverage:

```
$ XDEBUG_MODE=coverage ./vendor/bin/phpunit

```

HTML coverage path: `build/coverage/index.html`

Code style
----------

[](#code-style)

To fix code style, run:

```
~/.composer/vendor/bin/php-cs-fixer fix --verbose

```

You have to install [PHP CS Fixer](https://github.com/PHP-CS-Fixer/PHP-CS-Fixer) at first, if you don't use build-in Docker image:

```
composer global require friendsofphp/php-cs-fixer

```

License
-------

[](#license)

**xml-constructor** is released under the BSD-3-Clause License. See the bundled `LICENSE.md` for details.

###  Health Score

51

—

FairBetter than 96% of packages

Maintenance74

Regular maintenance activity

Popularity36

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 99.1% 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 ~211 days

Recently: every ~271 days

Total

19

Last Release

142d ago

Major Versions

v1.3.5 → v2.0.02023-01-06

PHP version history (2 changes)1.0.0PHP &gt;=5.4

1.3.0PHP &gt;=5.6

### Community

Maintainers

![](https://www.gravatar.com/avatar/f2f9ee20b742a44db8870955cd27b91bb82c14e08dd61a4e096692c9d9d83302?d=identicon)[bupy7](/maintainers/bupy7)

---

Top Contributors

[![bupy7](https://avatars.githubusercontent.com/u/5145037?v=4)](https://github.com/bupy7 "bupy7 (108 commits)")[![pandalowry](https://avatars.githubusercontent.com/u/9015140?v=4)](https://github.com/pandalowry "pandalowry (1 commits)")

---

Tags

libraryphpxmlphpxmllibraryxml constructorxml writterxml maker

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[goetas/xsd2php-runtime

Convert XSD (XML Schema) definitions into PHP classes

493.3k](/packages/goetas-xsd2php-runtime)[leonelquinteros/php-toml

PHP parser for TOML language ( https://github.com/toml-lang/toml )

266.7k](/packages/leonelquinteros-php-toml)

PHPackages © 2026

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