PHPackages                             drmad/semeele - 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. drmad/semeele

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

drmad/semeele
=============

Extremely simple and minimalistic XML generator for PHP. Really, very simple.

1.0.5(3y ago)11371GPL-3.0-or-laterPHPPHP &gt;=5.6

Since Jun 24Pushed 3y ago1 watchersCompare

[ Source](https://github.com/drmad/semeele)[ Packagist](https://packagist.org/packages/drmad/semeele)[ RSS](/packages/drmad-semeele/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (6)DependenciesVersions (7)Used By (0)

Semeele
=======

[](#semeele)

Extremely simple and minimalistic XML generator for PHP. Really, very simple.

I was using the [native XML libraries](http://php.net/manual/es/refs.xml.php) to create an... XML document. But they are *extremely verbose*. So I coded this initially in about four hours.

It works with PHP 5.6 and newer versions, with `mbstring` extension enabled.

Examples
--------

[](#examples)

```
$xml = new Drmad\Semeele\Document('html');
$xml->child('head')
    ->add('title', 'An XHTML')
    ->add('meta', ['charset' => 'utf-8'])
    ->parent()
->child('body')
    ->add('h1', 'An XHTML')
    ->add('p', 'This is a XML-valid HTML. Yay!')
;

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

And that's it. That prints:

```
An XHTMLAn XHTMLThis is a XML-valid HTML. Yay!
```

A more complex, real-life example, used in signed UBL documents:

```
$xml = new Drmad\Semeele\Node('ext:UBLExtension');
$xml->child('ext:ExtensionContent')
    ->child('ds:Signature', ['Id' => 'Signature'])->save($s) // Save this node for later
        ->child('ds:SignedInfo')
            ->add('ds:CanonicalizationMethod',
                ['Algorithm'=>'http://www.w3.org/TR/2001/REC-xml-c14n-20010315'])
            ->add('ds:SignatureMethod',
                ['Algorithm'=>'http://www.w3.org/2000/09/xmldsig#rsa-sha1'])
            ->child('ds:Reference', ['URI'=>''])
                ->child('ds:Transforms')
                    ->add('ds:Transform', ['Algorithm'=>'http://www.w3.org/2000/09/xmldsig#enveloped-signature'])
                    ->parent()
                ->add('ds:DigestMethod', ['Algorithm'=>'http://www.w3.org/2000/09/xmldsig#sha1'])
                ->add('ds:DigestValue')
;
        $s->add('ds:SignatureValue')    // Using the saved node
        ->child('ds:KeyInfo')
            ->child('ds:X509Data')
                ->add('ds:X509SubjectName')
                ->add('ds:X509Certificate')
;
echo $xml;
```

Outputs:

```

```

Installation and basic usage
----------------------------

[](#installation-and-basic-usage)

`Semeele` is available via [Composer](https://packagist.org/packages/drmad/semeele):

```
composer require drmad/semeele

```

Alternatively, you can `git clone` or download the ZIP from [GitHub](https://github.com/drmad/semeele), and use this simple autoloader function (update constant `SEMEELE_PATH` with the correct path as needed):

```
const SEMEELE_PATH = './semeele-master';

spl_autoload_register(function($class) {
    if (substr($class, 0, 13) == 'Drmad\\Semeele') {
        $base_name = substr($class, strrpos($class, '\\') + 1);
        $file_name = SEMEELE_PATH . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . $base_name . '.php';
        if (file_exists($file_name)) {
            require $file_name;
        }
    }
});
```

### `Drmad\Semeele\Node`

[](#drmadsemeelenode)

Base class for all nodes. Its constructor has these parameters:

- `$nodeName`: Required.
- `$content`: Optional. This is the node content. If an array is passed, it's used instead the `$attribute` parameter.
- `$attributes`: Optional. Array with `['attribute name' => 'attribute value']` structure.
- `$encoding`: Optional. Defaults to 'UTF-8'. Used to reencode `$content`, and it's passed to child nodes created with `child()` and `add()` methods.

This class has two main methods for adding new child nodes: `child()` and `add()`. Both returns a `Node` object, but `child()` returns the newly created node, and `add()` returns the current node, so you can keep adding new children to the same node.

All the arguments of both methods are passed to the `Node` constructor.

Other methods are (except otherwise noted, all methods returns the affected `Node` object):

- `parent()`: Returns the parent node. Used for 'going up the chain', perhaps after finished a run of `add()` methods (take a look at the examples above).
- `append(Node $node)`: Adds an already created node and its children to this node child tree.
- `save(&$node)`: Saves the node in `$node`. Useful for "returning" from a deep nested node.
- `attr($name, $value)`: Adds new properties to this node. You can specify both arguments, or pass an associative array with multiple properties and values as first argument.
- `comment($text)`: Adds a new `Drmad\Semeele\Comment` node.

The final XML is generated with the `getXML()` method, or just using the object in a `string` context.

### `Drmad\Semeele\Document`

[](#drmadsemeeledocument)

This class extends `Node`, and adds an [XML declaration](https://en.wikipedia.org/wiki/XHTML#XML_declaration) (using a `Drmad\Semeele\ProcessingInstruction` class) before the node content. Its constructor has these parameters:

- `$rootNodeName`: Required. It will be the name of the main `Node` in the XML document.
- `$version`: Optional. XML version, defaults to `1.0`.
- `$encoding`: Optional. XML encoding, defaults to `UTF-8`.

You can obtain the XML declaration node with `getDeclaration()`, perhaps to add new attributes, etc.

### `Drmad\Semeele\Cdata`

[](#drmadsemeelecdata)

Creates a CDATA value for escaping strings. Only useful if a human needs to read the XML, because all strings are always converted to XML entities when needed. E.g.:

```
$xml = new Drmad\Semeele\Node('test');
$xml->add('without_cdata', 'Love this song from KC & The Sunshine')
    ->add('with_cdata', new Drmad\Semeele\Cdata('Love that song from KC & The Sunshine'))
;
echo $xml;
```

Outputs:

```
Love this song from &lt;strong&gt;KC &amp; The Sunshine&lt;/strong&gt;Love that song from KC & The Sunshine]]>
```

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity62

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

Recently: every ~524 days

Total

6

Last Release

1145d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1307948?v=4)[Oliver Etchebarne](/maintainers/drmad)[@drmad](https://github.com/drmad)

---

Top Contributors

[![drmad](https://avatars.githubusercontent.com/u/1307948?v=4)](https://github.com/drmad "drmad (1 commits)")

---

Tags

phpxmlphpxml

### Embed Badge

![Health badge](/badges/drmad-semeele/health.svg)

```
[![Health](https://phpackages.com/badges/drmad-semeele/health.svg)](https://phpackages.com/packages/drmad-semeele)
```

###  Alternatives

[m1/vars

Vars is a simple to use and easily extendable configuration loader with in built loaders for ini, json, PHP, toml, XML and yaml/yml file types. It also comes with in built support for Silex and more frameworks to come soon.

69124.2k1](/packages/m1-vars)[goetas/xsd2php-runtime

Convert XSD (XML Schema) definitions into PHP classes

493.3k](/packages/goetas-xsd2php-runtime)[bupy7/xml-constructor

The array-like constructor of XML document structure.

1337.9k](/packages/bupy7-xml-constructor)

PHPackages © 2026

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