PHP Classes

PHP Validate XML Against XSD: Validate XML documents with XSD schema files

Recommend this page to a friend!
  Info   Documentation   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 29 All time: 11,180 This week: 73Up
Version License PHP version Categories
validator-xsd 1.0MIT/X Consortium ...7XML, Validation, PHP 7
Description 

Author

This package can validate XML documents with XSD schema files.

It can take a string of a given XML document and validate it using the schema definitions of a given XSD file.

The package returns a list of errors if the XML document has invalid elements.

ValidatorXSD is a facade over DOMDocument that will allow you to validate your XML file conveniently.

Picture of Andrey Iatsenko
  Performance   Level  
Innovation award
Innovation award
Nominee: 7x

 

Documentation

ValidatorXSD is a facade over DOMDocument.

Packagist Version Packagist Downloads Packagist Downloads

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:

    $data = '<XML>...</XML>';
    $validator = ValidatorXSD::init($data)
                ->loadSchema( './XSD/request.xsd')
                ->setLocalization(CustomLocalizationXSD::class);
    echo $validator->validate();

Get all error:

    if (!$validator->validate()) {
        foreach ($validator->getErrors() as $error) {
            var_dump($error);
        }
    }

Pluck result and group by field:

    $errors = $validator->getErrors()
                ->pluck(['element','message'])
                ->groupBy('element');

Create custom localization

class CustomLocalizationXSD implements LocalizationXSD
{
    public function customAttributes(): array
    {
        return [
            'Country' => '??????',
            'Province' => '???????',
        ];
    }
    
    public function messages(): array
    {
        return [
            'minLength' => '???? "${field}" ?????? ??????????? ?????.',
        ];
    }
}

  Files folder image Files (19)  
File Role Description
Files folder image.github (1 directory)
Files folder imagesrc (7 files, 1 directory)
Files folder imagetests (1 file, 1 directory)
Accessible without login Plain text file .editorconfig Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file composer.lock Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file phpcs.xml Data Auxiliary data
Accessible without login Plain text file phpstan.neon Data Auxiliary data
Accessible without login Plain text file phpunit.xml Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:29
This week:0
All time:11,180
This week:73Up