PHPackages                             noki/laravel-xml-converter - 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. noki/laravel-xml-converter

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

noki/laravel-xml-converter
==========================

Laravel XML Converter is Laravel package for converting XML to JSON and XML to array.

v1.0.3(9mo ago)322.0k↑92.9%1MITPHPPHP ^8.0

Since Sep 17Pushed 9mo ago1 watchersCompare

[ Source](https://github.com/novakurosevic/laravel-xml-converter)[ Packagist](https://packagist.org/packages/noki/laravel-xml-converter)[ Docs](https://github.com/novakurosevic/laravel-xml-converter)[ RSS](/packages/noki-laravel-xml-converter/feed)WikiDiscussions main Synced yesterday

READMEChangelogDependenciesVersions (4)Used By (1)

Laravel XML Converter Package
=============================

[](#laravel-xml-converter-package)

🧾 Introduction
--------------

[](#-introduction)

Since I started working with Laravel, I always wanted a simple helper that could convert XML files to JSON.

I created the first version of this package to do exactly that. While the package isn't perfect, it can handle a wide range of XML inputs. If you find any issues, feel free to report them.

I should note that this package was created with the help of AI. In my case, I used [ChatGPT](https://github.com/openai), and it saved me many hours of coding.

❓ What does this package do?
----------------------------

[](#-what-does-this-package-do)

This package provides a flexible and powerful way to convert XML strings to JSON or PHP arrays. It supports:

- DTD and XSD validation
- Namespace tagging
- CDATA handling

---

🚀 Installation
--------------

[](#-installation)

### Requirements

[](#requirements)

- PHP &gt;= 8.1
- Laravel &gt;= 9
- PHP Extensions:
    - `simplexml`
    - `libxml`
    - `dom`

### Composer Installation

[](#composer-installation)

```
composer require noki/laravel-xml-converter
```

⚙️ PHP Extensions Setup
-----------------------

[](#️-php-extensions-setup)

### Linux (Debian/Ubuntu)

[](#linux-debianubuntu)

```
sudo apt-get update
sudo apt-get install php-simplexml php-xml php-dom
```

> Example for PHP 8.3 — be sure to use the correct package names:

First, check your PHP version:

```
php -v
```

Then install extensions for your version:

```
sudo apt-get install php8.3-simplexml php8.3-xml php8.3-dom
```

---

### macOS (with Homebrew)

[](#macos-with-homebrew)

```
brew install php
# OR, if PHP is already installed:
brew reinstall php
```

> Required extensions (`simplexml`, `libxml`, `dom`) are bundled with PHP on macOS.

---

### Windows

[](#windows)

1. Open your `php.ini` file.
2. Ensure the following lines are **uncommented** (remove the `;` at the beginning):

```
extension=simplexml
extension=dom
extension=libxml
```

3. Restart your web server (Apache, Nginx) or PHP-FPM.

---

📦 Usage
-------

[](#-usage)

### Namespace

[](#namespace)

```
use Noki\XmlConverter\Convert;
```

---

### 1. Convert XML to JSON

[](#1-convert-xml-to-json)

```
$json = Convert::xmlToJson($xmlString);
```

---

### 2. Convert XML to array

[](#2-convert-xml-to-array)

```
$array = Convert::xmlToArray($xmlString);
```

---

### 3. Full control with options

[](#3-full-control-with-options)

```
$array = Convert::xmlToArray(
    $xmlString,
    namespace_in_tag_name: true,
    is_cdata: true,
    schema_path: '/path/to/schema.xsd' // or '' to enable DTD validation
);
```

- `namespace_in_tag_name`: If true, keys will include namespace prefixes (e.g., `ns:tag`).
- `is_cdata`: If true, CDATA sections are preserved as-is.
- `schema_path`:
    - Path to an `.xsd` file for XSD validation.
    - Use `''` (empty string) to enable DTD validation (your XML must contain ``).
    - Use `null` to skip validation.

---

### 4. Convert XML to JSON with options

[](#4-convert-xml-to-json-with-options)

```
$json = Convert::xmlToJson(
    $xmlString,
    namespace_in_tag_name: true,
    is_cdata: false,
    schema_path: null
);
```

---

🧪 Example
---------

[](#-example)

### Sample XML with namespaces and CDATA

[](#sample-xml-with-namespaces-and-cdata)

```
$xml =
    F. Scott Fitzgerald
    1925

XML;

$json = Convert::xmlToJson($xml, true, true, '/path/to/book.xsd');
```

---

🛠 Error Handling
----------------

[](#-error-handling)

- If the XML is invalid, an `InvalidArgumentException` will be thrown.
- If schema validation fails, a descriptive exception is thrown (with optional logging).
- CDATA sections and empty tags are handled gracefully.

---

🧩 Integration with Laravel
--------------------------

[](#-integration-with-laravel)

You can use this package in controllers, services, or jobs:

```
use Noki\XmlConverter\Convert;

$data = Convert::xmlToArray($request->getContent(), true);
```

---

📄 License
---------

[](#-license)

MIT License. See [LICENSE.md](LICENSE.md) for details.

---

🙌 Contributing
--------------

[](#-contributing)

Feel free to fork and submit a PR! Bug reports and feature requests are always welcome.

---

🔗 Author
--------

[](#-author)

- [Novak Urosevic](https://github.com/novakurosevic)
- [ChatGPT](https://github.com/openai)

---

📝 Changelog
-----------

[](#-changelog)

Please see [CHANGELOG.md](CHANGELOG.md) for recent updates.

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance57

Moderate activity, may be stable

Popularity31

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity43

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

Every ~0 days

Total

3

Last Release

288d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/198902?v=4)[Tobias Schwarz](/maintainers/noki)[@Noki](https://github.com/Noki)

---

Top Contributors

[![novakurosevic](https://avatars.githubusercontent.com/u/17499419?v=4)](https://github.com/novakurosevic "novakurosevic (18 commits)")

---

Tags

laravelxmltoarrayXMLtoJSONnokiLaravel XML Converter

### Embed Badge

![Health badge](/badges/noki-laravel-xml-converter/health.svg)

```
[![Health](https://phpackages.com/badges/noki-laravel-xml-converter/health.svg)](https://phpackages.com/packages/noki-laravel-xml-converter)
```

###  Alternatives

[stephenjude/filament-blog

Filament Blog Builder

20619.4k](/packages/stephenjude-filament-blog)[datomatic/nova-detached-actions

A Laravel Nova tool to allow for placing actions in the Nova toolbar detached from the checkbox selection mechanism.

11273.0k](/packages/datomatic-nova-detached-actions)

PHPackages © 2026

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