PHPackages                             coercive/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. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. coercive/xml

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

coercive/xml
============

Coercive Utility Xml

0.1.20(3y ago)11.3k1MITPHP &gt;=7

Since Nov 26Pushed 3y ago2 watchersCompare

[ Source](https://github.com/Coercive/Xml)[ Packagist](https://packagist.org/packages/coercive/xml)[ Docs](http://coercive.fr)[ RSS](/packages/coercive-xml/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (10)DependenciesVersions (31)Used By (1)

Coercive Utility Xml
====================

[](#coercive-utility-xml)

The Xml Utility allows you to easily import, clean, extract, reformat Xml files.

Get
---

[](#get)

```
composer require coercive/xml

```

Usage
-----

[](#usage)

XmlCleaner

```
#
# FIRST : clean your xml file
#
use \Coercive\Utility\Xml\XmlCleaner;

# Load cleaner
$cleaner = new XmlCleaner();

# You can add some options
$cleaner = new XmlCleaner([
    XmlCleaner::OPTION_DECODE => [ ['&', '&amp;'] ],
    XmlCleaner::OPTION_DELETE_DOCTYPE => true,
    XmlCleaner::OPTION_DELETE_PARASITIC => true
]);

# Load the file
$cleaner->loadFile('path/filename.xml');

# OR Load the string content
$cleaner->loadString('some_text ... ');

# Clean the file
$cleaner->clean();

# Get the content
$xmlCleanedContent = $cleaner->get();

# You can chain
$xmlCleanedContent = (new XmlCleaner)->loadFile('path/filename.xml')->clean()->get();
```

XmlToArray

```
#
# SECOND : transform file to array
#
use \Coercive\Utility\Xml\XmlToArray;

# Load ToArray converter
$toArray = new XmlToArray($xmlCleanedContent);

# You can add some options
$toArray = new XmlToArray($xmlCleanedContent, [
    XmlToArray::XML_OPTION_CASE_FOLDING => 0,
    XmlToArray::XML_OPTION_SKIP_WHITE => 0,
    XmlToArray::XML_OPTION_TARGET_ENCODING => 'UTF-8'
]);

# Parse to array when you're ready
$toArray->parse();

# Get the array content
$xml = $toArray->get();

# You can chain
$xml = (new XmlToArray($xmlCleanedContent))->parse()->get();
```

ExtractArray

```
#
# THIRD : extract array
#
use \Coercive\Utility\Xml\ExtractArray;

# Load array extractor
$extractArray = new ExtractArray($xml);

# You can add some options
$extractArray->setRoot('/example/subexample');
$extractArray->setDelimiter('/');
$extractArray->setRequired(false);

# Get your content (destructive array system)
$title = $extractArray->get('title');
$authors = $extractArray->get('authors');
$article = $extractArray->get(); /* take all others */

# You have two extraction options :

# Get all elements
$listAll = $extractArray->get('example', true);

# Get all elements at the foreground of setted root
$listAllForeground = $extractArray->get('example', true, true);
```

FormatML

```
#
# FOURTH : format your ML
#
use \Coercive\Utility\Xml\FormatML;

# Load ML Format
$formatML = new FormatML($aTitle);

# You can add some format options
$formatML = new FormatML($aTitle, [
    'bold' => '' . FormatML::CONTENT . '',
    'italic' => '' . FormatML::CONTENT . '',
    'link-www' => function($content, $attributes, $parents) {
        $color = 'blue';
        if(in_array('quote', $parents)) {
            $color = 'red';
        }
        $target = $attributes['cible'] ?? '#';
        return '' . $content . '';
    }
], [
    FormatML::OPTION_ALL_TAGS_REQUIRED => false,
    FormatML::OPTION_SKIP_MISSING_TAGS_CONTENT => false
]);

# Retrieve formated content
$formatedTitle = $formatML->get();
```

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity64

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 ~71 days

Recently: every ~293 days

Total

30

Last Release

1373d ago

PHP version history (2 changes)0.0.1PHP &gt;=7

0.1.6PHP &gt;=7.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/20288080?v=4)[Coercive](/maintainers/Coercive)[@Coercive](https://github.com/Coercive)

---

Top Contributors

[![Coercive](https://avatars.githubusercontent.com/u/20288080?v=4)](https://github.com/Coercive "Coercive (36 commits)")

---

Tags

arrayphpxmlxmlutils

### Embed Badge

![Health badge](/badges/coercive-xml/health.svg)

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

###  Alternatives

[mtdowling/jmespath.php

Declaratively specify how to extract elements from a JSON document

2.0k472.8M135](/packages/mtdowling-jmespathphp)[opis/closure

A library that can be used to serialize closures (anonymous functions) and arbitrary data.

2.6k230.0M284](/packages/opis-closure)[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)[michelf/php-markdown

PHP Markdown

3.5k52.4M345](/packages/michelf-php-markdown)[jms/metadata

Class/method/property metadata management in PHP

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

PHPackages © 2026

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