PHPackages                             ronappleton/php-to-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. ronappleton/php-to-xml

ActiveProject

ronappleton/php-to-xml
======================

Convert Json String, Object or Array to Simple XML

03PHP

Since Aug 19Pushed 5y ago1 watchersCompare

[ Source](https://github.com/ronappleton/php-to-xml)[ Packagist](https://packagist.org/packages/ronappleton/php-to-xml)[ RSS](/packages/ronappleton-php-to-xml/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependenciesVersions (1)Used By (0)

What is it?
===========

[](#what-is-it)

Php to xml is a simple package to allow the conversion of Json strings, Json objects and Php Arrays into valid XML.

The idea for this package is to reduce the building of XML within views. The package should allow for much cleaner code when producing XML to send, it also bridges a gap in respect to those that like to build in json or by using arrays.

Attributes are supported by adding an array called `attributes` to as a node, populated with the attribute names and values.

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

[](#installation)

`composer require ronappleton/php-to-xml`

Usage
-----

[](#usage)

The converter can be configured by using `RonAppleton\PhpToXml\Config` although a default configuration will be used if one is not passed.

To use the converter add a use statement for `RonAppleton\PhpToXml\PhpToXml` and use statically `PhpToXml::convert($array, $config)` where $config is optional.

```
$array = [
    'RootNode' => [
        'SecondaryNode' => [
            'attributes' => [
                'firstAttribute' => 'firstAttributeValue',
                'secondAttribute' => 'secondAttributeValue',
            ],
            'SecondaryChildValueKey' => 'SecondaryChildValue',
            'SecondaryChildValueKey2' => 'SecondaryChildValue2',
        ]
    ]
];

```

```
{
    "RootNode": {
        "SecondaryNode": {
            "attributes": {
                "firstAttribute": "firstAttributeValue",
                "secondAttribute": "secondAttributeValue"
            },
            "SecondaryChildValueKey": "SecondaryChildValue",
            "SecondaryChildValueKey2": "SecondaryChildValue2"
        }
    }
}

```

By default numeric keys are not allowed and will throw an exception, this can be configured using `$config->setPrependNumericKeys(true)`, this will prepend by default the word `item` to any numeric keys, so 0 becomes item0, 1 becomes item1 and so on. The numerical digits are then removed during conversion thereby adding multiple same named nodes. The prefix can be changed using `$config->setNumericKeyIndex('name');` where name is the node name you wish to use.

The following methods also exist for configuration.

`setBoolAsString()` to produce true instead of 1 in the xml for eaxmple.

`setNumbersToStrings()` to convert digits to strings.

`setHtmlSpecialCharacters()` to encode strings.

`setStringsAsCdata()` to wrap all strings in CDATA tags.

###  Health Score

17

—

LowBetter than 6% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity32

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/6e2afdd94a6f21a4ec2c5df569b80c1d47d6f5d0428f866f55c4bc117856b58b?d=identicon)[Ron Appleton](/maintainers/Ron%20Appleton)

---

Top Contributors

[![ronappleton](https://avatars.githubusercontent.com/u/3792420?v=4)](https://github.com/ronappleton "ronappleton (3 commits)")

### Embed Badge

![Health badge](/badges/ronappleton-php-to-xml/health.svg)

```
[![Health](https://phpackages.com/badges/ronappleton-php-to-xml/health.svg)](https://phpackages.com/packages/ronappleton-php-to-xml)
```

PHPackages © 2026

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