mmusaib/xml-builder

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

Installs: 3

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/mmusaib/xml-builder

v1.0.1 2026-01-07 17:24 UTC

This package is auto-updated.

Last update: 2026-01-07 17:39:44 UTC


README

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

Installation

composer require mmusaib/xml-builder

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',
    '<strong>High quality content</strong>'
);

echo $xml->getXml();

Features

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

License

MIT