seromenho / xml-validator
Validates your XML against a xsd schema file.
Installs: 177 640
Dependents: 2
Suggesters: 0
Security: 0
Stars: 12
Watchers: 2
Forks: 7
Open Issues: 0
Requires
- php: >=5.4.0
Requires (Dev)
- phpunit/phpunit: 4.7.*
This package is not auto-updated.
Last update: 2024-11-05 04:04:55 UTC
README
Validate Xml against a xsd schema file.
Installation
Library
$ git clone https://github.com/seromenho/XmlValidator.git
Composer
$ composer require seromenho/xml-validator:dev-master
Usage
<?php require "./vendor/autoload.php"; use XmlValidator\XmlValidator; $xml = "<sample>my xml string</sample>"; $xsd = "path_to_xsd_file.xsd"; // Validate $xmlValidator = new XmlValidator($xml, $xsd); try{ $xmlValidator->validate($xml,$xsd); // Check if is valid if(!$xmlValidator->isValid()){ // Do whatever with the errors. foreach ($xmlValidator->errors as $error) { /*echo sprintf('[%s %s] %s (in %s - line %d, column %d)', $error->level, $error->code, $error->message, $error->file, $error->line, $error->column ); */ } } } catch (\InvalidArgumentException $e){ // catch InvalidArgumentException }
Based on XmlUtils from Symfony config component.