2017 © Pedro Peláez
 

library xmlschemavalidator

PHP Library for XML Schema Validations

image

eclipxe/xmlschemavalidator

PHP Library for XML Schema Validations

  • Tuesday, July 17, 2018
  • by eclipxe
  • Repository
  • 2 Watchers
  • 4 Stars
  • 997 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 7 Versions
  • 27 % Grown

The README.md

eclipxe/XmlSchemaValidator

![Source Code][badge-source] Latest Version ![Software License][badge-license] [Build Status][build] ![Scrutinizer][badge-quality] Coverage Status ![Total Downloads][badge-downloads], (*1)

This is a library to validate XML files against multiple XSD Schemas according to its own definitions., (*2)

The way this works is:, (*3)

  1. Receive a valid xml string as the content to be evaluated
  2. Scan the file for every schemaLocation
  3. Compose a schema that include all the schemas
  4. Validate the XML against the composed file

Installation

Use composer, so please run, (*4)

composer require eclipxe/xmlschemavalidator

Basic usage

<?php
declare(strict_types=1);

use Eclipxe\XmlSchemaValidator\SchemaValidator;

$contents = file_get_contents('example.xml');
$validator = SchemaValidator::createFromString($contents);
if (! $validator->validate()) {
    echo 'Found error: ' . $validator->getLastError();
}

Advanced usage

<?php
declare(strict_types=1);

use Eclipxe\XmlSchemaValidator\SchemaValidator;
use Eclipxe\XmlSchemaValidator\Exceptions\ValidationFailException;
use Eclipxe\XmlSchemaValidator\Internal\LibXmlException;

// create SchemaValidator using a DOMDocument
$document = new DOMDocument();
$document->load('example.xml');
$validator = new SchemaValidator($document);

// change schemas collection to override the schema location of a specific namespace
$schemas = $validator->buildSchemas();
$schemas->create('http://example.org/schemas/x1', './local-schemas/x1.xsd');

// validateWithSchemas does not return boolean, it throws an exception
try {
    $validator->validateWithSchemas($schemas);
} catch (ValidationFailException $ex) {
    echo 'Found error: ' . $ex->getMessage();
    $previous = $ex->getPrevious();
    if ($previous instanceof LibXmlException) {
        foreach ($previous->getErrors() as $libXmlError) {
            echo $libXmlError->message, PHP_EOL,
                'File: ', $libXmlError->file, ':', $libXmlError->line, ',', $libXmlError->column, PHP_EOL;
        }
    }
}

On previous example, the class LibXmlException is internal. It will be public (not internal) on next major release., (*5)

Exceptions

This library creates its own specific exceptions and all of them implements XmlSchemaValidatorException. Check the exceptions' documentation for more information., (*6)

When this library uses LibXML functions, it captures the errors and throw its own exception., (*7)

Version 1.x is deprecated

Version 1.x is no longer on development. It has a problem of concerns, the same library try to solve two different issues: Validate an XML file and store locally a copy of the XSD files. Version 2.x breaks this problem and give this library only one propose: Validate an XML file against its multiple XSD files, it does not matter where are located., (*8)

Version 2.x is deprecated

Migration changes between version 2 and version 3, (*9)

Version 2.x was compatible with PHP 7 and was deprecated on 2020-04-05., (*10)

A branch 2.x has been created, it might be installable using composer require eclipxe/xmlschemavalidator:2.x-dev, but it will not be active maintained. You should change your dependency as soon as possible., (*11)

Contributing

Contributions are welcome! Please read CONTRIBUTING for details and don't forget to take a look in TODO and CHANGELOG files., (*12)

The eclipxe/XmlSchemaValidator library is copyright © Carlos C Soto and licensed for use under the MIT License (MIT). Please see LICENSE for more information., (*13)

The Versions

17/07 2018

dev-master

9999999-dev https://github.com/eclipxe13/XmlSchemaValidator

PHP Library for XML Schema Validations

  Sources   Download

MIT

The Requires

  • php >=7.0
  • ext-dom *
  • ext-libxml *

 

The Development Requires

xml validation xsd xmlschema

17/07 2018

v2.0.1

2.0.1.0 https://github.com/eclipxe13/XmlSchemaValidator

PHP Library for XML Schema Validations

  Sources   Download

MIT

The Requires

  • php >=7.0
  • ext-dom *
  • ext-libxml *

 

The Development Requires

xml validation xsd xmlschema

25/09 2017

v2.0.0

2.0.0.0 https://github.com/eclipxe13/XmlSchemaValidator

PHP Library for XML Schema Validations

  Sources   Download

MIT

The Requires

  • php >=7.0
  • ext-xml *

 

The Development Requires

xml validation xsd xmlschema

25/09 2017

dev-next-release

dev-next-release https://github.com/eclipxe13/XmlSchemaValidator

PHP Library for XML Schema Validations

  Sources   Download

MIT

The Requires

  • php >=7.0
  • ext-xml *

 

The Development Requires

xml validation xsd xmlschema

10/08 2017

v1.1.4

1.1.4.0 https://github.com/eclipxe13/XmlSchemaValidator

PHP Library for XML Schema Validations

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

xml validation xsd xmlschema