PHP Classes

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

Recommend this page to a friend!
  Info   View files Documentation   View files View files (19)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2024-03-19 (4 days ago) RSS 2.0 feedNot enough user ratingsTotal: 19 This week: 19All time: 11,185 This week: 4Up
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  
Name: Andrey Iatsenko <contact>
Classes: 7 packages by
Country: Russian Federation Russian Federation
Innovation award
Innovation award
Nominee: 5x

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  
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

  Files folder image Files  /  .github  
File Role Description
Files folder imageworkflows (1 file)

  Files folder image Files  /  .github  /  workflows  
File Role Description
  Accessible without login Plain text file testing.yml Data Auxiliary data

  Files folder image Files  /  src  
File Role Description
Files folder imageExceptions (1 file)
  Plain text file Collection.php Class Class source
  Plain text file CollectionErrorXSD.php Class Class source
  Plain text file ErrorXSD.php Class Class source
  Plain text file LocalizationXSD.php Class Class source
  Plain text file ParseLibXMLError.php Class Class source
  Plain text file Translator.php Class Class source
  Plain text file ValidatorXSD.php Class Class source

  Files folder image Files  /  src  /  Exceptions  
File Role Description
  Plain text file LocalizationFailedImplement.php Class Class source

  Files folder image Files  /  tests  
File Role Description
Files folder imageUnit (1 file)
  Plain text file ValidatorXSDTest.php Class Class source

  Files folder image Files  /  tests  /  Unit  
File Role Description
  Plain text file CollectionTest.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:19
This week:19
All time:11,185
This week:4Up