https://github.com/yzen-dev/validator-xsd
ValidatorXSD is a facade over DOMDocument that will allow you to more conveniently validate your XML file.
https://github.com/yzen-dev/validator-xsd
Last synced: 4 months ago
JSON representation
ValidatorXSD is a facade over DOMDocument that will allow you to more conveniently validate your XML file.
- Host: GitHub
- URL: https://github.com/yzen-dev/validator-xsd
- Owner: yzen-dev
- License: mit
- Created: 2020-11-27T07:05:06.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2023-01-12T14:18:51.000Z (over 3 years ago)
- Last Synced: 2025-10-25T14:59:08.978Z (8 months ago)
- Language: PHP
- Size: 107 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## ValidatorXSD is a facade over DOMDocument.



ValidatorXSD is a DOMDocument facade that will allow you to more conveniently validate your XML file and also localize errors.
## :scroll: **Installation**
The package can be installed via composer:
```
composer require yzen.dev/validator-xsd
```
## :scroll: **Features**
* Simple use
* Casting LibXMLError errors to ErrorXSD
* Parsing fields, rules and more from an error
* The ability to localize validator errors
## :scroll: **Usage**
Validate xml by schema:
```php
$data = '...';
$validator = ValidatorXSD::init($data)
->loadSchema( './XSD/request.xsd')
->setLocalization(CustomLocalizationXSD::class);
echo $validator->validate();
```
Get all error:
```php
if (!$validator->validate()) {
foreach ($validator->getErrors() as $error) {
var_dump($error);
}
}
```
Pluck result and group by field:
```php
$errors = $validator->getErrors()
->pluck(['element','message'])
->groupBy('element');
```
Create custom localization
```php
class CustomLocalizationXSD implements LocalizationXSD
{
public function customAttributes(): array
{
return [
'Country' => 'Страна',
'Province' => 'Область',
];
}
public function messages(): array
{
return [
'minLength' => 'Поле "${field}" меньше минимальной длины.',
];
}
}
```