hyperized / xml-validator
A simple PHP XML validator
Installs: 2 277
Dependents: 0
Suggesters: 0
Security: 0
Stars: 7
Watchers: 3
Forks: 5
Open Issues: 1
Requires
- php: >=7.2
- ext-dom: 20031129
- ext-libxml: ^7.2
Requires (Dev)
- ext-mbstring: ^7.2
- bmitch/churn-php: ^1.0.3
- infection/infection: ^0.15.0
- phan/phan: ^2.4
- phpmd/phpmd: @stable
- phpstan/phpstan: ^0.12.0
- phpunit/phpunit: ^7 || ^8
- povils/phpmnd: ^2.0
- squizlabs/php_codesniffer: ^3.5
- vimeo/psalm: ^3.8
README
A simple PHP XML validator.
Installation
composer require hyperized/xml-validator
Usage
<?php namespace Hyperized\Xml; require __DIR__ . '/vendor/autoload.php'; $xmlString = file_get_contents(__DIR__ . '/tests/files/correct.xml'); $dirtyXMLString = file_get_contents(__DIR__ . '/tests/files/incorrect.xml'); $xmlFile = __DIR__ . '/tests/files/correct.xml'; $xsdFile = __DIR__ . '/tests/files/simple.xsd'; $validator = new Validator(); // String validation print_r($validator->isXMLStringValid($xmlString)); // 1 print_r($validator->isXMLStringValid($xmlString, $xsdFile)); // 1 // File validation print_r($validator->isXMLFileValid($xmlFile)); // 1 print_r($validator->isXMLFileValid($xmlFile, $xsdFile)); // 1 // Error handling try { $validator->isXMLStringValid($dirtyXMLString, $xsdFile); } catch (Exceptions\InvalidXmlException $exception) { print_r($exception->getMessage()); // xmlParseEntityRef: no name\n The document has no document element. }
Treeware
You're free to use this package, but if it makes it to your production environment you are required to buy the world a tree.
It’s now common knowledge that one of the best tools to tackle the climate crisis and keep our temperatures from rising above 1.5C is to plant trees. If you support this package and contribute to the Treeware forest you’ll be creating employment for local families and restoring wildlife habitats.
You can buy trees here offset.earth/treeware
Read more about Treeware at treeware.earth