2017 © Pedro Peláez
 

library xml

Coercive Utility Xml

image

coercive/xml

Coercive Utility Xml

  • Wednesday, July 25, 2018
  • by Coercive
  • Repository
  • 1 Watchers
  • 1 Stars
  • 690 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 18 Versions
  • 18 % Grown

The README.md

Coercive Utility Xml

The Xml Utility allows you to easily import, clean, extract, reformat Xml files., (*1)

Get

composer require coercive/xml

Usage

XmlCleaner, (*2)

#
# 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 => [ ['&', '&'] ],
    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('<article>some_text</article> ... ');

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

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

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

XmlToArray, (*3)

#
# 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, (*4)

#
# 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, (*5)

#
# 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' => '<b>' . FormatML::CONTENT . '</b>',
    'italic' => '<i>' . FormatML::CONTENT . '</i>',
    'link-www' => function($content, $attributes, $parents) {
        $color = 'blue';
        if(in_array('quote', $parents)) {
            $color = 'red';
        }
        $target = $attributes['cible'] ?? '#';
        return '<a style="color: '.$color.';" href="'.$target.'">' . $content . '</a>';
    }
], [
    FormatML::OPTION_ALL_TAGS_REQUIRED => false,
    FormatML::OPTION_SKIP_MISSING_TAGS_CONTENT => false
]);

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

The Versions

25/07 2018

dev-master

9999999-dev http://coercive.fr

Coercive Utility Xml

  Sources   Download

MIT GNU

The Requires

  • php >=7.1

 

25/07 2018

0.1.7

0.1.7.0 http://coercive.fr

Coercive Utility Xml

  Sources   Download

MIT

The Requires

  • php >=7.1

 

24/07 2018

0.1.6

0.1.6.0 http://coercive.fr

Coercive Utility Xml

  Sources   Download

MIT

The Requires

  • php >=7.1

 

28/06 2018

0.1.5

0.1.5.0 http://coercive.fr

Coercive Utility Xml

  Sources   Download

MIT

The Requires

  • php >=7

 

07/02 2018

0.1.4

0.1.4.0 http://coercive.fr

Coercive Utility Xml

  Sources   Download

MIT

The Requires

  • php >=7

 

31/10 2017

0.1.3

0.1.3.0 http://coercive.fr

Coercive Utility Xml

  Sources   Download

GNU

The Requires

  • php >=7

 

20/06 2017

0.1.2

0.1.2.0 http://coercive.fr

Coercive Utility Xml

  Sources   Download

GNU

The Requires

  • php >=7

 

08/06 2017

0.1.1

0.1.1.0 http://coercive.fr

Coercive Utility Xml

  Sources   Download

GNU

The Requires

  • php >=7

 

08/06 2017

0.1.0

0.1.0.0 http://coercive.fr

Coercive Utility Xml

  Sources   Download

GNU

The Requires

  • php >=7

 

06/06 2017

0.0.9

0.0.9.0 http://coercive.fr

Coercive Utility Xml

  Sources   Download

GNU

The Requires

  • php >=7

 

09/02 2017

0.0.8

0.0.8.0 http://coercive.fr

Coercive Utility Xml

  Sources   Download

GNU

The Requires

  • php >=7

 

12/01 2017

0.0.7

0.0.7.0 http://coercive.fr

Coercive Utility Xml

  Sources   Download

GNU

The Requires

  • php >=7

 

12/01 2017

0.0.6

0.0.6.0 http://coercive.fr

Coercive Utility Xml

  Sources   Download

GNU

The Requires

  • php >=7

 

26/12 2016

0.0.5

0.0.5.0 http://coercive.fr

Coercive Utility Xml

  Sources   Download

GNU

The Requires

  • php >=7

 

13/12 2016

0.0.4

0.0.4.0 http://coercive.fr

Coercive Utility Xml

  Sources   Download

GNU

The Requires

  • php >=7

 

29/11 2016

0.0.3

0.0.3.0 http://coercive.fr

Coercive Utility Xml

  Sources   Download

GNU

The Requires

  • php >=7

 

28/11 2016

0.0.2

0.0.2.0 http://coercive.fr

Coercive Utility Xml

  Sources   Download

GNU

The Requires

  • php >=7

 

26/11 2016

0.0.1

0.0.1.0 http://coercive.fr

Coercive Utility Xml

  Sources   Download

GNU

The Requires

  • php >=7