PHPackages                             damijanc/simple-xml - 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. damijanc/simple-xml

ActiveLibrary

damijanc/simple-xml
===================

DomDocument wrapper for XML generation

1.0.0(2y ago)22[1 issues](https://github.com/damijanc/simple-xml/issues)MITPHPPHP &gt;=8.2

Since Apr 10Pushed 1y ago1 watchersCompare

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

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

simple-xml
==========

[](#simple-xml)

Simple wrapper for PHP () DOMDocument

After roughly 11 years this lib is finally getting and update. It uses a nice PHP feature - properties :D

Something about XML itself
==========================

[](#something-about-xml-itself)

Valid XML needs to start with xml version and encoding declaration like ``. XML without it is invalid.

Library by default uses UTF-8 encoding. So please make sure that all your strings are properly encoded.

XML supports multiple type of text: text, CDATA and an element.

Everything in [CDATA](https://en.wikipedia.org/wiki/CDATA) section will be interpreted as a literal string. For example `John Smith]]>`will be interpreted as `&lt;sender&gt;John Smith&lt;/sender&gt;`, as literal string. To be compatible with [XML Specs](https://www.w3.org/TR/xml/#syntax) you can use CDATA if your sting contains chars like &lt;, &gt;, &amp; etc.

Text attribute will make sure that same characters will be escaped. `&` will be `&amp;`, `>` will be `&gt;` and `

        George Orwell
        1984

        Lojze Slak
        S harmoniko po svetu

        Isaac Asimov
        Foundation
        $15.61

        Robert A Heinlein
        Stranger in a Strange Land
        $43.29

```

Note on comments: As comments can appear anywhere in the XML it is hard to predict the user's intention. I decided to add comment support on the node attribute level

for example:

```
    #[Node('title')]
    #[Comment('This is a comment')]
    public string $title;
```

will result in:

```
1984
```

I might change this implementation later. For now, I do not have any real use case.

Supported attributes
====================

[](#supported-attributes)

```
#[Node('book')]
class Book
{
    #[Property('name', null)]
    #[Property('data-link', 'some-dummy-link')]
    public string $author;
}
```

Propery attribute will add a propery to a node. It accepts two values name and value. If value is null it will be read from class property. We also have a support for multiple properties attributes that can added to mutiple class properties. Example above will attach properties to parent node as Node attribute is not defined. In the case in the example we would get

```

```

Another example with Node attribute

```
#[Node('book')]
class Book
{
    #[Node('author')]
    #[Property('data-link', 'some-dummy-link')]
    public string $author;
}
```

will result in:

```

    George Orwell

```

Property
--------

[](#property)

A word about performance
========================

[](#a-word-about-performance)

I did manage to generate XML from 50k classes in 300ms, therefor I believe it is fast enough. Would be nice if someone can confirm it.

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity53

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

Unknown

Total

1

Last Release

768d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6cdbc0c6ed1511bddf2d7528b8884b3ec05c2b017531e70471337a58c4646b30?d=identicon)[damijanc](/maintainers/damijanc)

---

Top Contributors

[![damijanc](https://avatars.githubusercontent.com/u/1586796?v=4)](https://github.com/damijanc "damijanc (7 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/damijanc-simple-xml/health.svg)

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

PHPackages © 2026

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