PHPackages                             jitesoft/xml2struct - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. jitesoft/xml2struct

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

jitesoft/xml2struct
===================

Simple lib to convert a xml file into a tree structure of nodes, an array structure or a json string.

2.0.0(8y ago)3104MITPHPPHP &gt;=7.1

Since Mar 3Pushed 8y ago2 watchersCompare

[ Source](https://github.com/jitesoft/php-xml2array)[ Packagist](https://packagist.org/packages/jitesoft/xml2struct)[ Docs](https://github.com/jitesoft/php-xml2array)[ RSS](/packages/jitesoft-xml2struct/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (3)Dependencies (2)Versions (6)Used By (0)

[![Build Status](https://camo.githubusercontent.com/b7b243c8167faf7b720559d03c583a240b9ad6c18462bd36bb6e3efb4e784686/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6a697465736f66742f7068702d786d6c3261727261792f6d61737465722e7376673f6c6162656c3d6d6173746572)](https://travis-ci.org/jitesoft/php-xml2array)

[![Build Status](https://camo.githubusercontent.com/d8cb588a835e0f7e5d68f188177bc0544cc697eb68bd922db01df9e101a87450/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6a697465736f66742f7068702d786d6c3261727261792f646576656c6f702e7376673f6c6162656c3d646576656c6f70)](https://travis-ci.org/jitesoft/php-xml2array)

[![Dependency Status](https://camo.githubusercontent.com/72a9f7b9b214ed5ebb9d2f633313a74b6d346627930ece68748606c5de8dfaa9/68747470733a2f2f67656d6e617369756d2e636f6d2f6261646765732f6769746875622e636f6d2f6a697465736f66742f7068702d786d6c3261727261792e737667)](https://gemnasium.com/github.com/jitesoft/php-xml2array)

XML2Struct
==========

[](#xml2struct)

XML can be a pain... Sometimes its a lot more handy to work with a tree structure or even json or an array!
This package was created to ease testing with xml files, so that, instead of going through a lengthy `DOMElement` test case or even just string-matching the xml right away, one could convert the xml into a more easily handled structure.
Thus XML2Struct was born.

Usage:
------

[](#usage)

Install package through composer:

```
composer require jitesoft/xml2struct

```

The parser is quite simple to use, all that is needed is to create a new parser object and call its parse method supplying the xml you want parsed as a string:

```
$parser = new Jitesoft\XML\Parser();
// Node tree!
$out    = $parser->parse(file_get_contents('myxmlfile.xml'));
// Json string!
$json   = json_encode($out);
// Array!
$array  = $out->toArray();
```

*For more in-depth examples, check the `examples` folder.*

The object returned is a `Jitesoft\XML\Node` structure.
The structure have the following fields defined:

```
name:       string                  default: ""
content:    string                  default: ""
attributes: array ([key => value])  default: []
children:   array ([Node])          default: []

```

When converting a node to an array or a json string, the properties or keys will be named the same as the Nodes fields. The keys will always be there, even if there is no value from the xml, if no parsed value, it will be the default value stated above..

Changes
-------

[](#changes)

### 2.0

[](#20)

- Removed `OutType` on parsing. Instead use `Node::toArray` and `json_encode($node)`.
- Removed `Node::toString` override. Dump as json if wanted as json.

Issues and PR's.
----------------

[](#issues-and-prs)

Any issues found should be reported in this repository issue tracker, issues will be fixed when possible.
Pull requests will be accepted, but please try to follow the general code-style!

License
-------

[](#license)

```
MIT License

Copyright (c) 2017 Jitesoft

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

```

###  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 ~64 days

Total

4

Last Release

3165d ago

Major Versions

1.2.0 → 2.0.02017-09-14

### Community

Maintainers

![](https://www.gravatar.com/avatar/07b2a82fa106892922a64f5a0456ed429fc8d1900f9d29be5475d5083b8f5304?d=identicon)[Jitesoft](/maintainers/Jitesoft)

---

Top Contributors

[![Johannestegner](https://avatars.githubusercontent.com/u/2530181?v=4)](https://github.com/Johannestegner "Johannestegner (22 commits)")

---

Tags

parserphp7xmlxml-parserxmlarrayconvertparsing

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/jitesoft-xml2struct/health.svg)

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

###  Alternatives

[openlss/lib-array2xml

Array2XML conversion library credit to lalit.org

31052.5M47](/packages/openlss-lib-array2xml)[clearstream/xml-to-array

Incredibly simple XML to array PHP converter

6736.7k](/packages/clearstream-xml-to-array)[digitickets/lalit

GitHub copy of LaLit's XML2Array and Array2XML

721.3M6](/packages/digitickets-lalit)

PHPackages © 2026

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