PHPackages                             verdant/xml2array - 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. verdant/xml2array

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

verdant/xml2array
=================

Convert from XML to array, array to XML, based on libs from lalit.org

10131.9k↓45.6%83PHP

Since Apr 23Pushed 4y ago1 watchersCompare

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

READMEChangelogDependenciesVersions (1)Used By (3)

Readme
======

[](#readme)

Convert XML to an array representation, and then convert back to XML again.

Drop-in replacement for Lalit.org's XML2Array and Array2XML classes, based on their work.

- Configurable to use different special array keys for attributes/cdata/value
- Configurable to preserve tag and attribute namespaces
- Array to XML conversion automatically uses the root array element as the root XML node, if only one element exists at the top-level in the array

Usage Examples
--------------

[](#usage-examples)

#### Basic usage

[](#basic-usage)

```
$array = XML2Array::createArray($xml);
$xml = Array2XML::createXML($array);

```

Note that there's no need to specify the 'rootNode' parameter from the previous implementation. If the array contains a single root item, that will automatically be used as the root node.

#### Drop-in replacement

[](#drop-in-replacement)

Of course, if you need a drop-in replacement, the old syntax works as before.

```
$array = XML2Array::createArray($xml);
$xml = Array2XML::createXML('rootNode', $array);

```

#### Preserve namespaces

[](#preserve-namespaces)

```
$config = array(
    'useNamespaces' => true,
);
$array = XML2Array::createArray($xml, $config);

```

#### Use JSON-friendly special keys

[](#use-json-friendly-special-keys)

```
$config = array(
    'attributesKey' => '$attributes',
    'cdataKey'      => '$cdata',
    'valueKey'      => '$value',
);
$array = XML2Array::createArray($xml, $config);
$xml = Array2XML::createXML($array, $config);

```

Further Reading
---------------

[](#further-reading)

Original [XML2Array](http://www.lalit.org/lab/convert-xml-to-array-in-php-xml2array/) and [Array2XML](http://www.lalit.org/lab/convert-php-array-to-xml-with-attributes/) libraries from Lalit.org

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity40

Moderate usage in the ecosystem

Community15

Small or concentrated contributor base

Maturity41

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/df254f8a9c525569a4c5e4d97463cab43d9a46e3a4b5c492df08fcb0401397b6?d=identicon)[oojacoboo](/maintainers/oojacoboo)

---

Top Contributors

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

### Embed Badge

![Health badge](/badges/verdant-xml2array/health.svg)

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

###  Alternatives

[masterminds/html5

An HTML5 parser and serializer.

1.8k242.8M229](/packages/masterminds-html5)[sabberworm/php-css-parser

Parser for CSS Files written in PHP

1.8k191.2M65](/packages/sabberworm-php-css-parser)[jms/metadata

Class/method/property metadata management in PHP

1.8k152.8M88](/packages/jms-metadata)[jms/serializer-bundle

Allows you to easily serialize, and deserialize data of any complexity

1.8k89.3M627](/packages/jms-serializer-bundle)[hassankhan/config

Lightweight configuration file loader that supports PHP, INI, XML, JSON, and YAML files

97513.5M170](/packages/hassankhan-config)[meyfa/php-svg

Read, edit, write, and render SVG files with PHP

54613.9M42](/packages/meyfa-php-svg)

PHPackages © 2026

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