PHPackages                             mmusaib/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. mmusaib/xml-builder

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

mmusaib/xml-builder
===================

A lightweight, fluent XML builder utility for PHP using native DOMDocument

v1.0.1(4mo ago)115↓50%MITPHPPHP &gt;=7.4

Since Jan 7Pushed 4mo agoCompare

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

READMEChangelogDependencies (1)Versions (3)Used By (0)

XML Builder for PHP
===================

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

A lightweight, fluent XML builder built on top of PHP's DOMDocument.

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

[](#installation)

```
composer require mmusaib/xml-builder
```

Usage
-----

[](#usage)

```
use mmusaib\XmlBuilder\XmlBuilder;

$xml = new XmlBuilder('products');

$product = $xml->addElementToRoot('product');
$xml->addAttributes($product, [
    'id' => 101,
    'type' => 'digital'
]);

$xml->addElement($product, 'name', 'Premium Course');
$xml->addCDATAElement(
    $product,
    'description',
    'High quality content'
);

echo $xml->getXml();
```

🚀 Streaming Large XML Files (Chunk-Safe Mode)
---------------------------------------------

[](#-streaming-large-xml-files-chunk-safe-mode)

When generating very large XML files (hundreds of thousands or millions of nodes), keeping everything in memory using DOMDocument can cause memory exhaustion. XmlBuilder supports streaming mode, allowing you to:

- Keep the root element constant
- Append children chunk by chunk
- Write directly to a file
- Keep memory usage extremely low

### Start Streaming

[](#start-streaming)

```
$xml = new XmlBuilder('products');
$xml->startStream('products.xml');
```

This writes:

```

```

### Append Nodes Per Chunk

[](#append-nodes-per-chunk)

```
foreach ($chunks as $chunk) {
    foreach ($chunk as $item) {
        $product = $xml->addElementToRoot('product');

        $xml->addElement($product, 'name', $item['name']);
        $xml->addElement($product, 'price', $item['price']);

        $xml->appendToStream($product);   // Writes & frees memory
    }
}
```

Each call:

- Writes ... to file
- Removes it from memory immediately

### Finish Streaming

[](#finish-streaming)

```
$xml->endStream();
```

This closes the root element:

```

```

✅ Why Use Streaming Mode?
-------------------------

[](#-why-use-streaming-mode)

ProblemStreaming SolvesMillions of records✔Memory exhaustion✔Chunked DB processing✔Long-running jobs✔Features
--------

[](#features)

- Fluent XML creation
- CDATA support
- Attribute helpers
- Encoding-safe
- Pretty or compact output
- PSR-4 autoloading

License
-------

[](#license)

MIT

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance77

Regular maintenance activity

Popularity9

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity36

Early-stage or recently created project

 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

2

Last Release

131d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/020dd3a4c07ff693c9b75b4380a895714877203f3b322b2f70319f9c6ce91254?d=identicon)[mmusaib](/maintainers/mmusaib)

---

Top Contributors

[![mmusaib](https://avatars.githubusercontent.com/u/33693861?v=4)](https://github.com/mmusaib "mmusaib (6 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mmusaib-xml-builder/health.svg)

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

###  Alternatives

[phpflo/phpflo

Flow-based programming for PHP

2173.3k4](/packages/phpflo-phpflo)[jaspaul/laravel-rollout

A package to integrate rollout into your Laravel project.

2493.8k](/packages/jaspaul-laravel-rollout)

PHPackages © 2026

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