PHPackages                             sausin/xml-construct - 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. sausin/xml-construct

Abandoned → [spatie/array-to-xml](/?search=spatie%2Farray-to-xml)Library[Utility &amp; Helpers](/categories/utility)

sausin/xml-construct
====================

XML constructor class for PHP

v0.2.0(8y ago)022MITPHPPHP &gt;=7.0.0

Since Sep 9Pushed 8y ago1 watchersCompare

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

READMEChangelog (3)Dependencies (1)Versions (4)Used By (0)

Xml generator
=============

[](#xml-generator)

[![Latest Version on Packagist](https://camo.githubusercontent.com/ffd010c4242db94fffefffcfd02d461609560a517679c1c19ccfd3311c4092ee/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f73617573696e2f786d6c2d636f6e7374727563742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/sausin/xml-construct)[![Build Status](https://camo.githubusercontent.com/48c177d449b9d0ccb99c447e16e2eccf8e78be29f6b5cba3aa7ec72ca0192671/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f73617573696e2f786d6c2d636f6e7374727563742f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/sausin/xml-construct)[![Quality Score](https://camo.githubusercontent.com/0f1b16400512068e3950ec5d33b9dccdde2f273543a9e099b80491dce3818f04/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f73617573696e2f786d6c2d636f6e7374727563742e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/sausin/xml-construct)[![Scrutinizer Coverage](https://camo.githubusercontent.com/6d97252aa0bc9182da4c06abb843b94c8c217d8474e69cda8de7cb5bfb2fd450/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f73617573696e2f786d6c2d636f6e7374727563742e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/sausin/xml-construct)[![StyleCI](https://camo.githubusercontent.com/08dacff27535588ef29ddcde87b76d7ab2f102f8e457b4729ac0926ba95d7f17/68747470733a2f2f7374796c6563692e696f2f7265706f732f3130323934393334392f736869656c643f6272616e63683d6d6173746572)](https://styleci.io/repos/102949349)[![Total Downloads](https://camo.githubusercontent.com/16153652b18b73ac2208c36415a63ada779b850261c392db74de6eef7abb3833/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f73617573696e2f786d6c2d636f6e7374727563742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/sausin/xml-construct)[![License: MIT](https://camo.githubusercontent.com/1b01ef0024ba0866c115986b895301f657c1b21fc29f05c4844b7f2e8d89204d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e7376673f7374796c653d666c61742d737175617265)](https://opensource.org/licenses/MIT)

A useful class to generate valid XML from a PHP array.

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

[](#installation)

Run the following command in your project to get the class:

```
composer require sausin/xml-construct

```

Usage with normal arrays
------------------------

[](#usage-with-normal-arrays)

Usage is simple

### Verbose way:

[](#verbose-way)

```
$xmlGen = new XmlConstruct('ROOT')

$string = $xmlGen->fromArray($array)->getDocument();
```

where `$array` is the PHP array from which you need the XML to be generated.

### Quick:

[](#quick)

```
(new XmlConstruct('ROOT'))->fromArray($f)->getDocument();
```

returns the XML string.

In both the above examples, `ROOT` is the root of the XML (i.e. the first element).

Usage with arrays when attributes are needed in XML
---------------------------------------------------

[](#usage-with-arrays-when-attributes-are-needed-in-xml)

If used like this:

```
$array = ['KEY|ATTR|VAL' => 'VALUE'];

return (new XmlConstruct('ROOT'))->fromArray($f)->getDocument();

```

It will result in the following XML

```

  VALUE

```

You can add as many attributes as you like and they will all be added to the element. Neat!

Credits
-------

[](#credits)

Initial inputs to the class were taken from [php user contributed notes](http://php.net/manual/en/ref.xmlwriter.php)

###  Health Score

23

—

LowBetter than 26% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

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

Total

3

Last Release

3217d ago

PHP version history (2 changes)v0.1.0PHP &gt;=5.6.0

v0.1.1PHP &gt;=7.0.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/1efa495645876ee7b1157fb11de36597784034a721f787738b655ac574bf88ef?d=identicon)[sausin](/maintainers/sausin)

---

Top Contributors

[![sausin](https://avatars.githubusercontent.com/u/11542923?v=4)](https://github.com/sausin "sausin (14 commits)")

---

Tags

phpxmlarraywriterXMLWriterattributes

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[openlss/lib-array2xml

Array2XML conversion library credit to lalit.org

31053.8M53](/packages/openlss-lib-array2xml)

PHPackages © 2026

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