Giter Club home page Giter Club logo

xmlschemavalidator's Introduction

eclipxe/XmlSchemaValidator

Source Code Latest Version Software License Build Status Scrutinizer Coverage Status Total Downloads

This is a library to validate XML files against multiple XSD Schemas according to its own definitions.

The way this works is:

  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

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;

// 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 an 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();
}

Exceptions

This library creates its own specific exceptions and all of them implements XmlSchemaValidatorException. Check the exceptions documentation for more information.

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

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.

Version 2.x is deprecated

Migration changes between version 2 and version 3

Version 2.x was compatible with PHP 7 and was deprecated on 2020-04-05.

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 and you should change your dependency as soon as possible.

Contributing

Contributions are welcome! Please read CONTRIBUTING for details and don't forget to take a look in the TODO and CHANGELOG files.

Copyright and License

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

xmlschemavalidator's People

Contributors

eclipxe13 avatar dwilbourne avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.