PHPackages                             krosscode/xml-to-object - 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. krosscode/xml-to-object

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

krosscode/xml-to-object
=======================

Converts XML into an object

1.0.0(6y ago)24GPL-3.0-or-laterPHPPHP ^7.0

Since Nov 15Pushed 6y ago1 watchersCompare

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

READMEChangelogDependenciesVersions (2)Used By (0)

XML to object
=============

[](#xml-to-object)

This library simply converts XML into an object.

Getting started
---------------

[](#getting-started)

XML to object is very easy to use. **Example:**

```
// Using composer here, but you can also directly include XmlToObject.php
require_once __DIR__ . '/vendor/autoload.php';

// Import the function
use function KrossCode\XmlToObject\xmlToObject;

// First we need to get the contents of our XML file
$xmlContents = file_get_contents('path/to/xml/file.xml');
if (!$xmlContents) return false; // File couldn't be read

// Now we try to convert the XML to an object
$xmlObject = xmlToObject($xmlContents);
if (!$xmlObject) return false; // XML couldn't be converted to an object

print_r($xmlObject); // Success!
```

Example
-------

[](#example)

What does the object look like, compared to the XML?

### XML

[](#xml)

```

	Johnny's Green Goods

			Cucumber
			63
			1.99

			Carrot
			24
			1.79

```

### Object (represented in JSON)

[](#object-represented-in-json)

```
{
    "Name": "Johnny's Green Goods",
    "GroceryCollection": {
        "Grocery": [
            {
                "@attributes": {
                    "id": "13"
                },
                "Name": "Cucumber",
                "Amount": "63",
                "Price": "1.99"
            },
            {
                "@attributes": {
                    "id": "17"
                },
                "Name": "Carrot",
                "Amount": "24",
                "Price": "1.79"
            }
        ]
    }
}
```

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity52

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

2376d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/22466906?v=4)[Sean Krossing](/maintainers/krosscode)[@krosscode](https://github.com/krosscode)

---

Top Contributors

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

---

Tags

composer-packageconverterobjectphpphp-libraryphp7xml

### Embed Badge

![Health badge](/badges/krosscode-xml-to-object/health.svg)

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

###  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)
