horat1us/simple-xml

SimpleXML Extensions

1.0.0 2019-03-08 19:38 UTC

This package is auto-updated.

Last update: 2024-10-09 14:09:26 UTC


README

Build Status codecov

This package provides some extensions fore simple xml:

Installation

composer require wearesho-team/simple-xml

Usage

Parse

This class represents parser, that wraps simplexml_load_string and simplexml_load_file into errors wrapper, so you will be able to catch exceptions.

File Parsing

<?php

use Horat1us\SimpleXML;

$path = 'valid.xml';

try {
    $element = SimpleXML\Parse::file($path/*, $className*/);    
} catch(SimpleXML\Parse\Exception\InvalidFilePath $e) {
    $path = $e->getPath();
} catch(SimpleXML\Parse\Exception\InvalidFormat\File $e) {
    $filePath = $e->getPath();
    $libXmlErrors = $e->getErrors();
} catch(SimpleXML\Parse\Exception\InvalidClassName $e) {
    $className = $e->getClassName();
}

String Parsing

<?php

use Horat1us\SimpleXML;

$path = 'valid.xml';

try {
    $element = SimpleXML\Parse::file($path/*, $className*/);    
} catch(SimpleXML\Parse\Exception\InvalidFormat\Data $e) {
    $contents = $e->getContents();
    $libXmlErrors = $e->getErrors();
} catch(SimpleXML\Parse\Exception\InvalidClassName $e) {
    $className = $e->getClassName();
}

Errors

Contributors

License

MIT