horat1us / simple-xml
SimpleXML Extensions
1.0.0
2019-03-08 19:38 UTC
Requires
- php: >=7.2
Requires (Dev)
- phpunit/phpunit: ^8.0
- squizlabs/php_codesniffer: ^3.4
This package is auto-updated.
Last update: 2024-10-09 14:09:26 UTC
README
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
- Parse\Exception - base exception interface for all parsing exceptions.
- Parse\Exception\InvalidFormat - base exception for
libxml errors
- Parse\Exception\InvalidFormat\Data - string parse errors
- Parse\Exception\InvalidFormat\File - file parse errors
- Parse\Exception\InvalidClassName - represents case when passed class name does not exist.
- Parse\Exception\InvaldiFilePath - represents case when passed file path does not exists or is not file path.
- Parse\Exception\InvalidFormat - base exception for
libxml errors